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=-3.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 3758BC55186 for ; Fri, 24 Apr 2020 16:31:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF38D2063A for ; Fri, 24 Apr 2020 16:31:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n3Ao58aP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF38D2063A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8BEC98E0008; Fri, 24 Apr 2020 12:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86DD58E0003; Fri, 24 Apr 2020 12:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7353B8E0008; Fri, 24 Apr 2020 12:31:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 5B42C8E0003 for ; Fri, 24 Apr 2020 12:31:27 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0B386640E for ; Fri, 24 Apr 2020 16:31:27 +0000 (UTC) X-FDA: 76743289014.14.jail36_8107a82c8b55f X-HE-Tag: jail36_8107a82c8b55f X-Filterd-Recvd-Size: 7483 Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 16:31:26 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id z2so10952218iol.11 for ; Fri, 24 Apr 2020 09:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S8gZzuzuHy1N2O54R+Hhx4bbnAF7GR0rIPTLAkk3+9U=; b=n3Ao58aPO1jP631p56XDOWB6KBqKAvqqY+k7HepxaBki97beKAEUEpNRZto5UTwq4C xh687hSrTTXAav0JjWMsfzUkS8CsLXF3nwXR7PtqH6mbLXD/xolXmMj2DxvOm9F9Q8pM oXFz75KFTHdAaH/QJG7G7Wx7YBIp8qwaNGKrMvuGmV8BgeTvlVIcLqdpMwnwJ9ewLROH zB3nlIyYW0dIxX2pfFRRn541S8UMH6VCiTPYunRtpmVHvyOTl9CSYOR8fjUXeD5jWvt1 k8BTvmtEJenNIp05aCZuOqIC+w/Cog2DaUYZ7RCwjUyX4va0pC5lGS6UWqZkPH+BaVVl w1/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S8gZzuzuHy1N2O54R+Hhx4bbnAF7GR0rIPTLAkk3+9U=; b=FI5aqYD+OShzRifjdNXyNfxySGTnIAmfI6lrJJAB1+dmcZUrgDSFBTxuQisiXVTYbY M98a+pBt+XBO8rEAPiF3WpIPBy+SlhPFizIkIJdzzd/lxd6vYoTdQ3CfyJdzJY4OMxVI Mo6scFEnmDVIyFZgykjUudZcHzJYSv+rLVC+Sre5Z4VZS/OTi9abTcLPOZ9ip4w3BxEW 3dFJaWBE6T+IHiDlX4tHttfXnfkX8D9/bsGaDc6Ds6lq++QGhPVinVMo4zpRkGDeAZUi B2xMejyboP8LTfXXuOUkrvjtpGyx6YjpPjuKw8MiNs/pAuuNtM4bhriotJWaogDN/y7w bozA== X-Gm-Message-State: AGi0PubtQd/TjowYB3u3EWEHx5M7Hi5o+FTaYqddwhAt5IvTLMQbP/gD zKqtRx6Ligqekrf2xwzEFE0pEdv1pwfkK+Ogtkr41ejJz/M= X-Google-Smtp-Source: APiQypKJEe3y6mru5S+uRWATW1RxNzdISidArH53uC+BeG9bX0aePuzM99o3SmK0gnEnn0qZqk1by7vyCnZeLyJiBT0= X-Received: by 2002:a6b:7843:: with SMTP id h3mr9421428iop.202.1587745886012; Fri, 24 Apr 2020 09:31:26 -0700 (PDT) MIME-Version: 1.0 References: <20200423061629.24185-1-laoar.shao@gmail.com> <20200424131450.GA495720@cmpxchg.org> <20200424142958.GF11591@dhcp22.suse.cz> <20200424162148.GA99424@carbon.lan> In-Reply-To: <20200424162148.GA99424@carbon.lan> From: Yafang Shao Date: Sat, 25 Apr 2020 00:30:14 +0800 Message-ID: Subject: Re: [PATCH] mm, memcg: fix wrong mem cgroup protection To: Roman Gushchin Cc: Michal Hocko , Johannes Weiner , Andrew Morton , Vladimir Davydov , Linux MM , Chris Down , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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: On Sat, Apr 25, 2020 at 12:22 AM Roman Gushchin wrote: > > On Fri, Apr 24, 2020 at 04:29:58PM +0200, Michal Hocko wrote: > > On Fri 24-04-20 09:14:50, Johannes Weiner wrote: > > > On Thu, Apr 23, 2020 at 02:16:29AM -0400, Yafang Shao wrote: > > > > This patch is an improvement of a previous version[1], as the previous > > > > version is not easy to understand. > > > > This issue persists in the newest kernel, I have to resend the fix. As > > > > the implementation is changed, I drop Roman's ack from the previous > > > > version. > > > > > > Now that I understand the problem, I much prefer the previous version. > > > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > index 745697906ce3..2bf91ae1e640 100644 > > > --- a/mm/memcontrol.c > > > +++ b/mm/memcontrol.c > > > @@ -6332,8 +6332,19 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > > > > > > if (!root) > > > root = root_mem_cgroup; > > > - if (memcg == root) > > > + if (memcg == root) { > > > + /* > > > + * The cgroup is the reclaim root in this reclaim > > > + * cycle, and therefore not protected. But it may have > > > + * stale effective protection values from previous > > > + * cycles in which it was not the reclaim root - for > > > + * example, global reclaim followed by limit reclaim. > > > + * Reset these values for mem_cgroup_protection(). > > > + */ > > > + memcg->memory.emin = 0; > > > + memcg->memory.elow = 0; > > > return MEMCG_PROT_NONE; > > > + } > > > > Could you be more specific why you prefer this over the > > mem_cgroup_protection which doesn't change the effective value? > > Isn't it easier to simply ignore effective value for the reclaim roots? > > Hm, I think I like the new version better, because it feels "safer" in terms > of preserving sane effective protection values for concurrent reclaimers. > > > > > [...] > > > > > As others have noted, it's fairly hard to understand the problem from > > > the above changelog. How about the following: > > > > > > A cgroup can have both memory protection and a memory limit to isolate > > > it from its siblings in both directions - for example, to prevent it > > > from being shrunk below 2G under high pressure from outside, but also > > > from growing beyond 4G under low pressure. > > > > > > 9783aa9917f8 ("mm, memcg: proportional memory.{low,min} reclaim") > > > implemented proportional scan pressure so that multiple siblings in > > > excess of their protection settings don't get reclaimed equally but > > > instead in accordance to their unprotected portion. > > > > > > During limit reclaim, this proportionality shouldn't apply of course: > > > there is no competition, all pressure is from within the cgroup and > > > should be applied as such. Reclaim should operate at full efficiency. > > > > > > However, mem_cgroup_protected() never expected anybody to look at the > > > effective protection values when it indicated that the cgroup is above > > > its protection. As a result, a query during limit reclaim may return > > > stale protection values that were calculated by a previous reclaim > > > cycle in which the cgroup did have siblings. > > > > This is better. Thanks! > > +1 > > and I like the proposed renaming/cleanup. Thanks, Johannes! > > > > > > When this happens, reclaim is unnecessarily hesitant and potentially > > > slow to meet the desired limit. In theory this could lead to premature > > > OOM kills, although it's not obvious this has occurred in practice. > > > > I do not see how this would lead all the way to OOM killer but it > > certainly can lead to unnecessary increase of the reclaim priority. The > > smaller the difference between the reclaim target and protection the > > more visible the effect would be. But if there are reclaimable pages > > then the reclaim should see them sooner or later > > I guess if all memory is protected by emin and the targeted reclaim > will be unable to reclaim anything, OOM can be triggered. > > Btw, I wonder if this case can be covered by a new memcg kselftest? > I'm not sure it can be easily reproducible, but if it can, it would be > the best demonstration of a problem and the fix. > Yafang, don't you want to try? I have tried to produce the premature OOM before I send this fix, but I find that it is really not easy to produce. But if a new memcg kselftest is needed, I can try it again. -- Thanks Yafang