From: Shakeel Butt <shakeelb@google.com>
To: Muchun Song <songmuchun@bytedance.com>
Cc: Roman Gushchin <guro@fb.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux MM <linux-mm@kvack.org>,
Xiongchun duan <duanxiongchun@bytedance.com>,
fam.zheng@bytedance.com, zhengqi.arch@bytedance.com
Subject: Re: [PATCH v2] mm: memcontrol: fix root_mem_cgroup charging
Date: Mon, 10 May 2021 15:03:52 -0700 [thread overview]
Message-ID: <CALvZod5dOwLAbShLKP2o=nZVcPNJ2pwR-EDNfSTX77H3VVK5+A@mail.gmail.com> (raw)
In-Reply-To: <20210425075410.19255-1-songmuchun@bytedance.com>
On Sun, Apr 25, 2021 at 12:57 AM Muchun Song <songmuchun@bytedance.com> wrote:
>
> The below scenario can cause the page counters of the root_mem_cgroup
> to be out of balance.
>
> CPU0: CPU1:
>
> objcg = get_obj_cgroup_from_current()
> obj_cgroup_charge_pages(objcg)
> memcg_reparent_objcgs()
> // reparent to root_mem_cgroup
> WRITE_ONCE(iter->memcg, parent)
> // memcg == root_mem_cgroup
> memcg = get_mem_cgroup_from_objcg(objcg)
> // do not charge to the root_mem_cgroup
> try_charge(memcg)
>
> obj_cgroup_uncharge_pages(objcg)
> memcg = get_mem_cgroup_from_objcg(objcg)
> // uncharge from the root_mem_cgroup
> refill_stock(memcg)
> drain_stock(memcg)
> page_counter_uncharge(&memcg->memory)
>
> get_obj_cgroup_from_current() never returns a root_mem_cgroup's objcg,
> so we never explicitly charge the root_mem_cgroup. And it's not
> going to change. It's all about a race when we got an obj_cgroup
> pointing at some non-root memcg, but before we were able to charge it,
> the cgroup was gone, objcg was reparented to the root and so we're
> skipping the charging. Then we store the objcg pointer and later use
> to uncharge the root_mem_cgroup.
>
> This can cause the page counter to be less than the actual value.
> Although we do not display the value (mem_cgroup_usage) so there
> shouldn't be any actual problem, but there is a WARN_ON_ONCE in
> the page_counter_cancel(). Who knows if it will trigger? So it
> is better to fix it.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
prev parent reply other threads:[~2021-05-10 22:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-25 7:54 [PATCH v2] mm: memcontrol: fix root_mem_cgroup charging Muchun Song
2021-05-10 0:54 ` Andrew Morton
2021-05-10 16:28 ` Roman Gushchin
2021-05-10 22:03 ` Shakeel Butt [this message]
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='CALvZod5dOwLAbShLKP2o=nZVcPNJ2pwR-EDNfSTX77H3VVK5+A@mail.gmail.com' \
--to=shakeelb@google.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@kernel.org \
--cc=songmuchun@bytedance.com \
--cc=vdavydov.dev@gmail.com \
--cc=zhengqi.arch@bytedance.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).