Skip to content

Commit

Permalink
ipc, shm: make shmem attach/detach wait for mmap_sem killable
Browse files Browse the repository at this point in the history
shmat and shmdt rely on mmap_sem for write.  If the waiting task gets
killed by the oom killer 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.

Signed-off-by: Michal Hocko <[email protected]>
Acked-by: Davidlohr Bueso <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: Hugh Dickins <[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 7c05126 commit 91f4f94
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
if (err)
goto out_fput;

down_write(&current->mm->mmap_sem);
if (down_write_killable(&current->mm->mmap_sem)) {
err = -EINTR;
goto out_fput;
}

if (addr && !(shmflg & SHM_REMAP)) {
err = -EINVAL;
if (addr + size < addr)
Expand Down Expand Up @@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
if (addr & ~PAGE_MASK)
return retval;

down_write(&mm->mmap_sem);
if (down_write_killable(&mm->mmap_sem))
return -EINTR;

/*
* This function tries to be smart and unmap shm segments that
Expand Down

0 comments on commit 91f4f94

Please sign in to comment.