From patchwork Mon Oct 22 07:13:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10651773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4C82109C for ; Mon, 22 Oct 2018 07:13:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CECE0201A4 for ; Mon, 22 Oct 2018 07:13:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2B8C2881A; Mon, 22 Oct 2018 07:13:48 +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 59408201A4 for ; Mon, 22 Oct 2018 07:13:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D9086B000C; Mon, 22 Oct 2018 03:13:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9873C6B000E; Mon, 22 Oct 2018 03:13:46 -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 8A5746B0010; Mon, 22 Oct 2018 03:13:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 38A3C6B000C for ; Mon, 22 Oct 2018 03:13:46 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id t18-v6so21565380plo.16 for ; Mon, 22 Oct 2018 00:13:46 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=FBCBxQHOTmvZgHJl60t6jyJTwJfcDyQfW3eSyeZ8neA=; b=QCyoF/3WtrND+xiQTWxskOqxXN6dNxjVRjpmDqcunTkmHHpO5X/OyHxVrSf9TNKU65 Cu1rQ7k86zi70PnKqCIYerY+xnAHnXEUnkzOHz6rlFPuLVd3m533ysF1McLNooRGZ5vy d6sCdNOnwFZZgGxOr4pxObWPzSe2nnn1sEPtMgPj1+DDHvALFBSZeMtQijfyMm3t4hJt nv8Z9C22IcUsCp3dSyXpYnKXa/CDYGRT4n6aFyftpl2H3aLR6wMknr3uIEHDMYBqxsHI /UoMoOUC61zMOhWFd6Pgqb+rj+sGcQz6d9qZkhkh7LBVhFJsBmQQGZE17+O0F96/ndw2 Y4wA== 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: ABuFfohIJGi1Jgysog1iDS0EdKkSs6QyaaTZRJlk4bhCym4fxDdgPCjE yFqEYqcmHTt9gZN5CZ+58SImPsflYgcPIclU9XC3nUvDtjzt8v9SEOsY9oOlMW3/VaJIzNu/Na/ xNQimJEnbs070vEgnIhlSlf8sH+XWM/m6C3Nx/FU/UiTF44uPJy1lgDD88YYiQOv9ysfv2wQFP8 bgii7Btd9GofQotolDvrXhsZ1qweu0lF5LhDLOAC3RWv3PHMxgW+yvpEcc0F8zeBU4umiYosXOI eyOZBaSOuGEBqpoj2xHg/MOTYOfNk0603J7HGL+1ymskuUEp36Tji3i02oTBV6ucSpOmfvEFDp4 4KZVDNtYcOVvbrcbFzgYaMxk+Pz2M4+E22bV0K2piayaINxBalvMK36dzD/PkUvVD3f0lxOGTw= = X-Received: by 2002:a62:8f0c:: with SMTP id n12-v6mr45039516pfd.172.1540192425911; Mon, 22 Oct 2018 00:13:45 -0700 (PDT) X-Received: by 2002:a62:8f0c:: with SMTP id n12-v6mr45039478pfd.172.1540192425063; Mon, 22 Oct 2018 00:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540192425; cv=none; d=google.com; s=arc-20160816; b=QfjeGMSetl3xXivHljwN3sDw4pPXAUD/io9N32c5gWu7uiJvOwUWogJ1n4exMlP42p STzzi8y/Qkllj2JnG5nQUw/ZV2eZTTNoFED9L9Fd4YXD3+eHZqSuKB5JLOqPtQh5YG9S Lg6WUskGUQ9GLWCLMxrY+RPT86pUDcP3TZ66J0Lrhg48PgA+4q4r0jxrQ+46WI3o6ZEj QFiWGOCklEPqzE5Os1/JbHU6Fl2Z1b8RPL8/83Q5RSfRWe8PQPWGyFZ6KBRc8XmwtxyA FvDeoqTiGJsdErzvvctqtVCBXnI5MQvJn7VatAlgjhjWW9SO1ObsMVc961T9m7omKGJY alpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=FBCBxQHOTmvZgHJl60t6jyJTwJfcDyQfW3eSyeZ8neA=; b=XVcQ/wtW47jjWmTcdCWZPdSzCBn6ifJIKENrDq23SL6woKxi4j3S1AJL90oBs4rfxw EQAx64dS+s8MZFxMBVJqxXGAPy2gD8blVQrlQyes1e0nyeSuGNewQp3BdwgVMyn8J9dc alMAC9jCvteDz9j16b2EX1t3FQt08phPM79d6sBuGbrCZVVpTgI6fbarYEEkzmFEff+y wEgSUy369hzNYavkymnqUnwTZtSVWiLfTaQzHPnlqFjX33kr31wZWMCjsLA03xCMhU1L lU/eSRsj+ssS7WfJrDAuE6LPXacGV9/RXMhc8S9pOKLNvB5Fu2CiVA71OqwBYoRI+5l/ H5rw== 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 19-v6sor20803810pft.4.2018.10.22.00.13.44 for (Google Transport Security); Mon, 22 Oct 2018 00:13:45 -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: ACcGV6064Z1dWqa7QMCXfgEb9cpfEDaa6ZH2gbgOOmik96tlPssDIV7b2W3tmlzucX76u01TUKPNKw== X-Received: by 2002:a62:569d:: with SMTP id h29-v6mr16163789pfj.42.1540192424428; Mon, 22 Oct 2018 00:13:44 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id c79-v6sm38097542pfc.92.2018.10.22.00.13.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 00:13:43 -0700 (PDT) From: Michal Hocko To: Cc: Johannes Weiner , Tetsuo Handa , David Rientjes , Andrew Morton , LKML , Michal Hocko Subject: [RFC PATCH 2/2] memcg: do not report racy no-eligible OOM tasks Date: Mon, 22 Oct 2018 09:13:23 +0200 Message-Id: <20181022071323.9550-3-mhocko@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181022071323.9550-1-mhocko@kernel.org> References: <20181022071323.9550-1-mhocko@kernel.org> MIME-Version: 1.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 Tetsuo has reported [1] that a single process group memcg might easily swamp the log with no-eligible oom victim reports due to race between the memcg charge and oom_reaper Thread 1 Thread2 oom_reaper try_charge try_charge mem_cgroup_out_of_memory mutex_lock(oom_lock) mem_cgroup_out_of_memory mutex_lock(oom_lock) out_of_memory select_bad_process oom_kill_process(current) wake_oom_reaper oom_reap_task MMF_OOM_SKIP->victim mutex_unlock(oom_lock) out_of_memory select_bad_process # no task If Thread1 didn't race it would bail out from try_charge and force the charge. We can achieve the same by checking tsk_is_oom_victim inside the oom_lock and therefore close the race. [1] http://lkml.kernel.org/r/bb2074c0-34fe-8c2c-1c7d-db71338f1e7f@i-love.sakura.ne.jp Signed-off-by: Michal Hocko Signed-off-by: Tetsuo Handa Signed-off-by: Tetsuo Handa --- mm/memcontrol.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e79cb59552d9..a9dfed29967b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1380,10 +1380,22 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, .gfp_mask = gfp_mask, .order = order, }; - bool ret; + bool ret = true; mutex_lock(&oom_lock); + + /* + * multi-threaded tasks might race with oom_reaper and gain + * MMF_OOM_SKIP before reaching out_of_memory which can lead + * to out_of_memory failure if the task is the last one in + * memcg which would be a false possitive failure reported + */ + if (tsk_is_oom_victim(current)) + goto unlock; + ret = out_of_memory(&oc); + +unlock: mutex_unlock(&oom_lock); return ret; }