From: Muchun Song <songmuchun@bytedance.com>
To: Michal Hocko <mhocko@suse.com>
Cc: guro@fb.com, hannes@cmpxchg.org, akpm@linux-foundation.org,
shakeelb@google.com, vdavydov.dev@gmail.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
duanxiongchun@bytedance.com, fam.zheng@bytedance.com
Subject: Re: [External] Re: [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm
Date: Wed, 14 Apr 2021 18:04:35 +0800 [thread overview]
Message-ID: <CAMZfGtVpUW1=Zvys7J=gW1xqkuUVLuPYcQbwJoe=TEkBa6qqQw@mail.gmail.com> (raw)
In-Reply-To: <YHa00lx7ACWcS1/h@dhcp22.suse.cz>
On Wed, Apr 14, 2021 at 5:24 PM Michal Hocko <mhocko@suse.com> wrote:
>
> On Tue 13-04-21 14:51:48, Muchun Song wrote:
> > When mm is NULL, we do not need to hold rcu lock and call css_tryget for
> > the root memcg. And we also do not need to check !mm in every loop of
> > while. So bail out early when !mm.
>
> mem_cgroup_charge and other callers unconditionally drop the reference
> so how come this does not underflow reference count?
For the root memcg, the CSS_NO_REF flag is set, so css_get
and css_put do not get or put reference.
Thanks.
>
> > Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> > Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> > Reviewed-by: Shakeel Butt <shakeelb@google.com>
> > ---
> > mm/memcontrol.c | 21 ++++++++++-----------
> > 1 file changed, 10 insertions(+), 11 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index f229de925aa5..9cbfff59b171 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -901,20 +901,19 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
> > if (mem_cgroup_disabled())
> > return NULL;
> >
> > + /*
> > + * Page cache insertions can happen without an
> > + * actual mm context, e.g. during disk probing
> > + * on boot, loopback IO, acct() writes etc.
> > + */
> > + if (unlikely(!mm))
> > + return root_mem_cgroup;
> > +
> > rcu_read_lock();
> > do {
> > - /*
> > - * Page cache insertions can happen without an
> > - * actual mm context, e.g. during disk probing
> > - * on boot, loopback IO, acct() writes etc.
> > - */
> > - if (unlikely(!mm))
> > + memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
> > + if (unlikely(!memcg))
> > memcg = root_mem_cgroup;
> > - else {
> > - memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
> > - if (unlikely(!memcg))
> > - memcg = root_mem_cgroup;
> > - }
> > } while (!css_tryget(&memcg->css));
> > rcu_read_unlock();
> > return memcg;
> > --
> > 2.11.0
>
> --
> Michal Hocko
> SUSE Labs
next prev parent reply other threads:[~2021-04-14 10:05 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 6:51 [PATCH 0/7] memcontrol code cleanup and simplification Muchun Song
2021-04-13 6:51 ` [PATCH 1/7] mm: memcontrol: fix page charging in page replacement Muchun Song
2021-04-13 17:45 ` Roman Gushchin
2021-04-14 9:20 ` Michal Hocko
2021-04-13 6:51 ` [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm Muchun Song
2021-04-13 17:47 ` Roman Gushchin
2021-04-14 9:24 ` Michal Hocko
2021-04-14 10:04 ` Muchun Song [this message]
2021-04-14 10:15 ` [External] " Michal Hocko
2021-04-15 3:13 ` Muchun Song
2021-04-15 7:09 ` Michal Hocko
2021-04-13 6:51 ` [PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock Muchun Song
2021-04-13 13:28 ` Shakeel Butt
2021-04-13 17:57 ` Roman Gushchin
2021-04-14 9:44 ` Michal Hocko
2021-04-14 10:00 ` [External] " Muchun Song
2021-04-14 17:49 ` Johannes Weiner
2021-04-15 7:08 ` Michal Hocko
2021-04-15 10:01 ` Muchun Song
2021-04-13 6:51 ` [PATCH 5/7] mm: memcontrol: simplify the logic of objcg pinning memcg Muchun Song
2021-04-13 14:16 ` Shakeel Butt
2021-04-13 17:51 ` Roman Gushchin
2021-04-13 6:51 ` [PATCH 6/7] mm: memcontrol: move obj_cgroup_uncharge_pages() out of css_set_lock Muchun Song
2021-04-13 14:18 ` Shakeel Butt
2021-04-13 17:54 ` Roman Gushchin
2021-04-13 18:03 ` Johannes Weiner
2021-04-13 6:51 ` [PATCH 7/7] mm: vmscan: remove noinline_for_stack Muchun Song
2021-04-14 9:46 ` Michal Hocko
[not found] ` <20210413065153.63431-4-songmuchun@bytedance.com>
2021-04-13 13:12 ` [PATCH 3/7] mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec Shakeel Butt
2021-04-13 17:48 ` Roman Gushchin
2021-04-14 9:27 ` 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='CAMZfGtVpUW1=Zvys7J=gW1xqkuUVLuPYcQbwJoe=TEkBa6qqQw@mail.gmail.com' \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=duanxiongchun@bytedance.com \
--cc=fam.zheng@bytedance.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=shakeelb@google.com \
--cc=vdavydov.dev@gmail.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