aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/base.c
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2007-05-06 17:49:24 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-07 15:12:52 -0400
commitb813e931b4c8235bb42e301096ea97dbdee3e8fe (patch)
treef8182687bffe8e3b95bac69b2cc7fdfe674ddc53 /fs/proc/base.c
parentf79f177c25016647cc92ffac8afa7cb96ce47011 (diff)
smaps: add clear_refs file to clear reference
Adds /proc/pid/clear_refs. When any non-zero number is written to this file, pte_mkold() and ClearPageReferenced() is called for each pte and its corresponding page, respectively, in that task's VMAs. This file is only writable by the user who owns the task. It is now possible to measure _approximately_ how much memory a task is using by clearing the reference bits with echo 1 > /proc/pid/clear_refs and checking the reference count for each VMA from the /proc/pid/smaps output at a measured time interval. For example, to observe the approximate change in memory footprint for a task, write a script that clears the references (echo 1 > /proc/pid/clear_refs), sleeps, and then greps for Pgs_Referenced and extracts the size in kB. Add the sizes for each VMA together for the total referenced footprint. Moments later, repeat the process and observe the difference. For example, using an efficient Mozilla: accumulated time referenced memory ---------------- ----------------- 0 s 408 kB 1 s 408 kB 2 s 556 kB 3 s 1028 kB 4 s 872 kB 5 s 1956 kB 6 s 416 kB 7 s 1560 kB 8 s 2336 kB 9 s 1044 kB 10 s 416 kB This is a valuable tool to get an approximate measurement of the memory footprint for a task. Cc: Hugh Dickins <hugh@veritas.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Christoph Lameter <clameter@sgi.com> Signed-off-by: David Rientjes <rientjes@google.com> [akpm@linux-foundation.org: build fixes] [mpm@selenic.com: rename for_each_pmd] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r--fs/proc/base.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 989af5e55d1b..ec158dd02b3a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -715,6 +715,40 @@ static const struct file_operations proc_oom_adjust_operations = {
715 .write = oom_adjust_write, 715 .write = oom_adjust_write,
716}; 716};
717 717
718static ssize_t clear_refs_write(struct file *file, const char __user *buf,
719 size_t count, loff_t *ppos)
720{
721 struct task_struct *task;
722 char buffer[PROC_NUMBUF], *end;
723 struct mm_struct *mm;
724
725 memset(buffer, 0, sizeof(buffer));
726 if (count > sizeof(buffer) - 1)
727 count = sizeof(buffer) - 1;
728 if (copy_from_user(buffer, buf, count))
729 return -EFAULT;
730 if (!simple_strtol(buffer, &end, 0))
731 return -EINVAL;
732 if (*end == '\n')
733 end++;
734 task = get_proc_task(file->f_path.dentry->d_inode);
735 if (!task)
736 return -ESRCH;
737 mm = get_task_mm(task);
738 if (mm) {
739 clear_refs_smap(mm);
740 mmput(mm);
741 }
742 put_task_struct(task);
743 if (end - buffer == 0)
744 return -EIO;
745 return end - buffer;
746}
747
748static struct file_operations proc_clear_refs_operations = {
749 .write = clear_refs_write,
750};
751
718#ifdef CONFIG_AUDITSYSCALL 752#ifdef CONFIG_AUDITSYSCALL
719#define TMPBUFLEN 21 753#define TMPBUFLEN 21
720static ssize_t proc_loginuid_read(struct file * file, char __user * buf, 754static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
@@ -1851,6 +1885,7 @@ static struct pid_entry tgid_base_stuff[] = {
1851 REG("mounts", S_IRUGO, mounts), 1885 REG("mounts", S_IRUGO, mounts),
1852 REG("mountstats", S_IRUSR, mountstats), 1886 REG("mountstats", S_IRUSR, mountstats),
1853#ifdef CONFIG_MMU 1887#ifdef CONFIG_MMU
1888 REG("clear_refs", S_IWUSR, clear_refs),
1854 REG("smaps", S_IRUGO, smaps), 1889 REG("smaps", S_IRUGO, smaps),
1855#endif 1890#endif
1856#ifdef CONFIG_SECURITY 1891#ifdef CONFIG_SECURITY
@@ -2132,6 +2167,7 @@ static struct pid_entry tid_base_stuff[] = {
2132 LNK("exe", exe), 2167 LNK("exe", exe),
2133 REG("mounts", S_IRUGO, mounts), 2168 REG("mounts", S_IRUGO, mounts),
2134#ifdef CONFIG_MMU 2169#ifdef CONFIG_MMU
2170 REG("clear_refs", S_IWUSR, clear_refs),
2135 REG("smaps", S_IRUGO, smaps), 2171 REG("smaps", S_IRUGO, smaps),
2136#endif 2172#endif
2137#ifdef CONFIG_SECURITY 2173#ifdef CONFIG_SECURITY