Skip to content

Commit 7c05126

Browse files
Michal Hockotorvalds
Michal Hocko
authored andcommitted
mm, fork: make dup_mmap wait for mmap_sem for write killable
dup_mmap needs to lock current's mm 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: Vlastimil Babka <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4e80153 commit 7c05126

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/fork.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
414414
unsigned long charge;
415415

416416
uprobe_start_dup_mmap();
417-
down_write(&oldmm->mmap_sem);
417+
if (down_write_killable(&oldmm->mmap_sem)) {
418+
retval = -EINTR;
419+
goto fail_uprobe_end;
420+
}
418421
flush_cache_dup_mm(oldmm);
419422
uprobe_dup_mmap(oldmm, mm);
420423
/*
@@ -526,6 +529,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
526529
up_write(&mm->mmap_sem);
527530
flush_tlb_mm(oldmm);
528531
up_write(&oldmm->mmap_sem);
532+
fail_uprobe_end:
529533
uprobe_end_dup_mmap();
530534
return retval;
531535
fail_nomem_anon_vma_fork:

0 commit comments

Comments
 (0)