mirror of
https://github.com/torvalds/linux.git
synced 2026-06-08 06:25:52 +02:00
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. Origin: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=695f055936938c674473ea071ca7359a863551e7 [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> Change-Id: I543a7640639d9916e813af875003fe3ee3a6bfe0
This commit is contained in:
parent
428e6d675d
commit
740006ef28
|
|
@ -490,6 +490,10 @@ To clear the bits for the file mapped pages associated with the process
|
|||
> echo 3 > /proc/PID/clear_refs
|
||||
Any other value written to /proc/PID/clear_refs will have no effect.
|
||||
|
||||
To reset the peak resident set size ("high water mark") to the process's
|
||||
current value:
|
||||
> echo 5 > /proc/PID/clear_refs
|
||||
|
||||
The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags
|
||||
using /proc/kpageflags and number of times a page is mapped using
|
||||
/proc/kpagecount. For detailed explanation, see Documentation/vm/pagemap.txt.
|
||||
|
|
|
|||
|
|
@ -784,6 +784,7 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
|
|||
#define CLEAR_REFS_ALL 1
|
||||
#define CLEAR_REFS_ANON 2
|
||||
#define CLEAR_REFS_MAPPED 3
|
||||
#define CLEAR_REFS_MM_HIWATER_RSS 5
|
||||
|
||||
static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
|
|
@ -803,7 +804,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
|||
rv = kstrtoint(strstrip(buffer), 10, &type);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
|
||||
if ((type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED) &&
|
||||
type != CLEAR_REFS_MM_HIWATER_RSS)
|
||||
return -EINVAL;
|
||||
task = get_proc_task(file_inode(file));
|
||||
if (!task)
|
||||
|
|
@ -814,6 +816,18 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
|||
.pmd_entry = clear_refs_pte_range,
|
||||
.mm = mm,
|
||||
};
|
||||
|
||||
if (type == CLEAR_REFS_MM_HIWATER_RSS) {
|
||||
/*
|
||||
* Writing 5 to /proc/pid/clear_refs resets the peak
|
||||
* resident set size to this mm's current rss value.
|
||||
*/
|
||||
down_write(&mm->mmap_sem);
|
||||
reset_mm_hiwater_rss(mm);
|
||||
up_write(&mm->mmap_sem);
|
||||
goto out_mm;
|
||||
}
|
||||
|
||||
down_read(&mm->mmap_sem);
|
||||
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
||||
clear_refs_walk.private = vma;
|
||||
|
|
@ -837,6 +851,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
|||
}
|
||||
flush_tlb_mm(mm);
|
||||
up_read(&mm->mmap_sem);
|
||||
out_mm:
|
||||
mmput(mm);
|
||||
}
|
||||
put_task_struct(task);
|
||||
|
|
|
|||
|
|
@ -1166,6 +1166,11 @@ static inline void update_hiwater_vm(struct mm_struct *mm)
|
|||
mm->hiwater_vm = mm->total_vm;
|
||||
}
|
||||
|
||||
static inline void reset_mm_hiwater_rss(struct mm_struct *mm)
|
||||
{
|
||||
mm->hiwater_rss = get_mm_rss(mm);
|
||||
}
|
||||
|
||||
static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
|
||||
struct mm_struct *mm)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user