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 static int fragmentation_open(struct inode
*inode
, struct file
*file
)
63 return seq_open(file
, &fragmentation_op
);
66 static const struct file_operations fragmentation_file_operations
= {
67 .open
= fragmentation_open
,
70 .release
= seq_release
,
73 static int pagetypeinfo_open(struct inode
*inode
, struct file
*file
)
75 return seq_open(file
, &pagetypeinfo_op
);
78 static const struct file_operations pagetypeinfo_file_ops
= {
79 .open
= pagetypeinfo_open
,
82 .release
= seq_release
,
85 static int zoneinfo_open(struct inode
*inode
, struct file
*file
)
87 return seq_open(file
, &zoneinfo_op
);
90 static const struct file_operations proc_zoneinfo_file_operations
= {
91 .open
= zoneinfo_open
,
94 .release
= seq_release
,
97 static int vmstat_open(struct inode
*inode
, struct file
*file
)
99 return seq_open(file
, &vmstat_op
);
101 static const struct file_operations proc_vmstat_file_operations
= {
105 .release
= seq_release
,
109 static int diskstats_open(struct inode
*inode
, struct file
*file
)
111 return seq_open(file
, &diskstats_op
);
113 static const struct file_operations proc_diskstats_operations
= {
114 .open
= diskstats_open
,
117 .release
= seq_release
,
121 #ifdef CONFIG_MODULES
122 extern const struct seq_operations modules_op
;
123 static int modules_open(struct inode
*inode
, struct file
*file
)
125 return seq_open(file
, &modules_op
);
127 static const struct file_operations proc_modules_operations
= {
128 .open
= modules_open
,
131 .release
= seq_release
,
136 static int vmalloc_open(struct inode
*inode
, struct file
*file
)
138 unsigned int *ptr
= NULL
;
142 ptr
= kmalloc(nr_node_ids
* sizeof(unsigned int), GFP_KERNEL
);
143 ret
= seq_open(file
, &vmalloc_op
);
145 struct seq_file
*m
= file
->private_data
;
152 static const struct file_operations proc_vmalloc_operations
= {
153 .open
= vmalloc_open
,
156 .release
= seq_release_private
,
160 #ifdef CONFIG_PROC_PAGE_MONITOR
161 #define KPMSIZE sizeof(u64)
162 #define KPMMASK (KPMSIZE - 1)
163 /* /proc/kpagecount - an array exposing page counts
165 * Each entry is a u64 representing the corresponding
166 * physical page count.
168 static ssize_t
kpagecount_read(struct file
*file
, char __user
*buf
,
169 size_t count
, loff_t
*ppos
)
171 u64 __user
*out
= (u64 __user
*)buf
;
173 unsigned long src
= *ppos
;
179 count
= min_t(size_t, count
, (max_pfn
* KPMSIZE
) - src
);
180 if (src
& KPMMASK
|| count
& KPMMASK
)
186 ppage
= pfn_to_page(pfn
);
191 pcount
= page_mapcount(ppage
);
193 if (put_user(pcount
, out
++)) {
201 *ppos
+= (char __user
*)out
- buf
;
203 ret
= (char __user
*)out
- buf
;
207 static struct file_operations proc_kpagecount_operations
= {
209 .read
= kpagecount_read
,
212 /* /proc/kpageflags - an array exposing page flags
214 * Each entry is a u64 representing the corresponding
215 * physical page flags.
218 /* These macros are used to decouple internal flags from exported ones */
222 #define KPF_REFERENCED 2
223 #define KPF_UPTODATE 3
228 #define KPF_WRITEBACK 8
229 #define KPF_RECLAIM 9
232 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
234 static ssize_t
kpageflags_read(struct file
*file
, char __user
*buf
,
235 size_t count
, loff_t
*ppos
)
237 u64 __user
*out
= (u64 __user
*)buf
;
239 unsigned long src
= *ppos
;
245 count
= min_t(unsigned long, count
, (max_pfn
* KPMSIZE
) - src
);
246 if (src
& KPMMASK
|| count
& KPMMASK
)
252 ppage
= pfn_to_page(pfn
);
257 kflags
= ppage
->flags
;
259 uflags
= kpf_copy_bit(KPF_LOCKED
, PG_locked
, kflags
) |
260 kpf_copy_bit(kflags
, KPF_ERROR
, PG_error
) |
261 kpf_copy_bit(kflags
, KPF_REFERENCED
, PG_referenced
) |
262 kpf_copy_bit(kflags
, KPF_UPTODATE
, PG_uptodate
) |
263 kpf_copy_bit(kflags
, KPF_DIRTY
, PG_dirty
) |
264 kpf_copy_bit(kflags
, KPF_LRU
, PG_lru
) |
265 kpf_copy_bit(kflags
, KPF_ACTIVE
, PG_active
) |
266 kpf_copy_bit(kflags
, KPF_SLAB
, PG_slab
) |
267 kpf_copy_bit(kflags
, KPF_WRITEBACK
, PG_writeback
) |
268 kpf_copy_bit(kflags
, KPF_RECLAIM
, PG_reclaim
) |
269 kpf_copy_bit(kflags
, KPF_BUDDY
, PG_buddy
);
271 if (put_user(uflags
, out
++)) {
279 *ppos
+= (char __user
*)out
- buf
;
281 ret
= (char __user
*)out
- buf
;
285 static struct file_operations proc_kpageflags_operations
= {
287 .read
= kpageflags_read
,
289 #endif /* CONFIG_PROC_PAGE_MONITOR */
291 struct proc_dir_entry
*proc_root_kcore
;
293 void __init
proc_misc_init(void)
295 proc_symlink("mounts", NULL
, "self/mounts");
297 /* And now for trickier ones */
299 proc_create("vmallocinfo", S_IRUSR
, NULL
, &proc_vmalloc_operations
);
301 proc_create("buddyinfo", S_IRUGO
, NULL
, &fragmentation_file_operations
);
302 proc_create("pagetypeinfo", S_IRUGO
, NULL
, &pagetypeinfo_file_ops
);
303 proc_create("vmstat", S_IRUGO
, NULL
, &proc_vmstat_file_operations
);
304 proc_create("zoneinfo", S_IRUGO
, NULL
, &proc_zoneinfo_file_operations
);
306 proc_create("diskstats", 0, NULL
, &proc_diskstats_operations
);
308 #ifdef CONFIG_MODULES
309 proc_create("modules", 0, NULL
, &proc_modules_operations
);
311 #ifdef CONFIG_SCHEDSTATS
312 proc_create("schedstat", 0, NULL
, &proc_schedstat_operations
);
314 #ifdef CONFIG_PROC_KCORE
315 proc_root_kcore
= proc_create("kcore", S_IRUSR
, NULL
, &proc_kcore_operations
);
317 proc_root_kcore
->size
=
318 (size_t)high_memory
- PAGE_OFFSET
+ PAGE_SIZE
;
320 #ifdef CONFIG_PROC_PAGE_MONITOR
321 proc_create("kpagecount", S_IRUSR
, NULL
, &proc_kpagecount_operations
);
322 proc_create("kpageflags", S_IRUSR
, NULL
, &proc_kpageflags_operations
);
324 #ifdef CONFIG_PROC_VMCORE
325 proc_vmcore
= proc_create("vmcore", S_IRUSR
, NULL
, &proc_vmcore_operations
);