proc: move /proc/slab_allocators boilerplate to mm/slab.c
[linux-2.6/verdex.git] / fs / proc / proc_misc.c
blob5bca02842d07913def6a57793736f1d3f1e5c943
1 /*
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.
13 * Changes:
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>
23 #include <linux/fs.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>
30 #include <linux/mm.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>
55 #include <asm/io.h>
56 #include <asm/tlb.h>
57 #include <asm/div64.h>
58 #include "internal.h"
60 static int fragmentation_open(struct inode *inode, struct file *file)
62 (void)inode;
63 return seq_open(file, &fragmentation_op);
66 static const struct file_operations fragmentation_file_operations = {
67 .open = fragmentation_open,
68 .read = seq_read,
69 .llseek = seq_lseek,
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,
80 .read = seq_read,
81 .llseek = seq_lseek,
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,
92 .read = seq_read,
93 .llseek = seq_lseek,
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 = {
102 .open = vmstat_open,
103 .read = seq_read,
104 .llseek = seq_lseek,
105 .release = seq_release,
108 #ifdef CONFIG_BLOCK
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,
115 .read = seq_read,
116 .llseek = seq_lseek,
117 .release = seq_release,
119 #endif
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,
129 .read = seq_read,
130 .llseek = seq_lseek,
131 .release = seq_release,
133 #endif
135 #ifdef CONFIG_SLABINFO
136 static int slabinfo_open(struct inode *inode, struct file *file)
138 return seq_open(file, &slabinfo_op);
140 static const struct file_operations proc_slabinfo_operations = {
141 .open = slabinfo_open,
142 .read = seq_read,
143 .write = slabinfo_write,
144 .llseek = seq_lseek,
145 .release = seq_release,
147 #endif
149 #ifdef CONFIG_MMU
150 static int vmalloc_open(struct inode *inode, struct file *file)
152 unsigned int *ptr = NULL;
153 int ret;
155 if (NUMA_BUILD)
156 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
157 ret = seq_open(file, &vmalloc_op);
158 if (!ret) {
159 struct seq_file *m = file->private_data;
160 m->private = ptr;
161 } else
162 kfree(ptr);
163 return ret;
166 static const struct file_operations proc_vmalloc_operations = {
167 .open = vmalloc_open,
168 .read = seq_read,
169 .llseek = seq_lseek,
170 .release = seq_release_private,
172 #endif
174 #ifdef CONFIG_PROC_PAGE_MONITOR
175 #define KPMSIZE sizeof(u64)
176 #define KPMMASK (KPMSIZE - 1)
177 /* /proc/kpagecount - an array exposing page counts
179 * Each entry is a u64 representing the corresponding
180 * physical page count.
182 static ssize_t kpagecount_read(struct file *file, char __user *buf,
183 size_t count, loff_t *ppos)
185 u64 __user *out = (u64 __user *)buf;
186 struct page *ppage;
187 unsigned long src = *ppos;
188 unsigned long pfn;
189 ssize_t ret = 0;
190 u64 pcount;
192 pfn = src / KPMSIZE;
193 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
194 if (src & KPMMASK || count & KPMMASK)
195 return -EINVAL;
197 while (count > 0) {
198 ppage = NULL;
199 if (pfn_valid(pfn))
200 ppage = pfn_to_page(pfn);
201 pfn++;
202 if (!ppage)
203 pcount = 0;
204 else
205 pcount = page_mapcount(ppage);
207 if (put_user(pcount, out++)) {
208 ret = -EFAULT;
209 break;
212 count -= KPMSIZE;
215 *ppos += (char __user *)out - buf;
216 if (!ret)
217 ret = (char __user *)out - buf;
218 return ret;
221 static struct file_operations proc_kpagecount_operations = {
222 .llseek = mem_lseek,
223 .read = kpagecount_read,
226 /* /proc/kpageflags - an array exposing page flags
228 * Each entry is a u64 representing the corresponding
229 * physical page flags.
232 /* These macros are used to decouple internal flags from exported ones */
234 #define KPF_LOCKED 0
235 #define KPF_ERROR 1
236 #define KPF_REFERENCED 2
237 #define KPF_UPTODATE 3
238 #define KPF_DIRTY 4
239 #define KPF_LRU 5
240 #define KPF_ACTIVE 6
241 #define KPF_SLAB 7
242 #define KPF_WRITEBACK 8
243 #define KPF_RECLAIM 9
244 #define KPF_BUDDY 10
246 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
248 static ssize_t kpageflags_read(struct file *file, char __user *buf,
249 size_t count, loff_t *ppos)
251 u64 __user *out = (u64 __user *)buf;
252 struct page *ppage;
253 unsigned long src = *ppos;
254 unsigned long pfn;
255 ssize_t ret = 0;
256 u64 kflags, uflags;
258 pfn = src / KPMSIZE;
259 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
260 if (src & KPMMASK || count & KPMMASK)
261 return -EINVAL;
263 while (count > 0) {
264 ppage = NULL;
265 if (pfn_valid(pfn))
266 ppage = pfn_to_page(pfn);
267 pfn++;
268 if (!ppage)
269 kflags = 0;
270 else
271 kflags = ppage->flags;
273 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
274 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
275 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
276 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
277 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
278 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
279 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
280 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
281 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
282 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
283 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
285 if (put_user(uflags, out++)) {
286 ret = -EFAULT;
287 break;
290 count -= KPMSIZE;
293 *ppos += (char __user *)out - buf;
294 if (!ret)
295 ret = (char __user *)out - buf;
296 return ret;
299 static struct file_operations proc_kpageflags_operations = {
300 .llseek = mem_lseek,
301 .read = kpageflags_read,
303 #endif /* CONFIG_PROC_PAGE_MONITOR */
305 struct proc_dir_entry *proc_root_kcore;
307 void __init proc_misc_init(void)
309 proc_symlink("mounts", NULL, "self/mounts");
311 /* And now for trickier ones */
312 #ifdef CONFIG_SLABINFO
313 proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
314 #endif
315 #ifdef CONFIG_MMU
316 proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
317 #endif
318 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
319 proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
320 proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
321 proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
322 #ifdef CONFIG_BLOCK
323 proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
324 #endif
325 #ifdef CONFIG_MODULES
326 proc_create("modules", 0, NULL, &proc_modules_operations);
327 #endif
328 #ifdef CONFIG_SCHEDSTATS
329 proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
330 #endif
331 #ifdef CONFIG_PROC_KCORE
332 proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
333 if (proc_root_kcore)
334 proc_root_kcore->size =
335 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
336 #endif
337 #ifdef CONFIG_PROC_PAGE_MONITOR
338 proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
339 proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
340 #endif
341 #ifdef CONFIG_PROC_VMCORE
342 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
343 #endif