Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1919288ima; Mon, 22 Oct 2018 00:31:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV61EQXy4eiti93G/LSn6q3/MXcK0pO8mgWgPT0yaMpSxb4GnpRV/sESNDaApgor86ue+qc0G X-Received: by 2002:a65:6249:: with SMTP id q9-v6mr41675022pgv.392.1540193507029; Mon, 22 Oct 2018 00:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540193506; cv=none; d=google.com; s=arc-20160816; b=m12rT0NsA5yhnvQdl7maGRvX2wfLTT3nbaXWuo63cOIYfwBUw2NmIe4g0ZoPvBhifr dMoSg/9bGxLFADfN8giAgeC5ed5QM45rgI+gD7ySNh4ySbCAhzjJ76heo+PwuZHorptu CWihdqxas1sVY9O/01b3jz9OOsSRi40SBbrTjc9Oo358qcn70aqdhiKbP6z9Ed7Vcb71 TZHGpOGdEJM2v7bMnFcSptm1vCYCSP6gWyYbMpBQ1mtccHjzNEad5D/ToMK2Hv3Ukqxt 1/pDJDVT583Kb/7AFhrGajOdRDi5wy9cW5PZjaW+teBVVHS90ByEFFvp3qZoxOecDjNl OqYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FBCBxQHOTmvZgHJl60t6jyJTwJfcDyQfW3eSyeZ8neA=; b=FbIi14X0C+iO0ncOfOklJSUYn0ccnB9xBBvVhQ/Ru5XEv9CYQ5E/TLWKN7YYw7sL+O Vr4WJ8YyLQ8BnEuGy7Ch9Reumx9SxEQYsn9qCuvXORgHiPH/TW5cbkZ93hLNj+J/++wT vlhIuHPWT7ygz91tvWmmdTBRteE3FeBwlLsSG5WmS+Pmg7Oca/WzEaW4CUcHBDpjPtYk dQ0M5KqPipelq6Q2JDqrG+AtBDNd+Fi3E8Myaps54Br1LxJRWRcOleuAuVLZz3UOv3K1 JKkvCaIFYL/goKPvft6PhNf4gvYC+/ZjxZKbPl8R+Mh15x8mtINjVEWVtBbJBVeJKw+/ K/vA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35-v6si22836648pla.290.2018.10.22.00.31.32; Mon, 22 Oct 2018 00:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbeJVPbB (ORCPT + 99 others); Mon, 22 Oct 2018 11:31:01 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43530 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727579AbeJVPbB (ORCPT ); Mon, 22 Oct 2018 11:31:01 -0400 Received: by mail-pf1-f194.google.com with SMTP id q1-v6so2130176pfh.10 for ; Mon, 22 Oct 2018 00:13:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FBCBxQHOTmvZgHJl60t6jyJTwJfcDyQfW3eSyeZ8neA=; b=UDQPK+zWTtGMk5+nYP+8JJChs23KFf539SRaWit0rpo/6pF692hx4pylh8JI7TEF70 /9gpiqp4Q/xOQCiN0i5c4Gq7xVF6ABEXxfIBeFGnl3ros/443MrEtGiRJyMDhyUNRQdW /Loll1WpdSl8yjR3vnO4Ogjh3slV0uIy4WVQdkHJj0Lm5ykFPBPB+rPHIklACFVQrL9H /L5ojzFwpANPyyzCLQs1B61RSNSJGygqRlorCEfwgfIZN0wr+PfKvNDrB/SKj/X8F2Er sNq6Rl2lQp32v7aThHW0jBAqJlMSem+NGdVW1UErRKpGO5FlNENddeFh9BdQzuk1ibtT 309g== X-Gm-Message-State: ABuFfogKxTgIC1cnwjsR2IlDnKifFsTm0MGvNIy0TtXMfApXqCTT3jOI Q41qhA+FusQSg6L1Ah2ud3M= 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.19.1