All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@kernel.org>,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	Shakeel Butt <shakeelb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm <linux-mm@kvack.org>,
	open list <linux-kernel@vger.kernel.org>,
	<lkft-triage@lists.linaro.org>, Chris Down <chris@chrisdown.name>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: BUG: Bad page state in process - page dumped because: page still charged to cgroup
Date: Thu, 2 Jul 2020 10:07:12 -0700	[thread overview]
Message-ID: <20200702170712.GB106423@carbon.dhcp.thefacebook.com> (raw)
In-Reply-To: <57270a15-a792-5175-757b-c4bde6da3694@suse.cz>

On Thu, Jul 02, 2020 at 06:35:31PM +0200, Vlastimil Babka wrote:
> On 7/2/20 6:22 PM, Michal Hocko wrote:
> > On Wed 01-07-20 11:45:52, Roman Gushchin wrote:
> > [...]
> >> >From c97afecd32c0db5e024be9ba72f43d22974f5bcd Mon Sep 17 00:00:00 2001
> >> From: Roman Gushchin <guro@fb.com>
> >> Date: Wed, 1 Jul 2020 11:05:32 -0700
> >> Subject: [PATCH] mm: kmem: make memcg_kmem_enabled() irreversible
> >> 
> >> Historically the kernel memory accounting was an opt-in feature, which
> >> could be enabled for individual cgroups. But now it's not true, and
> >> it's on by default both on cgroup v1 and cgroup v2.  And as long as a
> >> user has at least one non-root memory cgroup, the kernel memory
> >> accounting is on. So in most setups it's either always on (if memory
> >> cgroups are in use and kmem accounting is not disabled), either always
> >> off (otherwise).
> >> 
> >> memcg_kmem_enabled() is used in many places to guard the kernel memory
> >> accounting code. If memcg_kmem_enabled() can reverse from returning
> >> true to returning false (as now), we can't rely on it on release paths
> >> and have to check if it was on before.
> >> 
> >> If we'll make memcg_kmem_enabled() irreversible (always returning true
> >> after returning it for the first time), it'll make the general logic
> >> more simple and robust. It also will allow to guard some checks which
> >> otherwise would stay unguarded.
> >> 
> >> Signed-off-by: Roman Gushchin <guro@fb.com>
> 
> Fixes: ? or let Andrew squash it to some patch of your series (it's in mmotm I
> think)?

Hm, it's actually complicated. One obvious case was added by
"mm: memcg/slab: save obj_cgroup for non-root slab objects",
which is currently in the mm tree, so no stable hash.

But I suspect that there are more cases where we just silently leaking
a memcg reference. But because the whole setup (going back and forth
between 0 and 1+ memory cgroups) can not be easily found in the real life,
nobody cares. So I don't think we really need a stable backport.

So IMO the best option is to put it as a standalone patch _before_
my series. Does it sound good to you?

> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

> 
> But see below:
> 
> >> ---
> >>  mm/memcontrol.c | 6 ++----
> >>  1 file changed, 2 insertions(+), 4 deletions(-)
> >> 
> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> >> index 50ae77f3985e..2d018a51c941 100644
> >> --- a/mm/memcontrol.c
> >> +++ b/mm/memcontrol.c
> >> @@ -3582,7 +3582,8 @@ static int memcg_online_kmem(struct mem_cgroup *memcg)
> >>  	objcg->memcg = memcg;
> >>  	rcu_assign_pointer(memcg->objcg, objcg);
> >>  
> >> -	static_branch_inc(&memcg_kmem_enabled_key);
> >> +	if (!memcg_kmem_enabled())
> >> +		static_branch_inc(&memcg_kmem_enabled_key);
> > 
> > Wouldn't be static_branch_enable() more readable?
> 
> Yes, and drop the if(). It will just do nothing and return if already enabled.
> Maybe slightly less efficient, but this is not a fast path anyway, and it feels
> weird to modify the static key in a branch controlled by the static key itself
> (CC peterz in case he wants to add something).

Ok, will do in v2.

Thanks!

  reply	other threads:[~2020-07-02 17:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01  8:18 BUG: Bad page state in process - page dumped because: page still charged to cgroup Naresh Kamboju
2020-07-01  8:18 ` Naresh Kamboju
2020-07-01  8:29 ` Michal Hocko
2020-07-01 12:31   ` Naresh Kamboju
2020-07-01 12:31     ` Naresh Kamboju
2020-07-01 18:45   ` Roman Gushchin
2020-07-02  6:19     ` Michal Hocko
2020-07-02  6:52     ` Naresh Kamboju
2020-07-02  6:52       ` Naresh Kamboju
2020-07-02 15:49       ` Roman Gushchin
2020-07-02 15:55         ` Naresh Kamboju
2020-07-02 15:55           ` Naresh Kamboju
2020-07-02 15:59           ` Roman Gushchin
2020-07-02 16:02     ` Shakeel Butt
2020-07-02 16:02       ` Shakeel Butt
2020-07-02 16:22     ` Michal Hocko
2020-07-02 16:35       ` Vlastimil Babka
2020-07-02 17:07         ` Roman Gushchin [this message]
2020-07-02 17:10         ` Michal Hocko
2020-07-02 16:37       ` Roman Gushchin
2020-07-02 17:13         ` Michal Hocko
2020-07-02 17:19           ` Roman Gushchin

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=20200702170712.GB106423@carbon.dhcp.thefacebook.com \
    --to=guro@fb.com \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chrisdown.name \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkft-triage@lists.linaro.org \
    --cc=mhocko@kernel.org \
    --cc=naresh.kamboju@linaro.org \
    --cc=peterz@infradead.org \
    --cc=shakeelb@google.com \
    --cc=vbabka@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.