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 85D53C2D0DA for ; Sat, 28 Dec 2019 01:45:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D5D620828 for ; Sat, 28 Dec 2019 01:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C3BmuWHQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D5D620828 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 C2C2B8E0005; Fri, 27 Dec 2019 20:45:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDC8C8E0001; Fri, 27 Dec 2019 20:45:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA47C8E0005; Fri, 27 Dec 2019 20:45:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 959A98E0001 for ; Fri, 27 Dec 2019 20:45:48 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 255F98249980 for ; Sat, 28 Dec 2019 01:45:48 +0000 (UTC) X-FDA: 76312858776.06.lip90_4fb7bb0dc2142 X-HE-Tag: lip90_4fb7bb0dc2142 X-Filterd-Recvd-Size: 6113 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Dec 2019 01:45:47 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id t26so27114815ioi.13 for ; Fri, 27 Dec 2019 17:45:47 -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=drwHJ94pXoTF//+PeeIPAkd05VOj9HKC05blpLwcwf4=; b=C3BmuWHQULFXgjqb2SK2C5ro12YuMYmBsNH7MBhZhsHywK/2KHTyO89rHyOrvy9RR/ xjlEcPplsUQ2D0POZLgmR1vC+HPOG9FuDAoX0+dNHzGLn3V3h7JPPgUZzOC9S+gFIoGH IBR6HvTGCoQ/M+YquF9sKGwZg7ZvjVYnI8kfwkUg+ZeSpPvSB9PcZzT3dEA9wcnL0Qe3 zHxD3zdWu7Ne42JuJvRB+TAfR3Ciq7Bj0rK9+miUu8Jdsbppr8avN97xXf/jIJ++5Lzg HkAHywh/Kkyi3w3XELHiPpzzdNWqqT4ZY01lAZPvSqF1rZzZZCYWyLddWOTU7E8WwQDy Ycow== 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=drwHJ94pXoTF//+PeeIPAkd05VOj9HKC05blpLwcwf4=; b=GCanetUglfqUZ3FMq900qlBdKaS9a/wnONws/hnqqWy9diYfe4PReGr0rAeO3WVuIA c8bsVQTaZ+Ed7/wHmwQR9zINid+Gs3CjhaP3CIE3VY6cXNAXAEXc92rlLMQS08IFiPY8 FxSwgJ3zWuy/BJvBjaEmNVUVvHG94E60Y0zHhXdtwRkUGT2EuVDd8x6LHoDQnIEXxkV8 bq/VlOhCLdq4o57BlL/bY/JM/kbE8snQTpKFkd+ZxzS+O/loU827nAcvtiiybvMF8zg8 PzlciRfxLf84f0WzFEFVmSWm0EYfXiUmRpu44ZboL/17sTF0OJlL7bMAP8fHUQb9MLJ4 vGRQ== X-Gm-Message-State: APjAAAXLxUFNAHrQu2ndbAZWpLeg7Pvg7g1/LCfQybLs0p94DhlF1k75 ZIeNAHvKROuNT0YKzN/PPDmRhDVRHN2VCF8IoMU= X-Google-Smtp-Source: APXvYqwDe7uqQxHdE8LyE0nbjmCs7p2H8JNOEA+7ICWIIXzeOy+ccEJyvxPbdbmgZAgpoXEA8i9eJ5kkMgSn3K66M+8= X-Received: by 2002:a5d:8b96:: with SMTP id p22mr36061364iol.93.1577497547152; Fri, 27 Dec 2019 17:45:47 -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> In-Reply-To: <20191227234913.GA6742@localhost.localdomain> From: Yafang Shao Date: Sat, 28 Dec 2019 09:45:11 +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.000001, 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 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. > Instead we should respect memory.low/max set by a user on this level > (look at the parent == root case), maybe clamped by memory.high/max. > Let's look at the parent == root case. What if the parent is the root_mem_cgroup? The memory.{emin, elow} of root_mem_cgroup is always 0 right ? So what's your problem ? Thanks Yafang