From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72154C004D3 for ; Mon, 22 Oct 2018 13:43:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EF93207DE for ; Mon, 22 Oct 2018 13:43:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF93207DE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727943AbeJVWB6 (ORCPT ); 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