Re: [PATCH 2/2] mm/migrate: exclude hugetlb folios from MTHP_STAT_NR_ANON accounting
From: Richard Cheng
Date: Fri Jul 03 2026 - 04:37:29 EST
On Fri, Jul 03, 2026 at 09:13:59AM +0800, David Hildenbrand (Arm) wrote:
>
> >> 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))
> >
> > If the hugetlb folio has a non-NULL mapping (i.e., it's a shared mapping), we
> > should migrate it via hugetlbfs_migrate_folio()-
> >>migrate_huge_page_move_mapping(). In other words, shared hugetlb mappings
> > should not reach this path, so this hugetlb check can be dropped. Or am I
> > missing something?
>
> Good point: we should only reach here with anonymous folios that are in the
> swapcache. That doesn't apply to hugetlb.
>
> --
> Cheers,
>
> David
>
I think this is right. THe second site requires folio_test_anon() with a
non-NULL mapping, i. e. an anon folio in the swap cache, and hugetlb folios
never enter the swap cache. Shared hugetlb goes through migrate_huge_page_move_mapping()
as you say, and the only other callers of folio_migrate_mapping() never pass
hugetlb folios either. So the check in the second hunk can't fire.
--Richard