* [Bug Report] Elevated PMD nr_anon after running selftests @ 2026-06-11 15:58 Nico Pache 2026-06-11 16:09 ` David Hildenbrand (Arm) 2026-06-11 16:39 ` Lorenzo Stoakes 0 siblings, 2 replies; 6+ messages in thread From: Nico Pache @ 2026-06-11 15:58 UTC (permalink / raw) To: Linux MM, linux-kselftest, LKML, linux-cxl Cc: David Hildenbrand (Red Hat), Lorenzo Stoakes (Oracle), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple Hi, While testing my mTHP code I noticed that mm selftests caused an accounting error in /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. This issue occurs in two mm selftests: 1) hmm test 2) migration - private_anon_htlb test I spoke to David about this and he suggested the following diff which seems to have solved both issues. David would you like to send a formal patch or patches? Cheers, -- Nico Diff for (1) diff --git a/mm/memremap.c b/mm/memremap.c index 053842d45cb1..683a77dd679d 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) mem_cgroup_uncharge(folio); if (folio_test_anon(folio)) { + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); for (i = 0; i < nr; i++) __ClearPageAnonExclusive(folio_page(folio, i)); } -- 2.54.0 For (2) he suggested diff --git a/mm/migrate.c b/mm/migrate.c index d9b23909d716..9fd50ea25d2d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -590,7 +590,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, /* No turning back from here */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; - if (folio_test_anon(folio) && folio_test_large(folio)) + if (folio_test_anon(folio) && folio_test_large(folio) && + !folio_test_hugetlb(folio)) mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); if (folio_test_swapbacked(folio)) __folio_set_swapbacked(newfolio); @@ -623,7 +624,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; - if (folio_test_anon(folio) && folio_test_large(folio)) + if (folio_test_anon(folio) && folio_test_large(folio) && + !folio_test_hugetlb(folio)) mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); folio_ref_add(newfolio, nr); /* add cache reference */ if (folio_test_swapbacked(folio)) -- 2.54.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Bug Report] Elevated PMD nr_anon after running selftests 2026-06-11 15:58 [Bug Report] Elevated PMD nr_anon after running selftests Nico Pache @ 2026-06-11 16:09 ` David Hildenbrand (Arm) 2026-06-11 16:23 ` David Hildenbrand (Arm) 2026-06-11 16:39 ` Lorenzo Stoakes 1 sibling, 1 reply; 6+ messages in thread From: David Hildenbrand (Arm) @ 2026-06-11 16:09 UTC (permalink / raw) To: Nico Pache, Linux MM, linux-kselftest, LKML, linux-cxl Cc: Lorenzo Stoakes (Oracle), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple On 6/11/26 17:58, Nico Pache wrote: > Hi, > > While testing my mTHP code I noticed that mm selftests caused an accounting error in > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon > > At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. > > This issue occurs in two mm selftests: > 1) hmm test > 2) migration - private_anon_htlb test > > I spoke to David about this and he suggested the following diff which seems to have solved both issues. > > David would you like to send a formal patch or patches? > > Cheers, > -- Nico > > Diff for (1) > > diff --git a/mm/memremap.c b/mm/memremap.c > index 053842d45cb1..683a77dd679d 100644 > --- a/mm/memremap.c > +++ b/mm/memremap.c > @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) > mem_cgroup_uncharge(folio); > > if (folio_test_anon(folio)) { > + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); > for (i = 0; i < nr; i++) > __ClearPageAnonExclusive(folio_page(folio, i)); > } Wasn't there another issue with hugetlb? diff --git a/mm/migrate.c b/mm/migrate.c index 8a64291ab5b4..0aec894266f2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -590,7 +590,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, /* No turning back from here */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; - if (folio_test_anon(folio) && folio_test_large(folio)) + if (folio_test_anon(folio) && folio_test_large(folio) && + !folio_test_hugetlb(folio)) mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); if (folio_test_swapbacked(folio)) __folio_set_swapbacked(newfolio); @@ -623,7 +624,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; - if (folio_test_anon(folio) && folio_test_large(folio)) + if (folio_test_anon(folio) && folio_test_large(folio) && + !folio_test_hugetlb(folio)) mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); folio_ref_add(newfolio, nr); /* add cache reference */ if (folio_test_swapbacked(folio)) Yeah, if you have some capacity, please send patches (and figure out Fixes:) :) -- Cheers, David ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Bug Report] Elevated PMD nr_anon after running selftests 2026-06-11 16:09 ` David Hildenbrand (Arm) @ 2026-06-11 16:23 ` David Hildenbrand (Arm) 2026-06-11 16:38 ` Nico Pache 0 siblings, 1 reply; 6+ messages in thread From: David Hildenbrand (Arm) @ 2026-06-11 16:23 UTC (permalink / raw) To: Nico Pache, Linux MM, linux-kselftest, LKML, linux-cxl Cc: Lorenzo Stoakes (Oracle), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple On 6/11/26 18:09, David Hildenbrand (Arm) wrote: > On 6/11/26 17:58, Nico Pache wrote: >> Hi, >> >> While testing my mTHP code I noticed that mm selftests caused an accounting error in >> /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon >> >> At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. >> >> This issue occurs in two mm selftests: >> 1) hmm test >> 2) migration - private_anon_htlb test >> >> I spoke to David about this and he suggested the following diff which seems to have solved both issues. >> >> David would you like to send a formal patch or patches? >> >> Cheers, >> -- Nico >> >> Diff for (1) >> >> diff --git a/mm/memremap.c b/mm/memremap.c >> index 053842d45cb1..683a77dd679d 100644 >> --- a/mm/memremap.c >> +++ b/mm/memremap.c >> @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) >> mem_cgroup_uncharge(folio); >> >> if (folio_test_anon(folio)) { >> + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); >> for (i = 0; i < nr; i++) >> __ClearPageAnonExclusive(folio_page(folio, i)); >> } > > Wasn't there another issue with hugetlb? Just realized that you sent this, but somehow my mail client got confused and hid it. -- Cheers, David ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bug Report] Elevated PMD nr_anon after running selftests 2026-06-11 16:23 ` David Hildenbrand (Arm) @ 2026-06-11 16:38 ` Nico Pache 0 siblings, 0 replies; 6+ messages in thread From: Nico Pache @ 2026-06-11 16:38 UTC (permalink / raw) To: David Hildenbrand (Arm) Cc: Linux MM, linux-kselftest, LKML, linux-cxl, Lorenzo Stoakes (Oracle), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple On Thu, Jun 11, 2026 at 10:24 AM David Hildenbrand (Arm) <david@kernel.org> wrote: > > On 6/11/26 18:09, David Hildenbrand (Arm) wrote: > > On 6/11/26 17:58, Nico Pache wrote: > >> Hi, > >> > >> While testing my mTHP code I noticed that mm selftests caused an accounting error in > >> /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon > >> > >> At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. > >> > >> This issue occurs in two mm selftests: > >> 1) hmm test > >> 2) migration - private_anon_htlb test > >> > >> I spoke to David about this and he suggested the following diff which seems to have solved both issues. > >> > >> David would you like to send a formal patch or patches? > >> > >> Cheers, > >> -- Nico > >> > >> Diff for (1) > >> > >> diff --git a/mm/memremap.c b/mm/memremap.c > >> index 053842d45cb1..683a77dd679d 100644 > >> --- a/mm/memremap.c > >> +++ b/mm/memremap.c > >> @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) > >> mem_cgroup_uncharge(folio); > >> > >> if (folio_test_anon(folio)) { > >> + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); > >> for (i = 0; i < nr; i++) > >> __ClearPageAnonExclusive(folio_page(folio, i)); > >> } > > > > Wasn't there another issue with hugetlb? > > Just realized that you sent this, but somehow my mail client got confused and > hid it. Yeah, sorry. Thanks for the message about the email client setting I'm probably missing. Thunderbird may actually work for me now :) Cheers, -- Nico > > -- > Cheers, > > David > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bug Report] Elevated PMD nr_anon after running selftests 2026-06-11 15:58 [Bug Report] Elevated PMD nr_anon after running selftests Nico Pache 2026-06-11 16:09 ` David Hildenbrand (Arm) @ 2026-06-11 16:39 ` Lorenzo Stoakes 2026-06-11 17:24 ` Nico Pache 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Stoakes @ 2026-06-11 16:39 UTC (permalink / raw) To: Nico Pache Cc: Linux MM, linux-kselftest, LKML, linux-cxl, David Hildenbrand (Red Hat), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple On Thu, Jun 11, 2026 at 09:58:55AM -0600, Nico Pache wrote: > Hi, > > While testing my mTHP code I noticed that mm selftests caused an accounting error in > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon You're not giving any details? how does this manifest? How did you detect? Output? Etc. > > At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. Seems to be a regression in your editor's line wrapping... ;) > > This issue occurs in two mm selftests: > 1) hmm test > 2) migration - private_anon_htlb test OK that's useful, but what exactly happened? Any test output? > > I spoke to David about this and he suggested the following diff which seems to have solved both issues. Whilst speaking to people off-list/elsewhere etc. is totally fine, I'd suggest engaging with the community as the first course of action is often a good way of resolving things. Even if things arise from private discussions, which is also totally fine, please do give sufficient context so that the community can engage with it. And I would suggest that ideally you phrase things such that you are asking the community as a whole :) > > David would you like to send a formal patch or patches? So on that point, I understand you're asking David specifically because he suggested the patch, but I feel that you'd get better results making it clear that you want community input :) As one might misread this, and perhaps other such occasions, as you feeling THP == 1 person, which I am absolutely sure is not how you feel, but phrasing things a little differently would help underline that :) Kernel review and maintainership can be rather a thankless task, so details like this matter I feel! [and I realise I probably screw up on this regularly too so we're all constantly learning :)] > > Cheers, > -- Nico Thanks, Lorenzo > > Diff for (1) > > diff --git a/mm/memremap.c b/mm/memremap.c > index 053842d45cb1..683a77dd679d 100644 > --- a/mm/memremap.c > +++ b/mm/memremap.c > @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) > mem_cgroup_uncharge(folio); > > if (folio_test_anon(folio)) { > + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); > for (i = 0; i < nr; i++) > __ClearPageAnonExclusive(folio_page(folio, i)); > } > -- > 2.54.0 > > For (2) he suggested > > diff --git a/mm/migrate.c b/mm/migrate.c > index d9b23909d716..9fd50ea25d2d 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -590,7 +590,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, > /* No turning back from here */ > newfolio->index = folio->index; > newfolio->mapping = folio->mapping; > - if (folio_test_anon(folio) && folio_test_large(folio)) > + if (folio_test_anon(folio) && folio_test_large(folio) && > + !folio_test_hugetlb(folio)) > mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); > if (folio_test_swapbacked(folio)) > __folio_set_swapbacked(newfolio); > @@ -623,7 +624,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, > */ > newfolio->index = folio->index; > newfolio->mapping = folio->mapping; > - if (folio_test_anon(folio) && folio_test_large(folio)) > + if (folio_test_anon(folio) && folio_test_large(folio) && > + !folio_test_hugetlb(folio)) > mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); > folio_ref_add(newfolio, nr); /* add cache reference */ > if (folio_test_swapbacked(folio)) > -- > 2.54.0 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bug Report] Elevated PMD nr_anon after running selftests 2026-06-11 16:39 ` Lorenzo Stoakes @ 2026-06-11 17:24 ` Nico Pache 0 siblings, 0 replies; 6+ messages in thread From: Nico Pache @ 2026-06-11 17:24 UTC (permalink / raw) To: Lorenzo Stoakes Cc: Linux MM, linux-kselftest, LKML, linux-cxl, David Hildenbrand (Red Hat), Oscar Salvador, Andrew Morton, Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park, Gregory Price, Ying Huang, Alistair Popple On Thu, Jun 11, 2026 at 10:39 AM Lorenzo Stoakes <ljs@kernel.org> wrote: > > On Thu, Jun 11, 2026 at 09:58:55AM -0600, Nico Pache wrote: > > Hi, > > > > While testing my mTHP code I noticed that mm selftests caused an accounting error in > > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon > > You're not giving any details? how does this manifest? How did you detect? > Output? Etc. When running my mTHP tests, I always have a terminal with watch grep . /sys/kernel/mm/transparent_hugepage/hugepages-*/stats/nr_anon I noticed that when I ran selftests the 2MB count remained elevated even after the tests finished and the system memory was returned. e.g) /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon:34831 > > > > > At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. > > Seems to be a regression in your editor's line wrapping... ;) Haha yeah still figuring that one out :) The guide on setting up Thunderbird recommends wrapping at 0 which seems wrong... Hopefully I have it working correctly now. > > > > > This issue occurs in two mm selftests: > > 1) hmm test > > 2) migration - private_anon_htlb test > > OK that's useful, but what exactly happened? Any test output? Tests seem to be ok (although the HMM tests fails, but that's not new) > > > > > I spoke to David about this and he suggested the following diff which seems to have solved both issues. > > Whilst speaking to people off-list/elsewhere etc. is totally fine, I'd suggest > engaging with the community as the first course of action is often a good way of > resolving things. > > Even if things arise from private discussions, which is also totally fine, > please do give sufficient context so that the community can engage with it. That was my goal here :) Perhaps I fell short... > > And I would suggest that ideally you phrase things such that you are asking the > community as a whole :) > > > > > David would you like to send a formal patch or patches? > > So on that point, I understand you're asking David specifically because he > suggested the patch, but I feel that you'd get better results making it clear > that you want community input :) Yeah I didn't want to just send a fix that wasn't authored by me, and I didn't fully understand it. When I brought this up to David (during a separate off-list conversation), he suggested fixes within minutes, and asked me to test. This was the formal follow up. > > As one might misread this, and perhaps other such occasions, as you feeling THP > == 1 person, which I am absolutely sure is not how you feel, but phrasing things > a little differently would help underline that :) > > Kernel review and maintainership can be rather a thankless task, so details like > this matter I feel! [and I realise I probably screw up on this regularly too so > we're all constantly learning :)] Yep! Still learning (and often failing :)) Cheers, -- Nico > > > > > Cheers, > > -- Nico > > Thanks, Lorenzo > > > > > Diff for (1) > > > > diff --git a/mm/memremap.c b/mm/memremap.c > > index 053842d45cb1..683a77dd679d 100644 > > --- a/mm/memremap.c > > +++ b/mm/memremap.c > > @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) > > mem_cgroup_uncharge(folio); > > > > if (folio_test_anon(folio)) { > > + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); > > for (i = 0; i < nr; i++) > > __ClearPageAnonExclusive(folio_page(folio, i)); > > } > > -- > > 2.54.0 > > > > For (2) he suggested > > > > diff --git a/mm/migrate.c b/mm/migrate.c > > index d9b23909d716..9fd50ea25d2d 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -590,7 +590,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, > > /* No turning back from here */ > > newfolio->index = folio->index; > > newfolio->mapping = folio->mapping; > > - if (folio_test_anon(folio) && folio_test_large(folio)) > > + if (folio_test_anon(folio) && folio_test_large(folio) && > > + !folio_test_hugetlb(folio)) > > mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); > > if (folio_test_swapbacked(folio)) > > __folio_set_swapbacked(newfolio); > > @@ -623,7 +624,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, > > */ > > newfolio->index = folio->index; > > newfolio->mapping = folio->mapping; > > - if (folio_test_anon(folio) && folio_test_large(folio)) > > + if (folio_test_anon(folio) && folio_test_large(folio) && > > + !folio_test_hugetlb(folio)) > > mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); > > folio_ref_add(newfolio, nr); /* add cache reference */ > > if (folio_test_swapbacked(folio)) > > -- > > 2.54.0 > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-11 17:23 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-11 15:58 [Bug Report] Elevated PMD nr_anon after running selftests Nico Pache 2026-06-11 16:09 ` David Hildenbrand (Arm) 2026-06-11 16:23 ` David Hildenbrand (Arm) 2026-06-11 16:38 ` Nico Pache 2026-06-11 16:39 ` Lorenzo Stoakes 2026-06-11 17:24 ` Nico Pache
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox