blob: a6fadc0cc4b0d6701116ce22778e5b12e76407a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Neil Horman7170be52006-01-14 13:20:38 -080023#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/tty.h>
25#include <linux/string.h>
26#include <linux/mman.h>
KOSAKI Motohiro4b856152008-09-02 14:35:53 -070027#include <linux/quicklist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
29#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/mm.h>
31#include <linux/mmzone.h>
32#include <linux/pagemap.h>
Yinghai Luc7fb03a2008-08-19 20:50:12 -070033#include <linux/irq.h>
Adrian Bunkf74596d2008-02-06 01:36:35 -080034#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/swap.h>
36#include <linux/slab.h>
Adrian Bunka0db7012008-03-04 11:23:50 +010037#include <linux/genhd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/smp.h>
39#include <linux/signal.h>
40#include <linux/module.h>
41#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/seq_file.h>
43#include <linux/times.h>
44#include <linux/profile.h>
Andrew Morton7bf65382006-12-08 02:41:14 -080045#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/blkdev.h>
47#include <linux/hugetlb.h>
48#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/vmalloc.h>
Vivek Goyal666bfdd2005-06-25 14:58:21 -070050#include <linux/crash_dump.h>
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080051#include <linux/pid_namespace.h>
Matt Mackall161f47b2008-02-04 22:29:05 -080052#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#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"
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static int fragmentation_open(struct inode *inode, struct file *file)
61{
62 (void)inode;
63 return seq_open(file, &fragmentation_op);
64}
65
Arjan van de Ven00977a52007-02-12 00:55:34 -080066static const struct file_operations fragmentation_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .open = fragmentation_open,
68 .read = seq_read,
69 .llseek = seq_lseek,
70 .release = seq_release,
71};
72
Mel Gorman467c9962007-10-16 01:26:02 -070073static int pagetypeinfo_open(struct inode *inode, struct file *file)
74{
75 return seq_open(file, &pagetypeinfo_op);
76}
77
78static const struct file_operations pagetypeinfo_file_ops = {
79 .open = pagetypeinfo_open,
80 .read = seq_read,
81 .llseek = seq_lseek,
82 .release = seq_release,
83};
84
Nikita Danilov295ab932005-06-21 17:14:38 -070085static int zoneinfo_open(struct inode *inode, struct file *file)
86{
87 return seq_open(file, &zoneinfo_op);
88}
89
Arjan van de Ven00977a52007-02-12 00:55:34 -080090static const struct file_operations proc_zoneinfo_file_operations = {
Nikita Danilov295ab932005-06-21 17:14:38 -070091 .open = zoneinfo_open,
92 .read = seq_read,
93 .llseek = seq_lseek,
94 .release = seq_release,
95};
96
Jan Engelhardt03a44822008-02-08 04:21:19 -080097extern const struct seq_operations cpuinfo_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static int cpuinfo_open(struct inode *inode, struct file *file)
99{
100 return seq_open(file, &cpuinfo_op);
101}
Neil Horman7170be52006-01-14 13:20:38 -0800102
Arjan van de Ven00977a52007-02-12 00:55:34 -0800103static const struct file_operations proc_cpuinfo_operations = {
Joe Korty68eef3b2006-03-31 02:30:32 -0800104 .open = cpuinfo_open,
Neil Horman7170be52006-01-14 13:20:38 -0800105 .read = seq_read,
106 .llseek = seq_lseek,
107 .release = seq_release,
108};
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static int vmstat_open(struct inode *inode, struct file *file)
111{
112 return seq_open(file, &vmstat_op);
113}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800114static const struct file_operations proc_vmstat_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 .open = vmstat_open,
116 .read = seq_read,
117 .llseek = seq_lseek,
118 .release = seq_release,
119};
120
David Howells93614012006-09-30 20:45:40 +0200121#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static int partitions_open(struct inode *inode, struct file *file)
123{
124 return seq_open(file, &partitions_op);
125}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800126static const struct file_operations proc_partitions_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .open = partitions_open,
128 .read = seq_read,
129 .llseek = seq_lseek,
130 .release = seq_release,
131};
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static int diskstats_open(struct inode *inode, struct file *file)
134{
135 return seq_open(file, &diskstats_op);
136}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800137static const struct file_operations proc_diskstats_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .open = diskstats_open,
139 .read = seq_read,
140 .llseek = seq_lseek,
141 .release = seq_release,
142};
David Howells93614012006-09-30 20:45:40 +0200143#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145#ifdef CONFIG_MODULES
Jan Engelhardt03a44822008-02-08 04:21:19 -0800146extern const struct seq_operations modules_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static int modules_open(struct inode *inode, struct file *file)
148{
149 return seq_open(file, &modules_op);
150}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800151static const struct file_operations proc_modules_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 .open = modules_open,
153 .read = seq_read,
154 .llseek = seq_lseek,
155 .release = seq_release,
156};
157#endif
158
Linus Torvalds158a9622008-01-02 13:04:48 -0800159#ifdef CONFIG_SLABINFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static int slabinfo_open(struct inode *inode, struct file *file)
161{
162 return seq_open(file, &slabinfo_op);
163}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800164static const struct file_operations proc_slabinfo_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 .open = slabinfo_open,
166 .read = seq_read,
167 .write = slabinfo_write,
168 .llseek = seq_lseek,
169 .release = seq_release,
170};
Al Viro871751e2006-03-25 03:06:39 -0800171
172#ifdef CONFIG_DEBUG_SLAB_LEAK
Jan Engelhardt03a44822008-02-08 04:21:19 -0800173extern const struct seq_operations slabstats_op;
Al Viro871751e2006-03-25 03:06:39 -0800174static int slabstats_open(struct inode *inode, struct file *file)
175{
176 unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
177 int ret = -ENOMEM;
178 if (n) {
179 ret = seq_open(file, &slabstats_op);
180 if (!ret) {
181 struct seq_file *m = file->private_data;
182 *n = PAGE_SIZE / (2 * sizeof(unsigned long));
183 m->private = n;
184 n = NULL;
185 }
186 kfree(n);
187 }
188 return ret;
189}
190
Arjan van de Ven00977a52007-02-12 00:55:34 -0800191static const struct file_operations proc_slabstats_operations = {
Al Viro871751e2006-03-25 03:06:39 -0800192 .open = slabstats_open,
193 .read = seq_read,
194 .llseek = seq_lseek,
Martin Peschke09f08922007-05-08 00:29:26 -0700195 .release = seq_release_private,
Al Viro871751e2006-03-25 03:06:39 -0800196};
197#endif
Matt Mackall10cef602006-01-08 01:01:45 -0800198#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Christoph Lametera10aa572008-04-28 02:12:40 -0700200#ifdef CONFIG_MMU
201static int vmalloc_open(struct inode *inode, struct file *file)
202{
Eric Dumazeta47a1262008-07-23 21:27:38 -0700203 unsigned int *ptr = NULL;
204 int ret;
205
206 if (NUMA_BUILD)
207 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
208 ret = seq_open(file, &vmalloc_op);
209 if (!ret) {
210 struct seq_file *m = file->private_data;
211 m->private = ptr;
212 } else
213 kfree(ptr);
214 return ret;
Christoph Lametera10aa572008-04-28 02:12:40 -0700215}
216
217static const struct file_operations proc_vmalloc_operations = {
218 .open = vmalloc_open,
219 .read = seq_read,
220 .llseek = seq_lseek,
Eric Dumazeta47a1262008-07-23 21:27:38 -0700221 .release = seq_release_private,
Christoph Lametera10aa572008-04-28 02:12:40 -0700222};
223#endif
224
Jan Beulicha2eddfa2008-05-12 15:44:41 +0200225#ifndef arch_irq_stat_cpu
226#define arch_irq_stat_cpu(cpu) 0
227#endif
228#ifndef arch_irq_stat
229#define arch_irq_stat() 0
230#endif
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static int show_stat(struct seq_file *p, void *v)
233{
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700234 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 unsigned long jif;
236 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200237 cputime64_t guest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 u64 sum = 0;
Tomas Janousek924b42d2007-07-15 23:39:42 -0700239 struct timespec boottime;
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700240 unsigned int per_irq_sum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 user = nice = system = idle = iowait =
243 irq = softirq = steal = cputime64_zero;
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200244 guest = cputime64_zero;
Tomas Janousek924b42d2007-07-15 23:39:42 -0700245 getboottime(&boottime);
246 jif = boottime.tv_sec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800248 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
250 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
251 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
252 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
253 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
254 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
255 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
256 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200257 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700258
Thomas Gleixner2be3b522008-10-16 14:50:27 +0200259 for_each_irq_nr(j)
Thomas Gleixner2cc21ef2008-10-15 14:16:55 +0200260 sum += kstat_irqs_cpu(j, i);
261
Jan Beulicha2eddfa2008-05-12 15:44:41 +0200262 sum += arch_irq_stat_cpu(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Jan Beulicha2eddfa2008-05-12 15:44:41 +0200264 sum += arch_irq_stat();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200266 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 (unsigned long long)cputime64_to_clock_t(user),
268 (unsigned long long)cputime64_to_clock_t(nice),
269 (unsigned long long)cputime64_to_clock_t(system),
270 (unsigned long long)cputime64_to_clock_t(idle),
271 (unsigned long long)cputime64_to_clock_t(iowait),
272 (unsigned long long)cputime64_to_clock_t(irq),
273 (unsigned long long)cputime64_to_clock_t(softirq),
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200274 (unsigned long long)cputime64_to_clock_t(steal),
275 (unsigned long long)cputime64_to_clock_t(guest));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 for_each_online_cpu(i) {
277
278 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
279 user = kstat_cpu(i).cpustat.user;
280 nice = kstat_cpu(i).cpustat.nice;
281 system = kstat_cpu(i).cpustat.system;
282 idle = kstat_cpu(i).cpustat.idle;
283 iowait = kstat_cpu(i).cpustat.iowait;
284 irq = kstat_cpu(i).cpustat.irq;
285 softirq = kstat_cpu(i).cpustat.softirq;
286 steal = kstat_cpu(i).cpustat.steal;
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200287 guest = kstat_cpu(i).cpustat.guest;
288 seq_printf(p,
289 "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 i,
291 (unsigned long long)cputime64_to_clock_t(user),
292 (unsigned long long)cputime64_to_clock_t(nice),
293 (unsigned long long)cputime64_to_clock_t(system),
294 (unsigned long long)cputime64_to_clock_t(idle),
295 (unsigned long long)cputime64_to_clock_t(iowait),
296 (unsigned long long)cputime64_to_clock_t(irq),
297 (unsigned long long)cputime64_to_clock_t(softirq),
Laurent Vivier5e84cfd2007-10-15 17:00:19 +0200298 (unsigned long long)cputime64_to_clock_t(steal),
299 (unsigned long long)cputime64_to_clock_t(guest));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301 seq_printf(p, "intr %llu", (unsigned long long)sum);
302
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700303 /* sum again ? it could be updated? */
Thomas Gleixner2be3b522008-10-16 14:50:27 +0200304 for_each_irq_nr(j) {
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700305 per_irq_sum = 0;
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700306
Thomas Gleixner2cc21ef2008-10-15 14:16:55 +0200307 for_each_possible_cpu(i)
308 per_irq_sum += kstat_irqs_cpu(j, i);
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700309
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700310 seq_printf(p, " %u", per_irq_sum);
Yinghai Luc7fb03a2008-08-19 20:50:12 -0700311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 seq_printf(p,
314 "\nctxt %llu\n"
315 "btime %lu\n"
316 "processes %lu\n"
317 "procs_running %lu\n"
318 "procs_blocked %lu\n",
319 nr_context_switches(),
320 (unsigned long)jif,
321 total_forks,
322 nr_running(),
323 nr_iowait());
324
325 return 0;
326}
327
328static int stat_open(struct inode *inode, struct file *file)
329{
330 unsigned size = 4096 * (1 + num_possible_cpus() / 32);
331 char *buf;
332 struct seq_file *m;
333 int res;
334
335 /* don't ask for more than the kmalloc() max size, currently 128 KB */
336 if (size > 128 * 1024)
337 size = 128 * 1024;
338 buf = kmalloc(size, GFP_KERNEL);
339 if (!buf)
340 return -ENOMEM;
341
342 res = single_open(file, show_stat, NULL);
343 if (!res) {
344 m = file->private_data;
345 m->buf = buf;
346 m->size = size;
347 } else
348 kfree(buf);
349 return res;
350}
Arjan van de Ven00977a52007-02-12 00:55:34 -0800351static const struct file_operations proc_stat_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 .open = stat_open,
353 .read = seq_read,
354 .llseek = seq_lseek,
355 .release = single_release,
356};
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*
359 * /proc/interrupts
360 */
361static void *int_seq_start(struct seq_file *f, loff_t *pos)
362{
Yinghai Luda27c112008-08-19 20:49:56 -0700363 return (*pos <= nr_irqs) ? pos : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Yinghai Lu52b17322008-08-19 20:50:20 -0700366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
368{
369 (*pos)++;
Yinghai Lu52b17322008-08-19 20:50:20 -0700370 return (*pos <= nr_irqs) ? pos : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
373static void int_seq_stop(struct seq_file *f, void *v)
374{
375 /* Nothing to do */
376}
377
Jan Engelhardt03a44822008-02-08 04:21:19 -0800378static const struct seq_operations int_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .start = int_seq_start,
380 .next = int_seq_next,
381 .stop = int_seq_stop,
382 .show = show_interrupts
383};
384
385static int interrupts_open(struct inode *inode, struct file *filp)
386{
387 return seq_open(filp, &int_seq_ops);
388}
389
Arjan van de Ven00977a52007-02-12 00:55:34 -0800390static const struct file_operations proc_interrupts_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .open = interrupts_open,
392 .read = seq_read,
393 .llseek = seq_lseek,
394 .release = seq_release,
395};
396
Matt Mackall1e883282008-02-04 22:29:07 -0800397#ifdef CONFIG_PROC_PAGE_MONITOR
Matt Mackall161f47b2008-02-04 22:29:05 -0800398#define KPMSIZE sizeof(u64)
399#define KPMMASK (KPMSIZE - 1)
400/* /proc/kpagecount - an array exposing page counts
401 *
402 * Each entry is a u64 representing the corresponding
403 * physical page count.
404 */
405static ssize_t kpagecount_read(struct file *file, char __user *buf,
406 size_t count, loff_t *ppos)
407{
408 u64 __user *out = (u64 __user *)buf;
409 struct page *ppage;
410 unsigned long src = *ppos;
411 unsigned long pfn;
412 ssize_t ret = 0;
413 u64 pcount;
414
415 pfn = src / KPMSIZE;
416 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
417 if (src & KPMMASK || count & KPMMASK)
Thomas Tuttle4710d1a2008-06-05 22:46:58 -0700418 return -EINVAL;
Matt Mackall161f47b2008-02-04 22:29:05 -0800419
420 while (count > 0) {
Matt Mackall304daa82008-02-04 22:29:06 -0800421 ppage = NULL;
422 if (pfn_valid(pfn))
423 ppage = pfn_to_page(pfn);
424 pfn++;
Matt Mackall161f47b2008-02-04 22:29:05 -0800425 if (!ppage)
426 pcount = 0;
427 else
Thomas Tuttlebbcdac02008-06-05 22:46:58 -0700428 pcount = page_mapcount(ppage);
Matt Mackall161f47b2008-02-04 22:29:05 -0800429
430 if (put_user(pcount, out++)) {
431 ret = -EFAULT;
432 break;
433 }
434
435 count -= KPMSIZE;
436 }
437
438 *ppos += (char __user *)out - buf;
439 if (!ret)
440 ret = (char __user *)out - buf;
441 return ret;
442}
443
444static struct file_operations proc_kpagecount_operations = {
445 .llseek = mem_lseek,
446 .read = kpagecount_read,
447};
448
Matt Mackall304daa82008-02-04 22:29:06 -0800449/* /proc/kpageflags - an array exposing page flags
450 *
451 * Each entry is a u64 representing the corresponding
452 * physical page flags.
453 */
454
455/* These macros are used to decouple internal flags from exported ones */
456
457#define KPF_LOCKED 0
458#define KPF_ERROR 1
459#define KPF_REFERENCED 2
460#define KPF_UPTODATE 3
461#define KPF_DIRTY 4
462#define KPF_LRU 5
463#define KPF_ACTIVE 6
464#define KPF_SLAB 7
465#define KPF_WRITEBACK 8
466#define KPF_RECLAIM 9
467#define KPF_BUDDY 10
468
469#define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
470
471static ssize_t kpageflags_read(struct file *file, char __user *buf,
472 size_t count, loff_t *ppos)
473{
474 u64 __user *out = (u64 __user *)buf;
475 struct page *ppage;
476 unsigned long src = *ppos;
477 unsigned long pfn;
478 ssize_t ret = 0;
479 u64 kflags, uflags;
480
481 pfn = src / KPMSIZE;
482 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
483 if (src & KPMMASK || count & KPMMASK)
Thomas Tuttle4710d1a2008-06-05 22:46:58 -0700484 return -EINVAL;
Matt Mackall304daa82008-02-04 22:29:06 -0800485
486 while (count > 0) {
487 ppage = NULL;
488 if (pfn_valid(pfn))
489 ppage = pfn_to_page(pfn);
490 pfn++;
491 if (!ppage)
492 kflags = 0;
493 else
494 kflags = ppage->flags;
495
496 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
497 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
498 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
499 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
500 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
501 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
502 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
503 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
504 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
505 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
506 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
507
508 if (put_user(uflags, out++)) {
509 ret = -EFAULT;
510 break;
511 }
512
513 count -= KPMSIZE;
514 }
515
516 *ppos += (char __user *)out - buf;
517 if (!ret)
518 ret = (char __user *)out - buf;
519 return ret;
520}
521
522static struct file_operations proc_kpageflags_operations = {
523 .llseek = mem_lseek,
524 .read = kpageflags_read,
525};
Matt Mackall1e883282008-02-04 22:29:07 -0800526#endif /* CONFIG_PROC_PAGE_MONITOR */
Matt Mackall304daa82008-02-04 22:29:06 -0800527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528struct proc_dir_entry *proc_root_kcore;
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530void __init proc_misc_init(void)
531{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 proc_symlink("mounts", NULL, "self/mounts");
533
534 /* And now for trickier ones */
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700535 proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
David Howells93614012006-09-30 20:45:40 +0200536#ifdef CONFIG_BLOCK
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700537 proc_create("partitions", 0, NULL, &proc_partitions_operations);
David Howells93614012006-09-30 20:45:40 +0200538#endif
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700539 proc_create("stat", 0, NULL, &proc_stat_operations);
540 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
Linus Torvalds158a9622008-01-02 13:04:48 -0800541#ifdef CONFIG_SLABINFO
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700542 proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
Al Viro871751e2006-03-25 03:06:39 -0800543#ifdef CONFIG_DEBUG_SLAB_LEAK
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700544 proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
Al Viro871751e2006-03-25 03:06:39 -0800545#endif
Matt Mackall10cef602006-01-08 01:01:45 -0800546#endif
Christoph Lametera10aa572008-04-28 02:12:40 -0700547#ifdef CONFIG_MMU
548 proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
549#endif
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700550 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
551 proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
552 proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
553 proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
David Howells93614012006-09-30 20:45:40 +0200554#ifdef CONFIG_BLOCK
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700555 proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
David Howells93614012006-09-30 20:45:40 +0200556#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#ifdef CONFIG_MODULES
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700558 proc_create("modules", 0, NULL, &proc_modules_operations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#endif
560#ifdef CONFIG_SCHEDSTATS
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700561 proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#endif
563#ifdef CONFIG_PROC_KCORE
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700564 proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
565 if (proc_root_kcore)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 proc_root_kcore->size =
567 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#endif
Matt Mackall1e883282008-02-04 22:29:07 -0800569#ifdef CONFIG_PROC_PAGE_MONITOR
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700570 proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
571 proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
Matt Mackall1e883282008-02-04 22:29:07 -0800572#endif
Vivek Goyal666bfdd2005-06-25 14:58:21 -0700573#ifdef CONFIG_PROC_VMCORE
Alexey Dobriyan0d5c9f52008-04-29 01:01:37 -0700574 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
Vivek Goyal666bfdd2005-06-25 14:58:21 -0700575#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}