Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2257312ima; Mon, 22 Oct 2018 07:01:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV62uEHKRaT7MEeeGzQwDeG9LFcAVcOInOhis8Y9bfx6jWFPK37miPRmV97xuFX8Tx8CgDc6Z X-Received: by 2002:a62:3185:: with SMTP id x127-v6mr47149431pfx.88.1540216874060; Mon, 22 Oct 2018 07:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540216873; cv=none; d=google.com; s=arc-20160816; b=oiGoGXUQsNUuplwLZi/ATerfC1e1W7TgDD150XzybSPVgLSdLcqsE1rs3aqMmbft/j d7RzFbwz0+vGE02e2db2z7ptO6ogvARmsoqM+G2dW3DjwdSjcF6IHHpIt0V2+3vcWDw6 DJXIMihfXzJyr1DNa2TWL76Rf/N0+WbtGb+N/3zMbYh4LEiQS9c1dL2dOPpuqPycApht ED9RAeyar9MrKKMHU6TAicRcWcpwcqX0lB2m1clY4JvlcaOBr0kpWnIWJNzN2m5K5zY5 4Ors8rXloC0IwaolL/4te8d/wC6DQ97OcC+DtsEuOOwXiPyrGJzx8VkyfA8jfDmtVCRf UvuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Uuy56WR0PRu5vlRzd21UIRxTqNKFGUiiS8oX9Dn8XRw=; b=plf5vmEPsoIOl6BEeHMxpSxIqnVEPaS1GrFvHyhO6hocYwzhajd0tZQBhBnhsv6w7o T5jqivxoC4ElpaAJSQKALwjo5CK0it2gEU22iHBuRcoU6Z4v5S5/jfORfiEDCrFgf3P4 5URyvbBR+aBywJbEnlOfv4oUt0GnawcQ+w2TzrQfXoHlcBgtKBRIIqp98KDn4ZTQzbui qxOs66/gS4op2zbtVW0a0RZTtExALRpmWRh5KFL4lNXjlB2e2uvdTZcah7FeKraglf3V OLFxgzsfhSecbJlOcwJghXJpIjYMXdjDnvk07Jo0friFA7m0gM+o6GVuGuqp9BcA+YkJ 9NSg== 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 h3-v6si33033118pls.27.2018.10.22.07.00.56; Mon, 22 Oct 2018 07:01:13 -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 S1727857AbeJVWB6 (ORCPT + 99 others); Mon, 22 Oct 2018 18:01:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:49290 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727210AbeJVWB5 (ORCPT ); Mon, 22 Oct 2018 18:01:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 36EFAAFE2; Mon, 22 Oct 2018 13:43:17 +0000 (UTC) Date: Mon, 22 Oct 2018 15:43:15 +0200 From: Michal Hocko To: Tetsuo Handa Cc: linux-mm@kvack.org, Johannes Weiner , David Rientjes , Andrew Morton , LKML Subject: Re: [RFC PATCH 2/2] memcg: do not report racy no-eligible OOM tasks Message-ID: <20181022134315.GF18839@dhcp22.suse.cz> References: <20181022071323.9550-1-mhocko@kernel.org> <20181022071323.9550-3-mhocko@kernel.org> <20181022120308.GB18839@dhcp22.suse.cz> <0a84d3de-f342-c183-579b-d672c116ba25@i-love.sakura.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0a84d3de-f342-c183-579b-d672c116ba25@i-love.sakura.ne.jp> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 22-10-18 22:20:36, Tetsuo Handa wrote: > On 2018/10/22 21:03, Michal Hocko wrote: > > On Mon 22-10-18 20:45:17, Tetsuo Handa wrote: > >> On 2018/10/22 16:13, Michal Hocko wrote: > >>> 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; > >>> + > >> > >> This is not wrong but is strange. We can use mutex_lock_killable(&oom_lock) > >> so that any killed threads no longer wait for oom_lock. > > > > tsk_is_oom_victim is stronger because it doesn't depend on > > fatal_signal_pending which might be cleared throughout the exit process. > > I mean: > > mm/memcontrol.c | 3 +- > mm/oom_kill.c | 111 +++++--------------------------------------------------- > 2 files changed, 12 insertions(+), 102 deletions(-) This is much larger change than I feel comfortable with to plug this specific issue. A simple and easy to understand fix which doesn't add maintenance burden should be preferred in general. The code reduction looks attractive but considering it is based on removing one of the heuristics to prevent OOM reports in some case it should be done on its own with a careful and throughout justification. E.g. how often is the heuristic really helpful. In principle I do not oppose to remove the shortcut after all due diligence is done because this particular one had given us quite a lot headaches in the past. -- Michal Hocko SUSE Labs