From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752448AbcB2SHV (ORCPT ); Mon, 29 Feb 2016 13:07:21 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:38439 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750871AbcB2SHT (ORCPT ); Mon, 29 Feb 2016 13:07:19 -0500 From: Michal Hocko To: LKML Cc: Andrew Morton , , Michal Hocko , Ingo Molnar , Peter Zijlstra , Oleg Nesterov , Konstantin Khlebnikov Subject: [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable Date: Mon, 29 Feb 2016 19:07:12 +0100 Message-Id: <1456769232-27592-1-git-send-email-mhocko@kernel.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1456752417-9626-9-git-send-email-mhocko@kernel.org> References: <1456752417-9626-9-git-send-email-mhocko@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Hocko 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. Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Oleg Nesterov Cc: Konstantin Khlebnikov Signed-off-by: Michal Hocko --- kernel/fork.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index d277e83ed3e0..139968026b76 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) unsigned long charge; uprobe_start_dup_mmap(); - down_write(&oldmm->mmap_sem); + if (down_write_killable(&oldmm->mmap_sem)) { + retval = -EINTR; + goto fail_uprobe_end; + } flush_cache_dup_mm(oldmm); uprobe_dup_mmap(oldmm, mm); /* @@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) up_write(&mm->mmap_sem); flush_tlb_mm(oldmm); up_write(&oldmm->mmap_sem); +fail_uprobe_end: uprobe_end_dup_mmap(); return retval; fail_nomem_anon_vma_fork: -- 2.7.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by kanga.kvack.org (Postfix) with ESMTP id 93EB26B0005 for ; Mon, 29 Feb 2016 13:07:19 -0500 (EST) Received: by mail-wm0-f53.google.com with SMTP id l68so1028344wml.0 for ; Mon, 29 Feb 2016 10:07:19 -0800 (PST) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com. [74.125.82.50]) by mx.google.com with ESMTPS id 17si33296870wjv.159.2016.02.29.10.07.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 10:07:18 -0800 (PST) Received: by mail-wm0-f50.google.com with SMTP id n186so950763wmn.1 for ; Mon, 29 Feb 2016 10:07:18 -0800 (PST) From: Michal Hocko Subject: [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable Date: Mon, 29 Feb 2016 19:07:12 +0100 Message-Id: <1456769232-27592-1-git-send-email-mhocko@kernel.org> In-Reply-To: <1456752417-9626-9-git-send-email-mhocko@kernel.org> References: <1456752417-9626-9-git-send-email-mhocko@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: LKML Cc: Andrew Morton , linux-mm@kvack.org, Michal Hocko , Ingo Molnar , Peter Zijlstra , Oleg Nesterov , Konstantin Khlebnikov From: Michal Hocko 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. Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Oleg Nesterov Cc: Konstantin Khlebnikov Signed-off-by: Michal Hocko --- kernel/fork.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index d277e83ed3e0..139968026b76 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) unsigned long charge; uprobe_start_dup_mmap(); - down_write(&oldmm->mmap_sem); + if (down_write_killable(&oldmm->mmap_sem)) { + retval = -EINTR; + goto fail_uprobe_end; + } flush_cache_dup_mm(oldmm); uprobe_dup_mmap(oldmm, mm); /* @@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) up_write(&mm->mmap_sem); flush_tlb_mm(oldmm); up_write(&oldmm->mmap_sem); +fail_uprobe_end: uprobe_end_dup_mmap(); return retval; fail_nomem_anon_vma_fork: -- 2.7.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org