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 1E34AC2D0CD for ; Wed, 18 Dec 2019 01:13:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D83A421835 for ; Wed, 18 Dec 2019 01:13:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SiwRAc36" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D83A421835 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 6D8D18E00BD; Tue, 17 Dec 2019 20:13:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 688E08E0079; Tue, 17 Dec 2019 20:13:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59DD68E00BD; Tue, 17 Dec 2019 20:13:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 44BF48E0079 for ; Tue, 17 Dec 2019 20:13:51 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 119A82C94 for ; Wed, 18 Dec 2019 01:13:51 +0000 (UTC) X-FDA: 76276490262.01.drum38_5bc6dfc214750 X-HE-Tag: drum38_5bc6dfc214750 X-Filterd-Recvd-Size: 6024 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Dec 2019 01:13:50 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id i11so169653ioi.12 for ; Tue, 17 Dec 2019 17:13:50 -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=lWW1R8ZCDToBc/PK6L9Ink23+g9Ne4wMqodrYhzn0C0=; b=SiwRAc36jE4Lc/JY3ghiKg/tcM8SPGmCv19BkUAhWFYaNdYf3AACGPQUatyudC3hFm 7aNOqZmHVEHNTvcdFSaUdAEUeLue/wElkCpZe6+Y60+VgwNsWfmv7nVOWhe5ldFIv3S+ SX9/yBmPBqyYSmoiKqM3lpKS3w/dmGZf+N6k+qZMzh6SVumY1OCG5G4Okp1GMv5UPxlx 4bdTyqO3cQrRkwPM3ea3nWyrIizkjNOCFJxyd1oY47re2jAna6IPM/NhosmPDkbDD4nI sVKhjDGDEwPSbp8yM4mNgzDp4A2zI6108/iU2z65n2+0ADC6kXmnzj46yuLLOP6P29B8 CDcQ== 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=lWW1R8ZCDToBc/PK6L9Ink23+g9Ne4wMqodrYhzn0C0=; b=GGWB9jsHFYBw2+SpHrs1ZTC+Q/M1G9sWuo2c+6PjSnlyVLahk4Dq0PECroti1Eh8OL o9nIU5z3uo36WFtRBOy2K2CYhKd8wZ9iT5zXJ6Q2WHiAIoUY9b8CXWRzGxlWz+G4Zue+ +XWBNJ+bNTHmb87iwDMxC5h6YNOrBfYVraRMAtYzO19Nx30ByZM3m9kNUpHn0FN+YmPW 6ACoWSiTkKL/VZnH54bfVw/n3m0U9IAbM5By2WZOIccXJiKY94dNPoLKxAqE3R9QEdR7 ujQdp/U3o554Kcso79y6rI10iQwkJmKHG3JWdi9BiMj6/kHLDBXnq+vcHqWv6ByQg3ob wWMA== X-Gm-Message-State: APjAAAXVr7sXpqcauiAh0uaUFJFHlD7RTN8QjMSwjmpxq23lSTcZMNGI MgayS1A9JjoIpVQ86dsYfKf+mLvQBevjIVW5Y5o= X-Google-Smtp-Source: APXvYqziSFYYXXDWN9RnCFdOIvkGq+RFr1tXgyvHE4ueUnj2jxDrAN/qw4qeBG5GL+j+CuUVCdpmsgoB4aEuOyBBlKo= X-Received: by 2002:a02:856a:: with SMTP id g97mr9572jai.97.1576631629836; Tue, 17 Dec 2019 17:13:49 -0800 (PST) MIME-Version: 1.0 References: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> <1576582159-5198-4-git-send-email-laoar.shao@gmail.com> <20191217142050.GA131030@chrisdown.name> In-Reply-To: <20191217142050.GA131030@chrisdown.name> From: Yafang Shao Date: Wed, 18 Dec 2019 09:13:13 +0800 Message-ID: Subject: Re: [PATCH 3/4] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself To: Chris Down Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Al Viro , Linux MM , linux-fsdevel@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 Tue, Dec 17, 2019 at 10:20 PM Chris Down wrote: > > Hi Yafang, > > Yafang Shao writes: > >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. > > If the memcg in question is passed as "root" to mem_cgroup_protected with a > child as the new "memcg" argument, then I still don't see what is wrong. > mem_cgroup_protected must be called top-down from the root of the hierarchy in > order to work already, which we already do in shrink_node_memcgs. This will > already update the tree's cached effective protections properly, as far as I > can see. > Right. > As such I'm not sure I understand what you mean in the changelog or in the > patch. emin/elow as a mechanism is already intended to be racy/best-effort, > since by the time we get to doing work it's always possible that reclaim > eligibility state changed, and callers have to consider that. > > Could you please explain further the situation you're trying to guard against? > Thanks. > Considering bellow case, 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 to 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 vaule 512M, and then this old value will be used to in mem_cgroup_protection() in get_scan_count() to get the scan count. That is not proper. Right ? Thanks Yafang > >Cc: Chris Down > >Signed-off-by: Yafang Shao > >--- > > mm/memcontrol.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > >diff --git a/mm/memcontrol.c b/mm/memcontrol.c > >index f35fcca..234370c 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.emin = 0; > >+ } > > return MEMCG_PROT_NONE; > >+ } > > > > usage = page_counter_read(&memcg->memory); > > if (!usage) > >-- > >1.8.3.1 > >