vmstat: mlocked pages statistics
[linux-2.6.git] / fs / proc / proc_misc.c
1 /*
2  *  linux/fs/proc/proc_misc.c
3  *
4  *  linux/fs/proc/array.c
5  *  Copyright (C) 1992  by Linus Torvalds
6  *  based on ideas by Darren Senn
7  *
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.
12  *
13  * Changes:
14  * Fulton Green      :  Encapsulated position metric calculations.
15  *                      <kernel@FultonGreen.com>
16  */
17
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/interrupt.h>
34 #include <linux/swap.h>
35 #include <linux/slab.h>
36 #include <linux/genhd.h>
37 #include <linux/smp.h>
38 #include <linux/signal.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/seq_file.h>
42 #include <linux/times.h>
43 #include <linux/profile.h>
44 #include <linux/utsname.h>
45 #include <linux/blkdev.h>
46 #include <linux/hugetlb.h>
47 #include <linux/jiffies.h>
48 #include <linux/vmalloc.h>
49 #include <linux/crash_dump.h>
50 #include <linux/pid_namespace.h>
51 #include <linux/bootmem.h>
52 #include <asm/uaccess.h>
53 #include <asm/pgtable.h>
54 #include <asm/io.h>
55 #include <asm/tlb.h>
56 #include <asm/div64.h>
57 #include "internal.h"
58
59 #define LOAD_INT(x) ((x) >> FSHIFT)
60 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
61 /*
62  * Warning: stuff below (imported functions) assumes that its output will fit
63  * into one page. For some of those functions it may be wrong. Moreover, we
64  * have a way to deal with that gracefully. Right now I used straightforward
65  * wrappers, but this needs further analysis wrt potential overflows.
66  */
67 extern int get_hardware_list(char *);
68 extern int get_stram_list(char *);
69 extern int get_exec_domain_list(char *);
70
71 static int proc_calc_metrics(char *page, char **start, off_t off,
72                                  int count, int *eof, int len)
73 {
74         if (len <= off+count) *eof = 1;
75         *start = page + off;
76         len -= off;
77         if (len>count) len = count;
78         if (len<0) len = 0;
79         return len;
80 }
81
82 static int loadavg_read_proc(char *page, char **start, off_t off,
83                                  int count, int *eof, void *data)
84 {
85         int a, b, c;
86         int len;
87         unsigned long seq;
88
89         do {
90                 seq = read_seqbegin(&xtime_lock);
91                 a = avenrun[0] + (FIXED_1/200);
92                 b = avenrun[1] + (FIXED_1/200);
93                 c = avenrun[2] + (FIXED_1/200);
94         } while (read_seqretry(&xtime_lock, seq));
95
96         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
97                 LOAD_INT(a), LOAD_FRAC(a),
98                 LOAD_INT(b), LOAD_FRAC(b),
99                 LOAD_INT(c), LOAD_FRAC(c),
100                 nr_running(), nr_threads,
101                 task_active_pid_ns(current)->last_pid);
102         return proc_calc_metrics(page, start, off, count, eof, len);
103 }
104
105 static int uptime_read_proc(char *page, char **start, off_t off,
106                                  int count, int *eof, void *data)
107 {
108         struct timespec uptime;
109         struct timespec idle;
110         int len;
111         cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
112
113         do_posix_clock_monotonic_gettime(&uptime);
114         monotonic_to_bootbased(&uptime);
115         cputime_to_timespec(idletime, &idle);
116         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
117                         (unsigned long) uptime.tv_sec,
118                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
119                         (unsigned long) idle.tv_sec,
120                         (idle.tv_nsec / (NSEC_PER_SEC / 100)));
121
122         return proc_calc_metrics(page, start, off, count, eof, len);
123 }
124
125 int __attribute__((weak)) arch_report_meminfo(char *page)
126 {
127         return 0;
128 }
129
130 static int meminfo_read_proc(char *page, char **start, off_t off,
131                                  int count, int *eof, void *data)
132 {
133         struct sysinfo i;
134         int len;
135         unsigned long committed;
136         unsigned long allowed;
137         struct vmalloc_info vmi;
138         long cached;
139         unsigned long pages[NR_LRU_LISTS];
140         int lru;
141
142 /*
143  * display in kilobytes.
144  */
145 #define K(x) ((x) << (PAGE_SHIFT - 10))
146         si_meminfo(&i);
147         si_swapinfo(&i);
148         committed = atomic_long_read(&vm_committed_space);
149         allowed = ((totalram_pages - hugetlb_total_pages())
150                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
151
152         cached = global_page_state(NR_FILE_PAGES) -
153                         total_swapcache_pages - i.bufferram;
154         if (cached < 0)
155                 cached = 0;
156
157         get_vmalloc_info(&vmi);
158
159         for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
160                 pages[lru] = global_page_state(NR_LRU_BASE + lru);
161
162         /*
163          * Tagged format, for easy grepping and expansion.
164          */
165         len = sprintf(page,
166                 "MemTotal:       %8lu kB\n"
167                 "MemFree:        %8lu kB\n"
168                 "Buffers:        %8lu kB\n"
169                 "Cached:         %8lu kB\n"
170                 "SwapCached:     %8lu kB\n"
171                 "Active:         %8lu kB\n"
172                 "Inactive:       %8lu kB\n"
173                 "Active(anon):   %8lu kB\n"
174                 "Inactive(anon): %8lu kB\n"
175                 "Active(file):   %8lu kB\n"
176                 "Inactive(file): %8lu kB\n"
177 #ifdef CONFIG_UNEVICTABLE_LRU
178                 "Unevictable:    %8lu kB\n"
179                 "Mlocked:        %8lu kB\n"
180 #endif
181 #ifdef CONFIG_HIGHMEM
182                 "HighTotal:      %8lu kB\n"
183                 "HighFree:       %8lu kB\n"
184                 "LowTotal:       %8lu kB\n"
185                 "LowFree:        %8lu kB\n"
186 #endif
187                 "SwapTotal:      %8lu kB\n"
188                 "SwapFree:       %8lu kB\n"
189                 "Dirty:          %8lu kB\n"
190                 "Writeback:      %8lu kB\n"
191                 "AnonPages:      %8lu kB\n"
192                 "Mapped:         %8lu kB\n"
193                 "Slab:           %8lu kB\n"
194                 "SReclaimable:   %8lu kB\n"
195                 "SUnreclaim:     %8lu kB\n"
196                 "PageTables:     %8lu kB\n"
197 #ifdef CONFIG_QUICKLIST
198                 "Quicklists:     %8lu kB\n"
199 #endif
200                 "NFS_Unstable:   %8lu kB\n"
201                 "Bounce:         %8lu kB\n"
202                 "WritebackTmp:   %8lu kB\n"
203                 "CommitLimit:    %8lu kB\n"
204                 "Committed_AS:   %8lu kB\n"
205                 "VmallocTotal:   %8lu kB\n"
206                 "VmallocUsed:    %8lu kB\n"
207                 "VmallocChunk:   %8lu kB\n",
208                 K(i.totalram),
209                 K(i.freeram),
210                 K(i.bufferram),
211                 K(cached),
212                 K(total_swapcache_pages),
213                 K(pages[LRU_ACTIVE_ANON]   + pages[LRU_ACTIVE_FILE]),
214                 K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
215                 K(pages[LRU_ACTIVE_ANON]),
216                 K(pages[LRU_INACTIVE_ANON]),
217                 K(pages[LRU_ACTIVE_FILE]),
218                 K(pages[LRU_INACTIVE_FILE]),
219 #ifdef CONFIG_UNEVICTABLE_LRU
220                 K(pages[LRU_UNEVICTABLE]),
221                 K(global_page_state(NR_MLOCK)),
222 #endif
223 #ifdef CONFIG_HIGHMEM
224                 K(i.totalhigh),
225                 K(i.freehigh),
226                 K(i.totalram-i.totalhigh),
227                 K(i.freeram-i.freehigh),
228 #endif
229                 K(i.totalswap),
230                 K(i.freeswap),
231                 K(global_page_state(NR_FILE_DIRTY)),
232                 K(global_page_state(NR_WRITEBACK)),
233                 K(global_page_state(NR_ANON_PAGES)),
234                 K(global_page_state(NR_FILE_MAPPED)),
235                 K(global_page_state(NR_SLAB_RECLAIMABLE) +
236                                 global_page_state(NR_SLAB_UNRECLAIMABLE)),
237                 K(global_page_state(NR_SLAB_RECLAIMABLE)),
238                 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
239                 K(global_page_state(NR_PAGETABLE)),
240 #ifdef CONFIG_QUICKLIST
241                 K(quicklist_total_size()),
242 #endif
243                 K(global_page_state(NR_UNSTABLE_NFS)),
244                 K(global_page_state(NR_BOUNCE)),
245                 K(global_page_state(NR_WRITEBACK_TEMP)),
246                 K(allowed),
247                 K(committed),
248                 (unsigned long)VMALLOC_TOTAL >> 10,
249                 vmi.used >> 10,
250                 vmi.largest_chunk >> 10
251                 );
252
253                 len += hugetlb_report_meminfo(page + len);
254
255         len += arch_report_meminfo(page + len);
256
257         return proc_calc_metrics(page, start, off, count, eof, len);
258 #undef K
259 }
260
261 static int fragmentation_open(struct inode *inode, struct file *file)
262 {
263         (void)inode;
264         return seq_open(file, &fragmentation_op);
265 }
266
267 static const struct file_operations fragmentation_file_operations = {
268         .open           = fragmentation_open,
269         .read           = seq_read,
270         .llseek         = seq_lseek,
271         .release        = seq_release,
272 };
273
274 static int pagetypeinfo_open(struct inode *inode, struct file *file)
275 {
276         return seq_open(file, &pagetypeinfo_op);
277 }
278
279 static const struct file_operations pagetypeinfo_file_ops = {
280         .open           = pagetypeinfo_open,
281         .read           = seq_read,
282         .llseek         = seq_lseek,
283         .release        = seq_release,
284 };
285
286 static int zoneinfo_open(struct inode *inode, struct file *file)
287 {
288         return seq_open(file, &zoneinfo_op);
289 }
290
291 static const struct file_operations proc_zoneinfo_file_operations = {
292         .open           = zoneinfo_open,
293         .read           = seq_read,
294         .llseek         = seq_lseek,
295         .release        = seq_release,
296 };
297
298 static int version_read_proc(char *page, char **start, off_t off,
299                                  int count, int *eof, void *data)
300 {
301         int len;
302
303         len = snprintf(page, PAGE_SIZE, linux_proc_banner,
304                 utsname()->sysname,
305                 utsname()->release,
306                 utsname()->version);
307         return proc_calc_metrics(page, start, off, count, eof, len);
308 }
309
310 extern const struct seq_operations cpuinfo_op;
311 static int cpuinfo_open(struct inode *inode, struct file *file)
312 {
313         return seq_open(file, &cpuinfo_op);
314 }
315
316 static const struct file_operations proc_cpuinfo_operations = {
317         .open           = cpuinfo_open,
318         .read           = seq_read,
319         .llseek         = seq_lseek,
320         .release        = seq_release,
321 };
322
323 static int devinfo_show(struct seq_file *f, void *v)
324 {
325         int i = *(loff_t *) v;
326
327         if (i < CHRDEV_MAJOR_HASH_SIZE) {
328                 if (i == 0)
329                         seq_printf(f, "Character devices:\n");
330                 chrdev_show(f, i);
331         }
332 #ifdef CONFIG_BLOCK
333         else {
334                 i -= CHRDEV_MAJOR_HASH_SIZE;
335                 if (i == 0)
336                         seq_printf(f, "\nBlock devices:\n");
337                 blkdev_show(f, i);
338         }
339 #endif
340         return 0;
341 }
342
343 static void *devinfo_start(struct seq_file *f, loff_t *pos)
344 {
345         if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
346                 return pos;
347         return NULL;
348 }
349
350 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
351 {
352         (*pos)++;
353         if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
354                 return NULL;
355         return pos;
356 }
357
358 static void devinfo_stop(struct seq_file *f, void *v)
359 {
360         /* Nothing to do */
361 }
362
363 static const struct seq_operations devinfo_ops = {
364         .start = devinfo_start,
365         .next  = devinfo_next,
366         .stop  = devinfo_stop,
367         .show  = devinfo_show
368 };
369
370 static int devinfo_open(struct inode *inode, struct file *filp)
371 {
372         return seq_open(filp, &devinfo_ops);
373 }
374
375 static const struct file_operations proc_devinfo_operations = {
376         .open           = devinfo_open,
377         .read           = seq_read,
378         .llseek         = seq_lseek,
379         .release        = seq_release,
380 };
381
382 static int vmstat_open(struct inode *inode, struct file *file)
383 {
384         return seq_open(file, &vmstat_op);
385 }
386 static const struct file_operations proc_vmstat_file_operations = {
387         .open           = vmstat_open,
388         .read           = seq_read,
389         .llseek         = seq_lseek,
390         .release        = seq_release,
391 };
392
393 #ifdef CONFIG_PROC_HARDWARE
394 static int hardware_read_proc(char *page, char **start, off_t off,
395                                  int count, int *eof, void *data)
396 {
397         int len = get_hardware_list(page);
398         return proc_calc_metrics(page, start, off, count, eof, len);
399 }
400 #endif
401
402 #ifdef CONFIG_STRAM_PROC
403 static int stram_read_proc(char *page, char **start, off_t off,
404                                  int count, int *eof, void *data)
405 {
406         int len = get_stram_list(page);
407         return proc_calc_metrics(page, start, off, count, eof, len);
408 }
409 #endif
410
411 #ifdef CONFIG_BLOCK
412 static int partitions_open(struct inode *inode, struct file *file)
413 {
414         return seq_open(file, &partitions_op);
415 }
416 static const struct file_operations proc_partitions_operations = {
417         .open           = partitions_open,
418         .read           = seq_read,
419         .llseek         = seq_lseek,
420         .release        = seq_release,
421 };
422
423 static int diskstats_open(struct inode *inode, struct file *file)
424 {
425         return seq_open(file, &diskstats_op);
426 }
427 static const struct file_operations proc_diskstats_operations = {
428         .open           = diskstats_open,
429         .read           = seq_read,
430         .llseek         = seq_lseek,
431         .release        = seq_release,
432 };
433 #endif
434
435 #ifdef CONFIG_MODULES
436 extern const struct seq_operations modules_op;
437 static int modules_open(struct inode *inode, struct file *file)
438 {
439         return seq_open(file, &modules_op);
440 }
441 static const struct file_operations proc_modules_operations = {
442         .open           = modules_open,
443         .read           = seq_read,
444         .llseek         = seq_lseek,
445         .release        = seq_release,
446 };
447 #endif
448
449 #ifdef CONFIG_SLABINFO
450 static int slabinfo_open(struct inode *inode, struct file *file)
451 {
452         return seq_open(file, &slabinfo_op);
453 }
454 static const struct file_operations proc_slabinfo_operations = {
455         .open           = slabinfo_open,
456         .read           = seq_read,
457         .write          = slabinfo_write,
458         .llseek         = seq_lseek,
459         .release        = seq_release,
460 };
461
462 #ifdef CONFIG_DEBUG_SLAB_LEAK
463 extern const struct seq_operations slabstats_op;
464 static int slabstats_open(struct inode *inode, struct file *file)
465 {
466         unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
467         int ret = -ENOMEM;
468         if (n) {
469                 ret = seq_open(file, &slabstats_op);
470                 if (!ret) {
471                         struct seq_file *m = file->private_data;
472                         *n = PAGE_SIZE / (2 * sizeof(unsigned long));
473                         m->private = n;
474                         n = NULL;
475                 }
476                 kfree(n);
477         }
478         return ret;
479 }
480
481 static const struct file_operations proc_slabstats_operations = {
482         .open           = slabstats_open,
483         .read           = seq_read,
484         .llseek         = seq_lseek,
485         .release        = seq_release_private,
486 };
487 #endif
488 #endif
489
490 #ifdef CONFIG_MMU
491 static int vmalloc_open(struct inode *inode, struct file *file)
492 {
493         unsigned int *ptr = NULL;
494         int ret;
495
496         if (NUMA_BUILD)
497                 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
498         ret = seq_open(file, &vmalloc_op);
499         if (!ret) {
500                 struct seq_file *m = file->private_data;
501                 m->private = ptr;
502         } else
503                 kfree(ptr);
504         return ret;
505 }
506
507 static const struct file_operations proc_vmalloc_operations = {
508         .open           = vmalloc_open,
509         .read           = seq_read,
510         .llseek         = seq_lseek,
511         .release        = seq_release_private,
512 };
513 #endif
514
515 #ifndef arch_irq_stat_cpu
516 #define arch_irq_stat_cpu(cpu) 0
517 #endif
518 #ifndef arch_irq_stat
519 #define arch_irq_stat() 0
520 #endif
521
522 static int show_stat(struct seq_file *p, void *v)
523 {
524         int i;
525         unsigned long jif;
526         cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
527         cputime64_t guest;
528         u64 sum = 0;
529         struct timespec boottime;
530         unsigned int *per_irq_sum;
531
532         per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
533         if (!per_irq_sum)
534                 return -ENOMEM;
535
536         user = nice = system = idle = iowait =
537                 irq = softirq = steal = cputime64_zero;
538         guest = cputime64_zero;
539         getboottime(&boottime);
540         jif = boottime.tv_sec;
541
542         for_each_possible_cpu(i) {
543                 int j;
544
545                 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
546                 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
547                 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
548                 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
549                 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
550                 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
551                 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
552                 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
553                 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
554                 for (j = 0; j < NR_IRQS; j++) {
555                         unsigned int temp = kstat_cpu(i).irqs[j];
556                         sum += temp;
557                         per_irq_sum[j] += temp;
558                 }
559                 sum += arch_irq_stat_cpu(i);
560         }
561         sum += arch_irq_stat();
562
563         seq_printf(p, "cpu  %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
564                 (unsigned long long)cputime64_to_clock_t(user),
565                 (unsigned long long)cputime64_to_clock_t(nice),
566                 (unsigned long long)cputime64_to_clock_t(system),
567                 (unsigned long long)cputime64_to_clock_t(idle),
568                 (unsigned long long)cputime64_to_clock_t(iowait),
569                 (unsigned long long)cputime64_to_clock_t(irq),
570                 (unsigned long long)cputime64_to_clock_t(softirq),
571                 (unsigned long long)cputime64_to_clock_t(steal),
572                 (unsigned long long)cputime64_to_clock_t(guest));
573         for_each_online_cpu(i) {
574
575                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
576                 user = kstat_cpu(i).cpustat.user;
577                 nice = kstat_cpu(i).cpustat.nice;
578                 system = kstat_cpu(i).cpustat.system;
579                 idle = kstat_cpu(i).cpustat.idle;
580                 iowait = kstat_cpu(i).cpustat.iowait;
581                 irq = kstat_cpu(i).cpustat.irq;
582                 softirq = kstat_cpu(i).cpustat.softirq;
583                 steal = kstat_cpu(i).cpustat.steal;
584                 guest = kstat_cpu(i).cpustat.guest;
585                 seq_printf(p,
586                         "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
587                         i,
588                         (unsigned long long)cputime64_to_clock_t(user),
589                         (unsigned long long)cputime64_to_clock_t(nice),
590                         (unsigned long long)cputime64_to_clock_t(system),
591                         (unsigned long long)cputime64_to_clock_t(idle),
592                         (unsigned long long)cputime64_to_clock_t(iowait),
593                         (unsigned long long)cputime64_to_clock_t(irq),
594                         (unsigned long long)cputime64_to_clock_t(softirq),
595                         (unsigned long long)cputime64_to_clock_t(steal),
596                         (unsigned long long)cputime64_to_clock_t(guest));
597         }
598         seq_printf(p, "intr %llu", (unsigned long long)sum);
599
600         for (i = 0; i < NR_IRQS; i++)
601                 seq_printf(p, " %u", per_irq_sum[i]);
602
603         seq_printf(p,
604                 "\nctxt %llu\n"
605                 "btime %lu\n"
606                 "processes %lu\n"
607                 "procs_running %lu\n"
608                 "procs_blocked %lu\n",
609                 nr_context_switches(),
610                 (unsigned long)jif,
611                 total_forks,
612                 nr_running(),
613                 nr_iowait());
614
615         kfree(per_irq_sum);
616         return 0;
617 }
618
619 static int stat_open(struct inode *inode, struct file *file)
620 {
621         unsigned size = 4096 * (1 + num_possible_cpus() / 32);
622         char *buf;
623         struct seq_file *m;
624         int res;
625
626         /* don't ask for more than the kmalloc() max size, currently 128 KB */
627         if (size > 128 * 1024)
628                 size = 128 * 1024;
629         buf = kmalloc(size, GFP_KERNEL);
630         if (!buf)
631                 return -ENOMEM;
632
633         res = single_open(file, show_stat, NULL);
634         if (!res) {
635                 m = file->private_data;
636                 m->buf = buf;
637                 m->size = size;
638         } else
639                 kfree(buf);
640         return res;
641 }
642 static const struct file_operations proc_stat_operations = {
643         .open           = stat_open,
644         .read           = seq_read,
645         .llseek         = seq_lseek,
646         .release        = single_release,
647 };
648
649 /*
650  * /proc/interrupts
651  */
652 static void *int_seq_start(struct seq_file *f, loff_t *pos)
653 {
654         return (*pos <= NR_IRQS) ? pos : NULL;
655 }
656
657 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
658 {
659         (*pos)++;
660         if (*pos > NR_IRQS)
661                 return NULL;
662         return pos;
663 }
664
665 static void int_seq_stop(struct seq_file *f, void *v)
666 {
667         /* Nothing to do */
668 }
669
670
671 static const struct seq_operations int_seq_ops = {
672         .start = int_seq_start,
673         .next  = int_seq_next,
674         .stop  = int_seq_stop,
675         .show  = show_interrupts
676 };
677
678 static int interrupts_open(struct inode *inode, struct file *filp)
679 {
680         return seq_open(filp, &int_seq_ops);
681 }
682
683 static const struct file_operations proc_interrupts_operations = {
684         .open           = interrupts_open,
685         .read           = seq_read,
686         .llseek         = seq_lseek,
687         .release        = seq_release,
688 };
689
690 static int filesystems_read_proc(char *page, char **start, off_t off,
691                                  int count, int *eof, void *data)
692 {
693         int len = get_filesystem_list(page);
694         return proc_calc_metrics(page, start, off, count, eof, len);
695 }
696
697 static int cmdline_read_proc(char *page, char **start, off_t off,
698                                  int count, int *eof, void *data)
699 {
700         int len;
701
702         len = sprintf(page, "%s\n", saved_command_line);
703         return proc_calc_metrics(page, start, off, count, eof, len);
704 }
705
706 #ifdef CONFIG_FILE_LOCKING
707 static int locks_open(struct inode *inode, struct file *filp)
708 {
709         return seq_open(filp, &locks_seq_operations);
710 }
711
712 static const struct file_operations proc_locks_operations = {
713         .open           = locks_open,
714         .read           = seq_read,
715         .llseek         = seq_lseek,
716         .release        = seq_release,
717 };
718 #endif /* CONFIG_FILE_LOCKING */
719
720 static int execdomains_read_proc(char *page, char **start, off_t off,
721                                  int count, int *eof, void *data)
722 {
723         int len = get_exec_domain_list(page);
724         return proc_calc_metrics(page, start, off, count, eof, len);
725 }
726
727 #ifdef CONFIG_PROC_PAGE_MONITOR
728 #define KPMSIZE sizeof(u64)
729 #define KPMMASK (KPMSIZE - 1)
730 /* /proc/kpagecount - an array exposing page counts
731  *
732  * Each entry is a u64 representing the corresponding
733  * physical page count.
734  */
735 static ssize_t kpagecount_read(struct file *file, char __user *buf,
736                              size_t count, loff_t *ppos)
737 {
738         u64 __user *out = (u64 __user *)buf;
739         struct page *ppage;
740         unsigned long src = *ppos;
741         unsigned long pfn;
742         ssize_t ret = 0;
743         u64 pcount;
744
745         pfn = src / KPMSIZE;
746         count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
747         if (src & KPMMASK || count & KPMMASK)
748                 return -EINVAL;
749
750         while (count > 0) {
751                 ppage = NULL;
752                 if (pfn_valid(pfn))
753                         ppage = pfn_to_page(pfn);
754                 pfn++;
755                 if (!ppage)
756                         pcount = 0;
757                 else
758                         pcount = page_mapcount(ppage);
759
760                 if (put_user(pcount, out++)) {
761                         ret = -EFAULT;
762                         break;
763                 }
764
765                 count -= KPMSIZE;
766         }
767
768         *ppos += (char __user *)out - buf;
769         if (!ret)
770                 ret = (char __user *)out - buf;
771         return ret;
772 }
773
774 static struct file_operations proc_kpagecount_operations = {
775         .llseek = mem_lseek,
776         .read = kpagecount_read,
777 };
778
779 /* /proc/kpageflags - an array exposing page flags
780  *
781  * Each entry is a u64 representing the corresponding
782  * physical page flags.
783  */
784
785 /* These macros are used to decouple internal flags from exported ones */
786
787 #define KPF_LOCKED     0
788 #define KPF_ERROR      1
789 #define KPF_REFERENCED 2
790 #define KPF_UPTODATE   3
791 #define KPF_DIRTY      4
792 #define KPF_LRU        5
793 #define KPF_ACTIVE     6
794 #define KPF_SLAB       7
795 #define KPF_WRITEBACK  8
796 #define KPF_RECLAIM    9
797 #define KPF_BUDDY     10
798
799 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
800
801 static ssize_t kpageflags_read(struct file *file, char __user *buf,
802                              size_t count, loff_t *ppos)
803 {
804         u64 __user *out = (u64 __user *)buf;
805         struct page *ppage;
806         unsigned long src = *ppos;
807         unsigned long pfn;
808         ssize_t ret = 0;
809         u64 kflags, uflags;
810
811         pfn = src / KPMSIZE;
812         count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
813         if (src & KPMMASK || count & KPMMASK)
814                 return -EINVAL;
815
816         while (count > 0) {
817                 ppage = NULL;
818                 if (pfn_valid(pfn))
819                         ppage = pfn_to_page(pfn);
820                 pfn++;
821                 if (!ppage)
822                         kflags = 0;
823                 else
824                         kflags = ppage->flags;
825
826                 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
827                         kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
828                         kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
829                         kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
830                         kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
831                         kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
832                         kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
833                         kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
834                         kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
835                         kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
836                         kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
837
838                 if (put_user(uflags, out++)) {
839                         ret = -EFAULT;
840                         break;
841                 }
842
843                 count -= KPMSIZE;
844         }
845
846         *ppos += (char __user *)out - buf;
847         if (!ret)
848                 ret = (char __user *)out - buf;
849         return ret;
850 }
851
852 static struct file_operations proc_kpageflags_operations = {
853         .llseek = mem_lseek,
854         .read = kpageflags_read,
855 };
856 #endif /* CONFIG_PROC_PAGE_MONITOR */
857
858 struct proc_dir_entry *proc_root_kcore;
859
860 void __init proc_misc_init(void)
861 {
862         static struct {
863                 char *name;
864                 int (*read_proc)(char*,char**,off_t,int,int*,void*);
865         } *p, simple_ones[] = {
866                 {"loadavg",     loadavg_read_proc},
867                 {"uptime",      uptime_read_proc},
868                 {"meminfo",     meminfo_read_proc},
869                 {"version",     version_read_proc},
870 #ifdef CONFIG_PROC_HARDWARE
871                 {"hardware",    hardware_read_proc},
872 #endif
873 #ifdef CONFIG_STRAM_PROC
874                 {"stram",       stram_read_proc},
875 #endif
876                 {"filesystems", filesystems_read_proc},
877                 {"cmdline",     cmdline_read_proc},
878                 {"execdomains", execdomains_read_proc},
879                 {NULL,}
880         };
881         for (p = simple_ones; p->name; p++)
882                 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
883
884         proc_symlink("mounts", NULL, "self/mounts");
885
886         /* And now for trickier ones */
887 #ifdef CONFIG_PRINTK
888         proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
889 #endif
890 #ifdef CONFIG_FILE_LOCKING
891         proc_create("locks", 0, NULL, &proc_locks_operations);
892 #endif
893         proc_create("devices", 0, NULL, &proc_devinfo_operations);
894         proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
895 #ifdef CONFIG_BLOCK
896         proc_create("partitions", 0, NULL, &proc_partitions_operations);
897 #endif
898         proc_create("stat", 0, NULL, &proc_stat_operations);
899         proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
900 #ifdef CONFIG_SLABINFO
901         proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
902 #ifdef CONFIG_DEBUG_SLAB_LEAK
903         proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
904 #endif
905 #endif
906 #ifdef CONFIG_MMU
907         proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
908 #endif
909         proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
910         proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
911         proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
912         proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
913 #ifdef CONFIG_BLOCK
914         proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
915 #endif
916 #ifdef CONFIG_MODULES
917         proc_create("modules", 0, NULL, &proc_modules_operations);
918 #endif
919 #ifdef CONFIG_SCHEDSTATS
920         proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
921 #endif
922 #ifdef CONFIG_PROC_KCORE
923         proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
924         if (proc_root_kcore)
925                 proc_root_kcore->size =
926                                 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
927 #endif
928 #ifdef CONFIG_PROC_PAGE_MONITOR
929         proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
930         proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
931 #endif
932 #ifdef CONFIG_PROC_VMCORE
933         proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
934 #endif
935 }