aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2008-02-05 01:29:05 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 12:44:17 -0500
commit161f47bf41c5ece90ac53cbb6a4cb9bf74ce0ef6 (patch)
treef6f18c3eb74faf8b2b8de27b42241e9986bd6dc9 /fs/proc
parent85863e475e59afb027b0113290e3796ee6020b7d (diff)
maps4: add /proc/kpagecount interface
This makes physical page map counts available to userspace. Together with /proc/pid/pagemap and /proc/pid/clear_refs, this can be used to monitor memory usage on a per-page basis. [akpm@linux-foundation.org: remove unneeded access_ok()] [bunk@stusta.de: make struct proc_kpagemap static] Signed-off-by: Matt Mackall <mpm@selenic.com> Cc: Jeremy Fitzhardinge <jeremy@goop.org> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Adrian Bunk <bunk@stusta.de> Cc: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/proc_misc.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index 3462bfde89f6..19b69f931bef 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -46,6 +46,7 @@
46#include <linux/vmalloc.h> 46#include <linux/vmalloc.h>
47#include <linux/crash_dump.h> 47#include <linux/crash_dump.h>
48#include <linux/pid_namespace.h> 48#include <linux/pid_namespace.h>
49#include <linux/bootmem.h>
49#include <asm/uaccess.h> 50#include <asm/uaccess.h>
50#include <asm/pgtable.h> 51#include <asm/pgtable.h>
51#include <asm/io.h> 52#include <asm/io.h>
@@ -675,6 +676,54 @@ static const struct file_operations proc_sysrq_trigger_operations = {
675}; 676};
676#endif 677#endif
677 678
679#define KPMSIZE sizeof(u64)
680#define KPMMASK (KPMSIZE - 1)
681/* /proc/kpagecount - an array exposing page counts
682 *
683 * Each entry is a u64 representing the corresponding
684 * physical page count.
685 */
686static ssize_t kpagecount_read(struct file *file, char __user *buf,
687 size_t count, loff_t *ppos)
688{
689 u64 __user *out = (u64 __user *)buf;
690 struct page *ppage;
691 unsigned long src = *ppos;
692 unsigned long pfn;
693 ssize_t ret = 0;
694 u64 pcount;
695
696 pfn = src / KPMSIZE;
697 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
698 if (src & KPMMASK || count & KPMMASK)
699 return -EIO;
700
701 while (count > 0) {
702 ppage = pfn_to_page(pfn++);
703 if (!ppage)
704 pcount = 0;
705 else
706 pcount = atomic_read(&ppage->_count);
707
708 if (put_user(pcount, out++)) {
709 ret = -EFAULT;
710 break;
711 }
712
713 count -= KPMSIZE;
714 }
715
716 *ppos += (char __user *)out - buf;
717 if (!ret)
718 ret = (char __user *)out - buf;
719 return ret;
720}
721
722static struct file_operations proc_kpagecount_operations = {
723 .llseek = mem_lseek,
724 .read = kpagecount_read,
725};
726
678struct proc_dir_entry *proc_root_kcore; 727struct proc_dir_entry *proc_root_kcore;
679 728
680void create_seq_entry(char *name, mode_t mode, const struct file_operations *f) 729void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
@@ -755,6 +804,7 @@ void __init proc_misc_init(void)
755 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; 804 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
756 } 805 }
757#endif 806#endif
807 create_seq_entry("kpagecount", S_IRUSR, &proc_kpagecount_operations);
758#ifdef CONFIG_PROC_VMCORE 808#ifdef CONFIG_PROC_VMCORE
759 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL); 809 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
760 if (proc_vmcore) 810 if (proc_vmcore)