From: Roman Gushchin <guro@fb.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Chris Down <chris@chrisdown.name>,
Andrew Morton <akpm@linux-foundation.org>,
Yafang Shao <laoar.shao@gmail.com>, <linux-mm@kvack.org>,
<cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] mm, memcg: Avoid stale protection values when cgroup is above protection
Date: Thu, 30 Apr 2020 10:17:16 -0700 [thread overview]
Message-ID: <20200430171716.GB339283@carbon.dhcp.thefacebook.com> (raw)
In-Reply-To: <20200430145721.GF12655@dhcp22.suse.cz>
On Thu, Apr 30, 2020 at 04:57:21PM +0200, Michal Hocko wrote:
> On Wed 29-04-20 12:56:27, Johannes Weiner wrote:
> [...]
> > I think to address this, we need a more comprehensive solution and
> > introduce some form of serialization. I'm not sure yet how that would
> > look like yet.
>
> Yeah, that is what I've tried to express earlier and that is why I would
> rather go with an uglier workaround for now and think about a more
> robust effective values calculation on top.
>
> > I'm still not sure it's worth having a somewhat ugly workaround in
> > mem_cgroup_protection() to protect against half of the bug. If you
> > think so, the full problem should at least be documented and marked
> > XXX or something.
>
> Yes, this makes sense to me. What about the following?
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 1b4150ff64be..50ffbc17cdd8 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -350,6 +350,42 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg,
> if (mem_cgroup_disabled())
> return 0;
>
> + /*
> + * There is no reclaim protection applied to a targeted reclaim.
> + * We are special casing this specific case here because
> + * mem_cgroup_protected calculation is not robust enough to keep
> + * the protection invariant for calculated effective values for
> + * parallel reclaimers with different reclaim target. This is
> + * especially a problem for tail memcgs (as they have pages on LRU)
> + * which would want to have effective values 0 for targeted reclaim
> + * but a different value for external reclaim.
> + *
> + * Example
> + * Let's have global and A's reclaim in parallel:
> + * |
> + * A (low=2G, usage = 3G, max = 3G, children_low_usage = 1.5G)
> + * |\
> + * | C (low = 1G, usage = 2.5G)
> + * B (low = 1G, usage = 0.5G)
> + *
> + * For the global reclaim
> + * A.elow = A.low
> + * B.elow = min(B.usage, B.low) because children_low_usage <= A.elow
> + * C.elow = min(C.usage, C.low)
> + *
> + * With the effective values resetting we have A reclaim
> + * A.elow = 0
> + * B.elow = B.low
> + * C.elow = C.low
> + *
> + * If the global reclaim races with A's reclaim then
> + * B.elow = C.elow = 0 because children_low_usage > A.elow)
> + * is possible and reclaiming B would be violating the protection.
> + *
> + */
> + if (memcg == root)
> + return 0;
> +
> if (in_low_reclaim)
> return READ_ONCE(memcg->memory.emin);
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 05b4ec2c6499..df88a22f09bc 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -6385,6 +6385,14 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
>
> if (!root)
> root = root_mem_cgroup;
> +
> + /*
> + * Effective values of the reclaim targets are ignored so they
> + * can be stale. Have a look at mem_cgroup_protection for more
> + * details.
> + * TODO: calculation should be more robust so that we do not need
> + * that special casing.
> + */
> if (memcg == root)
> return MEMCG_PROT_NONE;
Acked-by: Roman Gushchin <guro@fb.com>
Thanks!
next prev parent reply other threads:[~2020-04-30 17:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-28 18:26 [PATCH 0/2] mm: memcontrol: memory.{low,min} reclaim fix & cleanup Chris Down
2020-04-28 18:26 ` [PATCH 1/2] mm, memcg: Avoid stale protection values when cgroup is above protection Chris Down
2020-04-28 21:16 ` Johannes Weiner
2020-04-29 10:15 ` Michal Hocko
2020-04-29 10:53 ` Yafang Shao
2020-04-29 14:19 ` Johannes Weiner
2020-04-29 14:03 ` Johannes Weiner
2020-04-29 14:17 ` Yafang Shao
2020-04-29 14:27 ` Johannes Weiner
2020-04-29 14:31 ` Yafang Shao
2020-04-29 15:04 ` Michal Hocko
2020-04-29 16:56 ` Johannes Weiner
2020-04-30 14:57 ` Michal Hocko
2020-04-30 17:17 ` Roman Gushchin [this message]
2020-04-30 23:59 ` Yafang Shao
2020-05-04 7:23 ` Michal Hocko
2020-05-04 22:59 ` Roman Gushchin
2020-04-30 1:04 ` Yafang Shao
2020-04-30 1:16 ` Chris Down
2020-04-30 1:31 ` Yafang Shao
2020-04-30 1:46 ` Chris Down
2020-04-30 1:49 ` Yafang Shao
2020-04-28 18:27 ` [PATCH 2/2] mm, memcg: Decouple e{low,min} state mutations from protection checks Chris Down
2020-04-28 21:19 ` Johannes Weiner
2020-04-29 10:06 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200430171716.GB339283@carbon.dhcp.thefacebook.com \
--to=guro@fb.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=hannes@cmpxchg.org \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).