From: Muchun Song <muchun.song@linux.dev>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Hongfu Li <hongfu.li@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Michal Hocko <mhocko@suse.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Nhat Pham <nphamcs@gmail.com>, Chris Down <chris@chrisdown.name>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, Hongfu Li <lihongfu@kylinos.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/hugetlb: account migration target folio in per-node NR_HUGETLB vmstat
Date: Tue, 22 Sep 2026 11:34:06 +0800 [thread overview]
Message-ID: <5FE0FD2F-4F8D-4EF9-BD78-2AB97E10B687@linux.dev> (raw)
In-Reply-To: <20260921223544.2401052-1-joshua.hahnjy@gmail.com>
> On Sep 22, 2026, at 06:35, Joshua Hahn <joshua.hahnjy@gmail.com> wrote:
>
> On Mon, 21 Sep 2026 17:12:34 +0800 Hongfu Li <hongfu.li@linux.dev> wrote:
>
> Hi Hongfu,
>
> Thanks for this fix. From the cover letter I was frowning because I was
> thinking to myself "surely there's no way hugetlb accounting is this
> broken..." but it seems like indeed it is.
>
>> From: Hongfu Li <lihongfu@kylinos.cn>
>>
>> The NR_HUGETLB vmstat counter is maintained per folio's node: incremented
>> when a huge page is handed to a user via hugetlb_alloc_folio() and
>> decremented when it is returned to the pool via free_huge_folio().
>>
>> A folio obtained by alloc_hugetlb_folio_nodemask() never goes through
>> hugetlb_alloc_folio(), so it is never accounted, while its free always
>> is.
>
> That's pretty scary! Glad that you caught it here.
>
>> For a migration target this means the target node gets no matching
>> increment for the decrement on the old node, so the global nr_hugetlb in
>> /proc/vmstat drops by nr_pages for each migration. The same asymmetry
>> affects the failed migration path, which frees the target again right
>> away, and the temporary folio hugetlb_mfill_atomic_pte() takes from the
>> same helper.
>>
>> alloc_hugetlb_folio_reserve(), used to preallocate the memfd page cache
>> folios, has the same asymmetry: the folio is handed to a user without
>> being accounted, while its free is accounted through free_huge_folio().
>>
>> Account the folio where it is obtained, in alloc_hugetlb_folio_nodemask()
>> and alloc_hugetlb_folio_reserve(), so that the increment pairs with the
>> decrement in free_huge_folio(): a successful migration hands the folio
>> to a user, a failed one frees it again.
>
> The changes look good to me, and I was able to reproduce the issue on
> my host and confirm that after this change, the missing charge is
> fully accounted for.
> Tested-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
>
> Again, I'm super surprised that a problem this big has gone unnoticed
> for so long. Thanks again for working on this fix!
I think a migration for HugeTLB is very rare. That's probably why it
took us so long to find this issue.
Thanks.
>
> I hope you have a great day : -)
> Joshua
>
>> Fixes: 05d4532b60e3 ("memcg/hugetlb: add hugeTLB counters to memcg")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
>> ---
next prev parent reply other threads:[~2026-09-22 3:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 9:12 [PATCH 0/2] mm: fix hugetlb NR_HUGETLB accounting on folio migration Hongfu Li
2026-09-21 9:12 ` [PATCH 1/2] mm/hugetlb: account migration target folio in per-node NR_HUGETLB vmstat Hongfu Li
2026-09-21 22:35 ` Joshua Hahn
2026-09-22 3:34 ` Muchun Song [this message]
2026-09-22 3:33 ` Muchun Song
2026-09-22 4:04 ` Oscar Salvador (SUSE)
2026-09-21 9:12 ` [PATCH 2/2] mm/memcg: migrate per-node hugetlb lruvec stat together with hugetlb folio Hongfu Li
2026-09-21 23:03 ` Joshua Hahn
2026-09-22 4:15 ` Oscar Salvador (SUSE)
2026-09-22 4:20 ` Joshua Hahn
2026-09-22 4:30 ` Oscar Salvador (SUSE)
2026-09-22 6:31 ` Muchun Song
2026-09-22 6:18 ` Muchun Song
2026-09-22 9:38 ` Hongfu Li
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=5FE0FD2F-4F8D-4EF9-BD78-2AB97E10B687@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hongfu.li@linux.dev \
--cc=joshua.hahnjy@gmail.com \
--cc=lihongfu@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=nphamcs@gmail.com \
--cc=osalvador@suse.de \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
/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.