Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427AbcDZM4v (ORCPT ); Tue, 26 Apr 2016 08:56:51 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34479 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353AbcDZM4r (ORCPT ); Tue, 26 Apr 2016 08:56:47 -0400 From: Michal Hocko To: , Andrew Morton Cc: LKML , Michal Hocko , Benamin LaHaise , Alexander Viro , Jeff Moyer , Vlastimil Babka Subject: [PATCH 12/18] aio: make aio_setup_ring killable Date: Tue, 26 Apr 2016 14:56:19 +0200 Message-Id: <1461675385-5934-13-git-send-email-mhocko@kernel.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1461675385-5934-1-git-send-email-mhocko@kernel.org> References: <1461675385-5934-1-git-send-email-mhocko@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1283 Lines: 38 From: Michal Hocko aio_setup_ring waits for mmap_sem in writable mode. 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. This will also expedite the return to the userspace and do_exit. Cc: Benamin LaHaise Cc: Alexander Viro Acked-by: Jeff Moyer Acked-by: Vlastimil Babka Signed-off-by: Michal Hocko --- fs/aio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/aio.c b/fs/aio.c index 155f84253f33..be771046d77c 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -496,7 +496,12 @@ static int aio_setup_ring(struct kioctx *ctx) ctx->mmap_size = nr_pages * PAGE_SIZE; pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size); - down_write(&mm->mmap_sem); + if (down_write_killable(&mm->mmap_sem)) { + ctx->mmap_size = 0; + aio_free_ring(ctx); + return -EINTR; + } + ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, 0, &unused); -- 2.8.0.rc3