From patchwork Thu Jul 19 07:59:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10533755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1BB39601D2 for ; Thu, 19 Jul 2018 07:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D76129618 for ; Thu, 19 Jul 2018 07:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 016E029620; Thu, 19 Jul 2018 07:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 699EE29618 for ; Thu, 19 Jul 2018 07:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75EAD6B0003; Thu, 19 Jul 2018 03:59:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 70CAC6B0005; Thu, 19 Jul 2018 03:59:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 622E16B0006; Thu, 19 Jul 2018 03:59:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 007246B0003 for ; Thu, 19 Jul 2018 03:59:30 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id i26-v6so2941501edr.4 for ; Thu, 19 Jul 2018 00:59:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=b9VjlscrCR2ATnojEVIGSnc6yw6RpSXWB2tnT6FGkLE=; b=ABwoLx6/wgffwOShPz6qDpF9LAiuluePxrGRDTPIhaAvQqnFsbkawSpXggoP//ka8x XKOIiW4Ik1Jw2vXtmmQ8LKzoLUIsHdEIaYB9hv/xemRr7ipqnrYO9NSNnrWNkGnTlb/u HTFARi/+kHKZI1OhP5H+2UOKoY9OxbpyFIDkJhU+lhwOfyahmML90LKWp6/aOr9Vxd3P DRGd33IVFKXCN8K2suwc/Np82S0d7OqMWGvFZKPik5kvfTTZ2IoIxnpCrz+0x6h/zVGy sveu2Xw+FuCcnFP5Wlqn/7mFyHUiRioWQrkaGE0alZAZzM46iBmR762f8EUdh2twk6nb GPFg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: AOUpUlHArTR1soA1po1QNI4IkMo1iuaiwKZGMvTXdbhmbRCLi44r5y44 TA4svXF8GmsgwOWrXp9vNWmBKRxCuEyS47EyhpKneecnTKmibACSIYwSZJlzKGJM6xYt9WFX4sr Bm2lvocSX/6kth1g1dkKLaAUVOwH4Kc8mi483MrsBbQ1VaSn9oCnzheNPjtg5ypzfMEZtGMmj8M Ir9wXUVz8aTKzGDyB+1wOdrKnUURHi2SgIEvVBI/CF1zplrk+KoZGHHloz8W8FrQU6SHcqKFM4q L/VyCtSzVaJg00wvfrxf0XUdz6ZnMNDGycGTM+QXEFQIQ4k/ROSm3jg2L2XQmz2cAX4LEOuyRDv wEtzfpuQQg67JeXPwYZd7/pTkLzWiwFEnnu8jszdtbvHvlYCk/Ax2DLpXhMOdPoUfMvA9gpW/A= = X-Received: by 2002:a50:e885:: with SMTP id f5-v6mr10314872edn.39.1531987169489; Thu, 19 Jul 2018 00:59:29 -0700 (PDT) X-Received: by 2002:a50:e885:: with SMTP id f5-v6mr10314834edn.39.1531987168545; Thu, 19 Jul 2018 00:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531987168; cv=none; d=google.com; s=arc-20160816; b=UvtE5bs3eatKsL3ij89zQLIErhXv+vT+HiKEsIZzBTDwY+G+rkHf+lv+bgM66kJ53O zAjt1s14WdxATHpzoupYKmCXmOM127qiL2tRuGTlMAxlAJlGrCtePqhk0/jb1kfIVQpC DaPbsjU9k1ApakNCgeXtuqGjcHfhlmyNhWdTXlzOiJL2WhaMyhE6u1YDoLWxEtkj6Rva Z0j1FObNClTggOvfX9Dz8oHCjLtrsMF76V3bsk9JYVTi2R5eV2Rkl/CTKkcZuAH4zjan kmAvF/1+uc05dBinVbUTtTkfrF7NuSvEvh/jElhZNLnU2dyUOtwG9+J0iJqn58IgxYz9 knzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=b9VjlscrCR2ATnojEVIGSnc6yw6RpSXWB2tnT6FGkLE=; b=AWAkbq5JKAOcCSZ0PBi/Yq6FvHl0XtWBvBYrjz5y4Rcsw2iLpRdShCTxFMSY7nbh1B n7xk9oCHXzbTUnGUUo1W6Z8FnxiuOBAaewoimiL67BIOtLot3lQBQ2BtwmaOHp1/SNT2 NbmC5P0RK0m3056F+t5wuDWn/unSynzEtyVNB7/qsZ0hnJhk9xRezq7IZJ0vrZJx0sbj PK6uvUOiyYKwhoKciauv/KxPdSfnPmH873tmwCTGOsIFszobwjOhxpsa7BINJTnhGO5Q G0qWvb07WbrHcRyF9THJWfPypk2jeniCHYiQPXh+k7ZflS4zFoasuZkloeJMHwJ+2hBw mUZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p7-v6sor3212263edh.51.2018.07.19.00.59.28 for (Google Transport Security); Thu, 19 Jul 2018 00:59:28 -0700 (PDT) Received-SPF: pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Google-Smtp-Source: AAOMgpetvMPAU8s+WNe4IR0EpIPw/820b0AoI//H+zzGoMjlL+NrgtShYVL0YvjBXC2Nxd9eZeXCuw== X-Received: by 2002:a50:c211:: with SMTP id n17-v6mr10357985edf.11.1531987168100; Thu, 19 Jul 2018 00:59:28 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id d7-v6sm2191798edi.79.2018.07.19.00.59.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 00:59:26 -0700 (PDT) From: Michal Hocko To: Andrew Morton Cc: David Rientjes , Tetsuo Handa , , LKML , Michal Hocko Subject: [PATCH] mm, oom: remove oom_lock from oom_reaper Date: Thu, 19 Jul 2018 09:59:22 +0200 Message-Id: <20180719075922.13784-1-mhocko@kernel.org> X-Mailer: git-send-email 2.18.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko oom_reaper used to rely on the oom_lock since e2fe14564d33 ("oom_reaper: close race with exiting task"). We do not really need the lock anymore though. 212925802454 ("mm: oom: let oom_reap_task and exit_mmap run concurrently") has removed serialization with the exit path based on the mm reference count and so we do not really rely on the oom_lock anymore. Tetsuo was arguing that at least MMF_OOM_SKIP should be set under the lock to prevent from races when the page allocator didn't manage to get the freed (reaped) memory in __alloc_pages_may_oom but it sees the flag later on and move on to another victim. Although this is possible in principle let's wait for it to actually happen in real life before we make the locking more complex again. Therefore remove the oom_lock for oom_reaper paths (both exit_mmap and oom_reap_task_mm). The reaper serializes with exit_mmap by mmap_sem + MMF_OOM_SKIP flag. There is no synchronization with out_of_memory path now. Suggested-by: David Rientjes Signed-off-by: Michal Hocko Acked-by: David Rientjes --- mm/mmap.c | 2 -- mm/oom_kill.c | 29 ++++------------------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index fc41c0543d7f..4642964f7741 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3073,9 +3073,7 @@ void exit_mmap(struct mm_struct *mm) * which clears VM_LOCKED, otherwise the oom reaper cannot * reliably test it. */ - mutex_lock(&oom_lock); __oom_reap_task_mm(mm); - mutex_unlock(&oom_lock); set_bit(MMF_OOM_SKIP, &mm->flags); down_write(&mm->mmap_sem); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 32e6f7becb40..c74bf0bd8010 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -529,28 +529,9 @@ void __oom_reap_task_mm(struct mm_struct *mm) static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) { - bool ret = true; - - /* - * We have to make sure to not race with the victim exit path - * and cause premature new oom victim selection: - * oom_reap_task_mm exit_mm - * mmget_not_zero - * mmput - * atomic_dec_and_test - * exit_oom_victim - * [...] - * out_of_memory - * select_bad_process - * # no TIF_MEMDIE task selects new victim - * unmap_page_range # frees some memory - */ - mutex_lock(&oom_lock); - if (!down_read_trylock(&mm->mmap_sem)) { - ret = false; trace_skip_task_reaping(tsk->pid); - goto unlock_oom; + return false; } /* @@ -562,7 +543,7 @@ static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) if (mm_has_blockable_invalidate_notifiers(mm)) { up_read(&mm->mmap_sem); schedule_timeout_idle(HZ); - goto unlock_oom; + return true; } /* @@ -574,7 +555,7 @@ static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) if (test_bit(MMF_OOM_SKIP, &mm->flags)) { up_read(&mm->mmap_sem); trace_skip_task_reaping(tsk->pid); - goto unlock_oom; + return true; } trace_start_task_reaping(tsk->pid); @@ -589,9 +570,7 @@ static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) up_read(&mm->mmap_sem); trace_finish_task_reaping(tsk->pid); -unlock_oom: - mutex_unlock(&oom_lock); - return ret; + return true; } #define MAX_OOM_REAP_RETRIES 10