Skip to content

Commit 4e80153

Browse files
Michal Hockotorvalds
Michal Hocko
authored andcommitted
mm, proc: make clear_refs killable
CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on mmap_sem for write. If the waiting task gets killed by the oom killer and it would operate on the current's mm it would block oom_reaper from asynchronous address space reclaim and reduce the chances of timely OOM resolving. Wait for the lock in the killable mode and return with EINTR if the task got killed while waiting. This will also expedite the return to the userspace and do_exit even if the mm is remote. Signed-off-by: Michal Hocko <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Petr Cermak <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2d6c928 commit 4e80153

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/proc/task_mmu.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
10271027
};
10281028

10291029
if (type == CLEAR_REFS_MM_HIWATER_RSS) {
1030+
if (down_write_killable(&mm->mmap_sem)) {
1031+
count = -EINTR;
1032+
goto out_mm;
1033+
}
1034+
10301035
/*
10311036
* Writing 5 to /proc/pid/clear_refs resets the peak
10321037
* resident set size to this mm's current rss value.
10331038
*/
1034-
down_write(&mm->mmap_sem);
10351039
reset_mm_hiwater_rss(mm);
10361040
up_write(&mm->mmap_sem);
10371041
goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
10431047
if (!(vma->vm_flags & VM_SOFTDIRTY))
10441048
continue;
10451049
up_read(&mm->mmap_sem);
1046-
down_write(&mm->mmap_sem);
1050+
if (down_write_killable(&mm->mmap_sem)) {
1051+
count = -EINTR;
1052+
goto out_mm;
1053+
}
10471054
for (vma = mm->mmap; vma; vma = vma->vm_next) {
10481055
vma->vm_flags &= ~VM_SOFTDIRTY;
10491056
vma_set_page_prot(vma);

0 commit comments

Comments
 (0)