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=-6.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,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 79897C2D0DA for ; Sat, 28 Dec 2019 04:25:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3CF3820722 for ; Sat, 28 Dec 2019 04:25:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GTKc39d0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CF3820722 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 CC71C8E0005; Fri, 27 Dec 2019 23:25:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C76378E0001; Fri, 27 Dec 2019 23:25:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3EB78E0005; Fri, 27 Dec 2019 23:25:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 9DD238E0001 for ; Fri, 27 Dec 2019 23:25:24 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 4103A181AEF00 for ; Sat, 28 Dec 2019 04:25:24 +0000 (UTC) X-FDA: 76313260968.25.route96_1204ba736cd46 X-HE-Tag: route96_1204ba736cd46 X-Filterd-Recvd-Size: 6551 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Dec 2019 04:25:23 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id n21so25718911ioo.10 for ; Fri, 27 Dec 2019 20:25:23 -0800 (PST) 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=cXfmeRc/DQT5QGa1Zzbtx9o4jNhOuYwsMdwRlk0Js5M=; b=GTKc39d0iw1a15PKXNPr7Jd6cxtvSBt+DRNzU3lY/gBh8hvBIun4zoBDNiyb8DCBmL F8gWouRte74ylQVLeDPtaw0gKifYndcQleu+YQdRlYnVgZH1c0ynqPvr0wPuY7pkU3Mc dqN5Jk1ZarFxAwVPMn/aaSQ+9i/PdKjORSz0w2M9EwmJIhteZQ85OZwPsC14wmRefE+M gcu4cTIUKmL0v4WFrO3se+kshYslA9F/xe0Y1LJZmDi5vPJPCrNT7fhFcEyXJMjZY8QD 13FPuVcokBT3QeYinmMUMauhl8MN6AnY5O5HSLYE1+r0so7j9aFCzc0zbfM5XcPgm+qZ wRbQ== 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=cXfmeRc/DQT5QGa1Zzbtx9o4jNhOuYwsMdwRlk0Js5M=; b=Q5msJJV/HwqSKBAUTT80CY0CBP5EXpevza/PTpfLL+02/J3kablxG/C8OU+fmnfUj8 GVJvoK0WurVefBmgyrzoJ4QH/G6C8DV8hxsz98Bk4Tb8OT3C7o76yhoDGbzouwmsElWt uB8Mc62YZSofZdXlHNrXP0k4GkgIBA2fRNrOgGHN7Fw87sVjv9PqZXdwi7UvWEER10Qz d0sNNFdDWOwI+0slsI7Oisz+wf4JuMtc/cDuBwijdUYihl5ZoBYjYXLGK+/cz9/GjA+j BrErX3SE1mNooj6n+kvIj6jaD9uwc77v5IzLSBTEdnf0QIlMYDCA+kwMdXi9/QIpjltG w3sQ== X-Gm-Message-State: APjAAAUaFB+30NY2wEyLYA4Ryz5Qb2CSIxFDPO5C9gpzWVbhx3uUFqjR QB3tQhURXk+UsUQbokgv9PG6zXjVZloZFqqEYMw= X-Google-Smtp-Source: APXvYqxmEscC1lOiABwtiQ2kw0O4KaI818nJjTvvIHGJhczhXbW1y1TKp8bfZbirOWUo0WYmbm5Sf9I6/TNQEJhJWsg= X-Received: by 2002:a02:856a:: with SMTP id g97mr43201900jai.97.1577507123172; Fri, 27 Dec 2019 20:25:23 -0800 (PST) MIME-Version: 1.0 References: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com> <1577450633-2098-2-git-send-email-laoar.shao@gmail.com> <20191227234913.GA6742@localhost.localdomain> <20191228025951.GA8425@localhost.localdomain> In-Reply-To: <20191228025951.GA8425@localhost.localdomain> From: Yafang Shao Date: Sat, 28 Dec 2019 12:24:47 +0800 Message-ID: Subject: Re: [PATCH] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself To: Roman Gushchin Cc: "hannes@cmpxchg.org" , "mhocko@kernel.org" , "vdavydov.dev@gmail.com" , "akpm@linux-foundation.org" , "linux-mm@kvack.org" , 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, Dec 28, 2019 at 11:00 AM Roman Gushchin wrote: > > On Sat, Dec 28, 2019 at 09:45:11AM +0800, Yafang Shao wrote: > > On Sat, Dec 28, 2019 at 7:49 AM Roman Gushchin wrote: > > > > > > On Fri, Dec 27, 2019 at 07:43:53AM -0500, Yafang Shao wrote: > > > > memory.{emin, elow} are set in mem_cgroup_protected(), and the values of > > > > them won't be changed until next recalculation in this function. After > > > > either or both of them are set, the next reclaimer to relcaim this memcg > > > > may be a different reclaimer, e.g. this memcg is also the root memcg of > > > > the new reclaimer, and then in mem_cgroup_protection() in get_scan_count() > > > > the old values of them will be used to calculate scan count, that is not > > > > proper. We should reset them to zero in this case. > > > > > > > > Here's an example of this issue. > > > > > > > > root_mem_cgroup > > > > / > > > > A memory.max=1024M memory.min=512M memory.current=800M > > > > > > > > Once kswapd is waked up, it will try to scan all MEMCGs, including > > > > this A, and it will assign memory.emin of A with 512M. > > > > After that, A may reach its hard limit(memory.max), and then it will > > > > do memcg reclaim. Because A is the root of this reclaimer, so it will > > > > not calculate its memory.emin. So the memory.emin is the old value > > > > 512M, and then this old value will be used in > > > > mem_cgroup_protection() in get_scan_count() to get the scan count. > > > > That is not proper. > > > > > > > > Fixes: 9783aa9917f8 ("mm, memcg: proportional memory.{low,min} reclaim") > > > > Signed-off-by: Yafang Shao > > > > Cc: Chris Down > > > > Cc: Roman Gushchin > > > > Cc: stable@vger.kernel.org > > > > --- > > > > mm/memcontrol.c | 11 ++++++++++- > > > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > > index 601405b..bb3925d 100644 > > > > --- a/mm/memcontrol.c > > > > +++ b/mm/memcontrol.c > > > > @@ -6287,8 +6287,17 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > > > > > > > > if (!root) > > > > root = root_mem_cgroup; > > > > - if (memcg == root) > > > > + if (memcg == root) { > > > > + /* > > > > + * Reset memory.(emin, elow) for reclaiming the memcg > > > > + * itself. > > > > + */ > > > > + if (memcg != root_mem_cgroup) { > > > > + memcg->memory.emin = 0; > > > > + memcg->memory.elow = 0; > > > > + } > > > > > > I'm sorry, that didn't bring it from scratch, but I doubt that zeroing effecting > > > protection is correct. Imagine a simple config: a large cgroup subtree with memory.max > > > set on the top level. Reaching this limit doesn't mean that all protection > > > configuration inside the tree can be ignored. > > > > > > > No, they won't be ignored. > > Pls. see the logic in mem_cgroup_protected(), it will re-calculate all > > its children's effective min and low. > > Ah, you're right. I forgot about this > if (parent == root) > goto exit; > > which saves elow/emin from being truncated to 0. Sorry. > > Please, feel free to add > Acked-by: Roman Gushchin > Thanks for your review. Thanks Yafang