2 * linux/fs/proc/proc_misc.c
4 * linux/fs/proc/array.c
5 * Copyright (C) 1992 by Linus Torvalds
6 * based on ideas by Darren Senn
8 * This used to be the part of array.c. See the rest of history and credits
9 * there. I took this into a separate file and switched the thing to generic
10 * proc_file_inode_operations, leaving in array.c only per-process stuff.
11 * Inumbers allocation made dynamic (via create_proc_entry()). AV, May 1999.
14 * Fulton Green : Encapsulated position metric calculations.
15 * <kernel@FultonGreen.com>
18 #include <linux/types.h>
19 #include <linux/errno.h>
20 #include <linux/time.h>
21 #include <linux/kernel.h>
22 #include <linux/kernel_stat.h>
24 #include <linux/tty.h>
25 #include <linux/string.h>
26 #include <linux/mman.h>
27 #include <linux/quicklist.h>
28 #include <linux/proc_fs.h>
29 #include <linux/ioport.h>
31 #include <linux/mmzone.h>
32 #include <linux/pagemap.h>
33 #include <linux/irq.h>
34 #include <linux/interrupt.h>
35 #include <linux/swap.h>
36 #include <linux/slab.h>
37 #include <linux/genhd.h>
38 #include <linux/smp.h>
39 #include <linux/signal.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/seq_file.h>
43 #include <linux/times.h>
44 #include <linux/profile.h>
45 #include <linux/utsname.h>
46 #include <linux/blkdev.h>
47 #include <linux/hugetlb.h>
48 #include <linux/jiffies.h>
49 #include <linux/vmalloc.h>
50 #include <linux/crash_dump.h>
51 #include <linux/pid_namespace.h>
52 #include <linux/bootmem.h>
53 #include <asm/uaccess.h>
54 #include <asm/pgtable.h>
57 #include <asm/div64.h>
60 #ifdef CONFIG_PROC_PAGE_MONITOR
61 #define KPMSIZE sizeof(u64)
62 #define KPMMASK (KPMSIZE - 1)
63 /* /proc/kpagecount - an array exposing page counts
65 * Each entry is a u64 representing the corresponding
66 * physical page count.
68 static ssize_t
kpagecount_read(struct file
*file
, char __user
*buf
,
69 size_t count
, loff_t
*ppos
)
71 u64 __user
*out
= (u64 __user
*)buf
;
73 unsigned long src
= *ppos
;
79 count
= min_t(size_t, count
, (max_pfn
* KPMSIZE
) - src
);
80 if (src
& KPMMASK
|| count
& KPMMASK
)
86 ppage
= pfn_to_page(pfn
);
91 pcount
= page_mapcount(ppage
);
93 if (put_user(pcount
, out
++)) {
101 *ppos
+= (char __user
*)out
- buf
;
103 ret
= (char __user
*)out
- buf
;
107 static struct file_operations proc_kpagecount_operations
= {
109 .read
= kpagecount_read
,
112 /* /proc/kpageflags - an array exposing page flags
114 * Each entry is a u64 representing the corresponding
115 * physical page flags.
118 /* These macros are used to decouple internal flags from exported ones */
122 #define KPF_REFERENCED 2
123 #define KPF_UPTODATE 3
128 #define KPF_WRITEBACK 8
129 #define KPF_RECLAIM 9
132 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
134 static ssize_t
kpageflags_read(struct file
*file
, char __user
*buf
,
135 size_t count
, loff_t
*ppos
)
137 u64 __user
*out
= (u64 __user
*)buf
;
139 unsigned long src
= *ppos
;
145 count
= min_t(unsigned long, count
, (max_pfn
* KPMSIZE
) - src
);
146 if (src
& KPMMASK
|| count
& KPMMASK
)
152 ppage
= pfn_to_page(pfn
);
157 kflags
= ppage
->flags
;
159 uflags
= kpf_copy_bit(KPF_LOCKED
, PG_locked
, kflags
) |
160 kpf_copy_bit(kflags
, KPF_ERROR
, PG_error
) |
161 kpf_copy_bit(kflags
, KPF_REFERENCED
, PG_referenced
) |
162 kpf_copy_bit(kflags
, KPF_UPTODATE
, PG_uptodate
) |
163 kpf_copy_bit(kflags
, KPF_DIRTY
, PG_dirty
) |
164 kpf_copy_bit(kflags
, KPF_LRU
, PG_lru
) |
165 kpf_copy_bit(kflags
, KPF_ACTIVE
, PG_active
) |
166 kpf_copy_bit(kflags
, KPF_SLAB
, PG_slab
) |
167 kpf_copy_bit(kflags
, KPF_WRITEBACK
, PG_writeback
) |
168 kpf_copy_bit(kflags
, KPF_RECLAIM
, PG_reclaim
) |
169 kpf_copy_bit(kflags
, KPF_BUDDY
, PG_buddy
);
171 if (put_user(uflags
, out
++)) {
179 *ppos
+= (char __user
*)out
- buf
;
181 ret
= (char __user
*)out
- buf
;
185 static struct file_operations proc_kpageflags_operations
= {
187 .read
= kpageflags_read
,
189 #endif /* CONFIG_PROC_PAGE_MONITOR */
191 void __init
proc_misc_init(void)
193 proc_symlink("mounts", NULL
, "self/mounts");
195 /* And now for trickier ones */
196 #ifdef CONFIG_PROC_PAGE_MONITOR
197 proc_create("kpagecount", S_IRUSR
, NULL
, &proc_kpagecount_operations
);
198 proc_create("kpageflags", S_IRUSR
, NULL
, &proc_kpageflags_operations
);
200 #ifdef CONFIG_PROC_VMCORE
201 proc_vmcore
= proc_create("vmcore", S_IRUSR
, NULL
, &proc_vmcore_operations
);