From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com ([74.125.82.66]:33721 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbcB2N1O (ORCPT ); Mon, 29 Feb 2016 08:27:14 -0500 From: Michal Hocko Subject: [PATCH 03/18] mm: make vm_munmap killable Date: Mon, 29 Feb 2016 14:26:42 +0100 Message-ID: <1456752417-9626-4-git-send-email-mhocko@kernel.org> In-Reply-To: <1456752417-9626-1-git-send-email-mhocko@kernel.org> References: <1456752417-9626-1-git-send-email-mhocko@kernel.org> Sender: linux-arch-owner@vger.kernel.org List-ID: To: LKML Cc: Andrew Morton , linux-mm@kvack.org, Alex Deucher , Alex Thorlton , Andrea Arcangeli , Andy Lutomirski , Benjamin LaHaise , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , Dave Hansen , David Airlie , Davidlohr Bueso , David Rientjes , "H . Peter Anvin" , Hugh Dickins , Ingo Molnar , Johannes Weiner , "Kirill A . Shutemov" , Konstantin Khlebnikov , linux-arch@vger.kernel.org, Mel Gorman , Oleg Nesterov , Peter Zijlstra , Petr Cermak , Thomas Gleixner , Michal Hocko , Alexander Viro Message-ID: <20160229132642.0iBZc2fhlfQBioPoVCQdHQBYQBitePE4VxVzDWUjmD4@z> From: Michal Hocko 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. Cc: Oleg Nesterov Cc: "Kirill A. Shutemov" Cc: Konstantin Khlebnikov Cc: Andrea Arcangeli Cc: Alexander Viro Signed-off-by: Michal Hocko --- mm/mmap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4e1f852a52ff..5d33c841e3a2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2499,11 +2499,9 @@ int vm_munmap(unsigned long start, size_t len) int ret; struct mm_struct *mm = current->mm; - /* - * XXX convert to down_write_killable as soon as all users are able - * to handle the error. - */ - down_write(&mm->mmap_sem); + if (down_write_killable(&mm->mmap_sem)) + return -EINTR; + ret = do_munmap(mm, start, len); up_write(&mm->mmap_sem); return ret; -- 2.7.0