Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp671564imu; Fri, 25 Jan 2019 08:56:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN7v6C3eTGQuV+LRdVPwHPG3D+tYUui02tq3MFRP1wpm16QcjwhBnpcZpBrq75Jdko8lHKgX X-Received: by 2002:a63:c303:: with SMTP id c3mr10659814pgd.268.1548435409358; Fri, 25 Jan 2019 08:56:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548435409; cv=none; d=google.com; s=arc-20160816; b=SFlU+NfyndMn3ZKTiUHG2ttnjAHRebKPo0hjXrRleq6iDaKs//Zi3tVSmF8g4qXEe8 FzFAMJkrLh1QlbgXxpgsefdpXeC43LeSsO8XfFtqR5H08Fk+e7d300XPDgrdyca8/i3d MxwBUM0j7VmfBxNBkHAg374G+Q1I1+xTpicTZTq9759FHkULT3c0RaxRzx1H2dPPelAZ wWsHyBK6BWEQCkhnOSaCeGrORun8swVI6J3Fw0m1S/LF26kmAGhQUSHAkQa7fhHJsRPK QwUBvhWFCsH43aEsqVb7oD+KcIRf6JLnr+pIX1X8FxAoTqF7teuefr07E8c2weT/wOb0 wsKQ== 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:dkim-signature; bh=RNchuqr3adsTArnI0ZEntYHozJYWxyEQo/SnVvUtVNc=; b=txURwUlMORqkmD040/ZLzS89E2M04HnVh7ocYi0cfXZuSqjf/tzS5yx4RcISUd45z2 h4kooalz0C2XfeYJpRlrpksz+gHzakgVqOhbMZ7gis65Ugg7ooZGrEW1vbClqG0OOm90 GLx0IFzrjoWsOPGL6V3L3PdhQ5kk/vTi8B3sSAKhxAFlym4UEgJTjcWWgdq47tbSldC/ ZCiJl1iZWIaonCcGXrw0JBnlOyDfvEwRUTEFYSmTOv69Y7aycU5+ixk914FZ2xm92kex MfFcZYBxvfgFbkumTbCbrSVcmH39udBERirN+Y6DSh5zyfNtAWqVvITi5FLkTJydM+tA nv/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=uIIoysv+; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si21128707plz.327.2019.01.25.08.56.33; Fri, 25 Jan 2019 08:56:49 -0800 (PST) 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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=uIIoysv+; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbfAYQ42 (ORCPT + 99 others); Fri, 25 Jan 2019 11:56:28 -0500 Received: from mail-yb1-f179.google.com ([209.85.219.179]:38745 "EHLO mail-yb1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbfAYQ41 (ORCPT ); Fri, 25 Jan 2019 11:56:27 -0500 Received: by mail-yb1-f179.google.com with SMTP id x9so4086337ybj.5 for ; Fri, 25 Jan 2019 08:56:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RNchuqr3adsTArnI0ZEntYHozJYWxyEQo/SnVvUtVNc=; b=uIIoysv+H0D8F8n6fbuqAaCugVthDdjFx3BGz3Q/i0kCjWNLsFDyRt4QyJTmW+MJoI hlkkG0VoFp67FGmCBF+IDnT7DMHQLVolbwhaWNj/bSpXJGG3WUTU7BggZuuoeoVxHj4r XbFMWUT5Lxzp+UJhZa85SWO/4ZB0qNvzJhvXTseOeH/jND0qyo5RGgPYvHeXxsDEUoQ5 JI0wg8e78izosTtI38FdP+KKcMONfflsl0/HLPGYFY+Rsg5u3eavtLsPx3/u5mMd2tjM OoYIi50y34FwpcXVeR3msE3n9vvsgFP+XWcE47HJue02u3LtgOwVQz+MVVsJ7t4wv4Sl Ud0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RNchuqr3adsTArnI0ZEntYHozJYWxyEQo/SnVvUtVNc=; b=K3fmyO+Vx/ysCfu/dyMm/SMDaG0G0FzpAzlKW5sFz4et8pAvlmlWwDOR9AzWj3FRHH kRNgpIwfKyCpy+dnNlQhZ8AmxuCcAgfDlCGcVivSCJ6i6VA/DcmLsc3noCzuapFojk+7 oSompPBpABYAfTZ4zjm1azOlEeCrGyHQ0zctdK/DurI0B2uiWdKnoY2aUmX/R4G0Jagq LP3ZXND1znsJyg3GsBlfC1LIwMgum8DJdMF5YuO54AriQIMkLI+XOTcUfDn1g5xYm81P qraG/E9nDq6GYU+nvfGAySb7RWNt2SbFY0l+Lz0Cmnf9rqbxXVntUUHV1amOtVk39t1a PcVw== X-Gm-Message-State: AJcUukcUUuH9dJksiZmxen7f/pA/H27zgSz1wvzyydGB/1pa1cc2L+gs GUHub5m6cEy+aAUUTDciLqGkmw== X-Received: by 2002:a25:e904:: with SMTP id n4mr11455439ybd.54.1548435386317; Fri, 25 Jan 2019 08:56:26 -0800 (PST) Received: from localhost ([2620:10d:c091:200::4:144f]) by smtp.gmail.com with ESMTPSA id a7sm18054452ywb.18.2019.01.25.08.56.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Jan 2019 08:56:25 -0800 (PST) Date: Fri, 25 Jan 2019 11:56:24 -0500 From: Johannes Weiner To: akpm@linux-foundation.org Cc: mm-commits@vger.kernel.org, penguin-kernel@i-love.sakura.ne.jp, mhocko@suse.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: + memcg-do-not-report-racy-no-eligible-oom-tasks.patch added to -mm tree Message-ID: <20190125165624.GA17719@cmpxchg.org> References: <20190109190306.rATpT%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190109190306.rATpT%akpm@linux-foundation.org> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 09, 2019 at 11:03:06AM -0800, akpm@linux-foundation.org wrote: > > The patch titled > Subject: memcg: do not report racy no-eligible OOM tasks > has been added to the -mm tree. Its filename is > memcg-do-not-report-racy-no-eligible-oom-tasks.patch > > This patch should soon appear at > http://ozlabs.org/~akpm/mmots/broken-out/memcg-do-not-report-racy-no-eligible-oom-tasks.patch > and later at > http://ozlabs.org/~akpm/mmotm/broken-out/memcg-do-not-report-racy-no-eligible-oom-tasks.patch > > Before you just go and hit "reply", please: > a) Consider who else should be cc'ed > b) Prefer to cc a suitable mailing list as well > c) Ideally: find the original patch on the mailing list and do a > reply-to-all to that, adding suitable additional cc's > > *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** > > The -mm tree is included into linux-next and is updated > there every 3-4 working days > > ------------------------------------------------------ > From: Michal Hocko > Subject: memcg: do not report racy no-eligible OOM tasks > > 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 > Link: http://lkml.kernel.org/r/20190107143802.16847-3-mhocko@kernel.org > Signed-off-by: Michal Hocko > Cc: Tetsuo Handa > Cc: Johannes Weiner > Signed-off-by: Andrew Morton It looks like this problem is happening in production systems: https://www.spinics.net/lists/cgroups/msg21268.html where the threads don't exit because they are trapped writing out the oom messages to a slow console (running the reproducer from this email thread triggers the oom flooding). So IMO we should put this into 5.0 and add: Fixes: 29ef680ae7c2 ("memcg, oom: move out_of_memory back to the charge path") Fixes: 3100dab2aa09 ("mm: memcontrol: print proper OOM header when no eligible victim left") Cc: stable@kernel.org # 4.19+ > --- a/mm/memcontrol.c~memcg-do-not-report-racy-no-eligible-oom-tasks > +++ a/mm/memcontrol.c > @@ -1387,10 +1387,22 @@ static bool mem_cgroup_out_of_memory(str > .gfp_mask = gfp_mask, > .order = order, > }; > - bool ret; > + bool ret = true; Should this be false if skip the oom kill, btw? Either will result in a forced charge - false will do so right away, true will retry once and then trigger the victim check in try_charge(). It's just weird to return true when we didn't do what the caller asked us to do. > 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;