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