[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4xQhkEOe2Juqgy_3u7PNJ+hhby2qrpdf_X8YCuEwK8Yrw@mail.gmail.com>
Date: Fri, 30 Jan 2026 22:00:40 +0800
From: Barry Song <21cnbao@...il.com>
To: Shakeel Butt <shakeel.butt@...ux.dev>
Cc: Andrew Morton <akpm@...ux-foundation.org>, Johannes Weiner <hannes@...xchg.org>,
Rik van Riel <riel@...riel.com>, Song Liu <songliubraving@...com>,
Kiryl Shutsemau <kas@...nel.org>, Usama Arif <usamaarif642@...il.com>,
David Hildenbrand <david@...nel.org>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Zi Yan <ziy@...dia.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>, Nico Pache <npache@...hat.com>,
Ryan Roberts <ryan.roberts@....com>, Dev Jain <dev.jain@....com>,
Lance Yang <lance.yang@...ux.dev>, Matthew Wilcox <willy@...radead.org>,
Meta kernel team <kernel-team@...a.com>, linux-mm@...ck.org, cgroups@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] mm: khugepaged: fix NR_FILE_PAGES and NR_SHMEM in collapse_file()
On Fri, Jan 30, 2026 at 12:29 PM Shakeel Butt <shakeel.butt@...ux.dev> wrote:
>
> In META's fleet, we observed high-level cgroups showing zero file memcg
> stats while their descendants had non-zero values. Investigation using
> drgn revealed that these parent cgroups actually had negative file stats,
> aggregated from their children.
>
> This issue became more frequent after deploying thp-always more widely,
> pointing to a correlation with THP file collapsing. The root cause is
> that collapse_file() assumes old folios and the new THP belong to the
> same node and memcg. When this assumption breaks, stats become skewed.
> The bug affects not just memcg stats but also per-numa stats, and not
> just NR_FILE_PAGES but also NR_SHMEM.
>
> The assumption breaks in scenarios such as:
>
> 1. Small folios allocated on one node while the THP gets allocated on a
> different node.
>
> 2. A package downloader running in one cgroup populates the page cache,
> while a job in a different cgroup executes the downloaded binary.
>
> 3. A file shared between processes in different cgroups, where one
> process faults in the pages and khugepaged (or madvise(COLLAPSE))
> collapses them on behalf of the other.
>
> Fix the accounting by explicitly incrementing stats for the new THP and
> decrementing stats for the old folios being replaced.
>
> Fixes: f3f0e1d2150b ("khugepaged: add support of collapse for tmpfs/shmem pages")
> Signed-off-by: Shakeel Butt <shakeel.butt@...ux.dev>
Thanks!
Reviewed-by: Barry Song <baohua@...nel.org>
> ---
> mm/khugepaged.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
Powered by blists - more mailing lists