Skip to content

Commit

Permalink
mm: make vm_munmap killable
Browse files Browse the repository at this point in the history
Almost all current users of vm_munmap are ignoring the return value and
so they do not handle potential error.  This means that some VMAs might
stay behind.  This patch doesn't try to solve those potential problems.
Quite contrary it adds a new failure mode by using down_write_killable
in vm_munmap.  This should be safer than other failure modes, though,
because the process is guaranteed to die as soon as it leaves the kernel
and exit_mmap will clean the whole address space.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress and
reclaim the address space of the victim.

Signed-off-by: Michal Hocko <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Michal Hocko authored and torvalds committed May 24, 2016
1 parent 9fbeb5a commit ae79878
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2494,11 +2494,9 @@ int vm_munmap(unsigned long start, size_t len)
int ret;
struct mm_struct *mm = current->mm;

/*
* XXX convert to down_write_killable as soon as all users are able
* to handle the error.
*/
down_write(&mm->mmap_sem);
if (down_write_killable(&mm->mmap_sem))
return -EINTR;

ret = do_munmap(mm, start, len);
up_write(&mm->mmap_sem);
return ret;
Expand Down

0 comments on commit ae79878

Please sign in to comment.