aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Cermak <petrcermak@chromium.org>2015-02-12 18:01:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-12 21:54:12 -0500
commit695f055936938c674473ea071ca7359a863551e7 (patch)
tree8975abce255f8d638fa1291beb62803e2d611004
parentd170cf4674768db22b66a1be4be7877d3b2c3874 (diff)
fs/proc/task_mmu.c: add user-space support for resetting mm->hiwater_rss (peak RSS)
Peak resident size of a process can be reset back to the process's current rss value by writing "5" to /proc/pid/clear_refs. The driving use-case for this would be getting the peak RSS value, which can be retrieved from the VmHWM field in /proc/pid/status, per benchmark iteration or test scenario. [akpm@linux-foundation.org: clarify behaviour in documentation] Signed-off-by: Petr Cermak <petrcermak@chromium.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Primiano Tucci <primiano@chromium.org> Cc: Petr Cermak <petrcermak@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/filesystems/proc.txt4
-rw-r--r--fs/proc/task_mmu.c14
-rw-r--r--include/linux/mm.h5
3 files changed, 23 insertions, 0 deletions
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index cf8fc2f0b34b..0b3448dba9ec 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -489,6 +489,10 @@ To clear the bits for the file mapped pages associated with the process
489To clear the soft-dirty bit 489To clear the soft-dirty bit
490 > echo 4 > /proc/PID/clear_refs 490 > echo 4 > /proc/PID/clear_refs
491 491
492To reset the peak resident set size ("high water mark") to the process's
493current value:
494 > echo 5 > /proc/PID/clear_refs
495
492Any other value written to /proc/PID/clear_refs will have no effect. 496Any other value written to /proc/PID/clear_refs will have no effect.
493 497
494The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags 498The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 0e36c1e49fe3..1359a911d194 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -732,6 +732,7 @@ enum clear_refs_types {
732 CLEAR_REFS_ANON, 732 CLEAR_REFS_ANON,
733 CLEAR_REFS_MAPPED, 733 CLEAR_REFS_MAPPED,
734 CLEAR_REFS_SOFT_DIRTY, 734 CLEAR_REFS_SOFT_DIRTY,
735 CLEAR_REFS_MM_HIWATER_RSS,
735 CLEAR_REFS_LAST, 736 CLEAR_REFS_LAST,
736}; 737};
737 738
@@ -907,6 +908,18 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
907 .mm = mm, 908 .mm = mm,
908 .private = &cp, 909 .private = &cp,
909 }; 910 };
911
912 if (type == CLEAR_REFS_MM_HIWATER_RSS) {
913 /*
914 * Writing 5 to /proc/pid/clear_refs resets the peak
915 * resident set size to this mm's current rss value.
916 */
917 down_write(&mm->mmap_sem);
918 reset_mm_hiwater_rss(mm);
919 up_write(&mm->mmap_sem);
920 goto out_mm;
921 }
922
910 down_read(&mm->mmap_sem); 923 down_read(&mm->mmap_sem);
911 if (type == CLEAR_REFS_SOFT_DIRTY) { 924 if (type == CLEAR_REFS_SOFT_DIRTY) {
912 for (vma = mm->mmap; vma; vma = vma->vm_next) { 925 for (vma = mm->mmap; vma; vma = vma->vm_next) {
@@ -928,6 +941,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
928 mmu_notifier_invalidate_range_end(mm, 0, -1); 941 mmu_notifier_invalidate_range_end(mm, 0, -1);
929 flush_tlb_mm(mm); 942 flush_tlb_mm(mm);
930 up_read(&mm->mmap_sem); 943 up_read(&mm->mmap_sem);
944out_mm:
931 mmput(mm); 945 mmput(mm);
932 } 946 }
933 put_task_struct(task); 947 put_task_struct(task);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index bd52e2f14027..9bee7ec0c31f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1408,6 +1408,11 @@ static inline void update_hiwater_vm(struct mm_struct *mm)
1408 mm->hiwater_vm = mm->total_vm; 1408 mm->hiwater_vm = mm->total_vm;
1409} 1409}
1410 1410
1411static inline void reset_mm_hiwater_rss(struct mm_struct *mm)
1412{
1413 mm->hiwater_rss = get_mm_rss(mm);
1414}
1415
1411static inline void setmax_mm_hiwater_rss(unsigned long *maxrss, 1416static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
1412 struct mm_struct *mm) 1417 struct mm_struct *mm)
1413{ 1418{