Skip to content

Commit ae79878

Browse files
Michal Hockotorvalds
authored andcommitted
mm: make vm_munmap killable
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 <mhocko@suse.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9fbeb5a commit ae79878

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

mm/mmap.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,11 +2494,9 @@ int vm_munmap(unsigned long start, size_t len)
24942494
int ret;
24952495
struct mm_struct *mm = current->mm;
24962496

2497-
/*
2498-
* XXX convert to down_write_killable as soon as all users are able
2499-
* to handle the error.
2500-
*/
2501-
down_write(&mm->mmap_sem);
2497+
if (down_write_killable(&mm->mmap_sem))
2498+
return -EINTR;
2499+
25022500
ret = do_munmap(mm, start, len);
25032501
up_write(&mm->mmap_sem);
25042502
return ret;

0 commit comments

Comments
 (0)