linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	Chris Down <chris@chrisdown.name>,
	Shakeel Butt <shakeelb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH v2] mm, memcg: fix inconsistent oom event behavior
Date: Wed, 22 Apr 2020 13:51:47 +0200	[thread overview]
Message-ID: <20200422115147.GE30312@dhcp22.suse.cz> (raw)
In-Reply-To: <20200422110643.15725-1-laoar.shao@gmail.com>

On Wed 22-04-20 07:06:43, Yafang Shao wrote:
> A recent commit 9852ae3fe529 ("mm, memcg: consider subtrees in
> memory.events") changes the behavior of memcg events, which will
> consider subtrees in memory.events. But oom_kill event is a special one
> as it is used in both cgroup1 and cgroup2. In cgroup1, it is displayed
> in memory.oom_control. The file memory.oom_control is in both root memcg
> and non root memcg, that is different with memory.event as it only in
> non-root memcg. That commit is okay for cgroup2, but it is not okay for
> cgroup1 as it will cause inconsistent behavior between root memcg and
> non-root memcg.
> 
> Here's an example on why this behavior is inconsistent in cgroup1.
>      root memcg
>      /
>   memcg foo
>    /
> memcg bar
> 
> Suppose there's an oom_kill in memcg bar, then the oon_kill will be
> 
>      root memcg : memory.oom_control(oom_kill)  0
>      /
>   memcg foo : memory.oom_control(oom_kill)  1
>    /
> memcg bar : memory.oom_control(oom_kill)  1
> 
> For the non-root memcg, its memory.oom_control(oom_kill) includes its
> descendants' oom_kill, but for root memcg, it doesn't include its
> descendants' oom_kill. That means, memory.oom_control(oom_kill) has
> different meanings in different memcgs. That is inconsistent. Then the user
> has to know whether the memcg is root or not.
> 
> If we can't fully support it in cgroup1, for example by adding
> memory.events.local into cgroup1 as well, then let's don't touch
> its original behavior.
> 
> Setting CGRP_ROOT_MEMORY_LOCAL_EVENTS for legacy hierarchy by
> default rather than special casing it somewhere quite deep in the code
> would be better, per discussion with Michal.

OK, this makes sense to me. Cgroup v1 really had local semantic and
9852ae3fe529 changed it unintentionally. I think it is reasonable to use
the CGRP_ROOT_MEMORY_LOCAL_EVENTS which denotes this mode but I will
defer to cgroup maintainers. Maybe there are some other side effects
which I am not aware of that would make this more awkward than a special
case for cgroup v1

> Fixes: 9852ae3fe529 ("mm, memcg: consider subtrees in memory.events")
> Cc: Chris Down <chris@chrisdown.name>
> Cc: Shakeel Butt <shakeelb@google.com>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/memcontrol.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5beea03dd58a..0f7381bddcee 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5940,10 +5940,20 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)
>  	 * guarantees that @root doesn't have any children, so turning it
>  	 * on for the root memcg is enough.
>  	 */
> -	if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
> +	if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
>  		root_mem_cgroup->use_hierarchy = true;
> -	else
> +	} else {
>  		root_mem_cgroup->use_hierarchy = false;
> +		/*
> +		 * Set CGRP_ROOT_MEMORY_LOCAL_EVENTS for legacy hierarchy
> +		 * by default to avoid inconsistent oom_kill behavior
> +		 * between root memcg and non-root memcg.
> +		 * Regarding default hierarchy, as this flag will be set
> +		 * or cleared later, we don't need to process it in this
> +		 * function.
> +		 */

I do not think the comment has to be so specific about oom events
behavior. I would just go with
		/*
		 * Cgroup v1 has traditionally had local semantic for
		 * event counters. Cgroup v2 changed that to a
		 * hierarchical behavior. This is expressed by
		 * CGRP_ROOT_MEMORY_LOCAL_EVENTS in the cgroup core.
		 */
> +		cgrp_dfl_root.flags |= CGRP_ROOT_MEMORY_LOCAL_EVENTS;
> +	}
>  }
>  
>  static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value)
> -- 
> 2.18.2

-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2020-04-22 11:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22 11:06 [PATCH v2] mm, memcg: fix inconsistent oom event behavior Yafang Shao
2020-04-22 11:51 ` Michal Hocko [this message]
2020-04-22 12:54 ` Johannes Weiner
2020-04-22 12:58   ` Yafang Shao
2020-04-22 13:02     ` Chris Down
2020-04-22 13:15       ` Yafang Shao
2020-04-22 13:15   ` Michal Hocko
  -- strict thread matches above, loose matches on Subject: below --
2020-04-14  1:59 Yafang Shao
2020-04-14 15:22 ` Michal Hocko
2020-04-14 15:57   ` Yafang Shao

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=20200422115147.GE30312@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chrisdown.name \
    --cc=hannes@cmpxchg.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=shakeelb@google.com \
    /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).