From: Yang Shi <shy828301@gmail.com>
To: Michal Hocko <mhocko@suse.com>
Cc: Yongqiang Liu <liuyongqiang13@huawei.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
aarcange@redhat.com, hughd@google.com, mgorman@suse.de,
cl@gentwo.org, zokeefe@google.com, rientjes@google.com,
Matthew Wilcox <willy@infradead.org>,
peterx@redhat.com,
"Wangkefeng (OS Kernel Lab)" <wangkefeng.wang@huawei.com>,
"zhangxiaoxu (A)" <zhangxiaoxu5@huawei.com>,
kirill.shutemov@linux.intel.com,
Lu Jialin <lujialin4@huawei.com>
Subject: Re: [QUESTION] memcg page_counter seems broken in MADV_DONTNEED with THP enabled
Date: Tue, 29 Nov 2022 09:49:25 -0800 [thread overview]
Message-ID: <CAHbLzkpZWp4-XfSpXw86UokPuXSMPRg1UWfgpjL=FixjBr6sFw@mail.gmail.com> (raw)
In-Reply-To: <Y4W+joR1rIug0ydA@dhcp22.suse.cz>
On Tue, Nov 29, 2022 at 12:10 AM Michal Hocko <mhocko@suse.com> wrote:
>
> On Mon 28-11-22 12:01:37, Yang Shi wrote:
> > On Sat, Nov 26, 2022 at 5:10 AM Yongqiang Liu <liuyongqiang13@huawei.com> wrote:
> > >
> > > Hi,
> > >
> > > We use mm_counter to how much a process physical memory used. Meanwhile,
> > > page_counter of a memcg is used to count how much a cgroup physical
> > > memory used.
> > > If a cgroup only contains a process, they looks almost the same. But with
> > > THP enabled, sometimes memory.usage_in_bytes in memcg may be twice or
> > > more than rss
> > > in proc/[pid]/smaps_rollup as follow:
> [...]
> > > node_page_stat which shows in meminfo was also decreased. the
> > > __split_huge_pmd
> > > seems free no physical memory unless the total THP was free.I am
> > > confused which
> > > one is the true physical memory used of a process.
> >
> > This should be caused by the deferred split of THP. When MADV_DONTNEED
> > is called on the partial of the map, the huge PMD is split, but the
> > THP itself will not be split until the memory pressure is hit (global
> > or memcg limit). So the unmapped sub pages are actually not freed
> > until that point. So the mm counter is decreased due to the zapping
> > but the physical pages are not actually freed then uncharged from
> > memcg.
>
> Yes, and this is not really bound to THP. Consider a page cache. It can
> be accessed via syscalls when it doesn't correspondent to rss at all
> while it is still charged to a memcg. Or it can be mapped and then later
> unmapped so it disappear from rss while it is still charged until it
> gets reclaimed by the memory pressure. Or it can be an in-memory object
> that is not bound to any process life time (e.g. tmpfs). Or it can be a
> kernel memory charged to a memcg which is not covered by rss because it
> is either not mapped or it is unknown to rss counters.
Yes, good points. Thanks, Michal. And one more thing worth mentioning
is that the RSS shown by ps or smaps is different from the RSS shown
by memcg.
> --
> Michal Hocko
> SUSE Labs
next prev parent reply other threads:[~2022-11-29 17:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-26 13:09 Yongqiang Liu
2022-11-28 20:01 ` Yang Shi
2022-11-29 8:10 ` Michal Hocko
2022-11-29 13:19 ` Yongqiang Liu
2022-11-29 17:49 ` Yang Shi [this message]
2022-11-29 13:14 ` Yongqiang Liu
2022-11-29 17:23 ` Yang Shi
2022-12-01 2:22 ` Yongqiang Liu
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='CAHbLzkpZWp4-XfSpXw86UokPuXSMPRg1UWfgpjL=FixjBr6sFw@mail.gmail.com' \
--to=shy828301@gmail.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=hughd@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuyongqiang13@huawei.com \
--cc=lujialin4@huawei.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=peterx@redhat.com \
--cc=rientjes@google.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=zhangxiaoxu5@huawei.com \
--cc=zokeefe@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