Re: [PATCH v2 04/15] mm/hugetlb: account temporary folios separately
From: David Hildenbrand (Arm)
Date: Sun Nov 22 2026 - 13:22:04 EST
On 11/16/26 19:29, David Hildenbrand (Arm) wrote:
> Hugetlb migration might have to allocate a temporary folio through
> alloc_migrate_hugetlb_folio(). Such folios are currently accounted in
> "nr_huge_pages" but not in "surplus_huge_pages". persistent_huge_pages()
> can mistake them as persistent huge pages, as it merely calculates the
> difference.
>
> If set_max_huge_pages() shrinks the pool at the wrong time, it will turn
> hugetlb folios into surplus folios until persistent_huge_pages() returns
> the desired number.
>
> After the migration (successful or unsuccessful) either the new (temporary)
> folio or the old folio gets freed: this will reduce "nr_huge_pages" but
> not "surplus_huge_pages", to undo what was done when allocating a
> temporary folio.
>
> This can result in having more surplus folios than actually allocated
> folios:
>
> HugePages_Total: 0
> HugePages_Surp: 1
>
> From then on persistent_huge_pages() returns garbage.
>
> To fix it, add internal temporary counters and subtract them when
> calculating persistent pool sizes. Update persistent_huge_pages() and add
> persistent_huge_pages_node() to make the code easier to read.
>
> Count migration targets and rejected surplus allocations as temporary.
> Transfer the per-node temporary count along with the temporary flag on
> migration, such that folio freeing will always do the right thing.
>
> Take care of calling account_new_hugetlb_folio() only after setting the
> folios to be temporary.
>
> For now, keep temporary folios in nr_huge_pages, so HugePages_Total and
> Hugetlb continue to include them and overcommit accounting remains
> unchanged. The new temporary counters are internal for now and are not
> exported to userspace.
>
> Fixes: ab5ac90aecf5 ("mm, hugetlb: do not rely on overcommit limit during migration")
> Cc: stable@xxxxxxxxxx
> Reported-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> ---
In combination with
mm/hugetlb: preserve persistent flags when returning folios to the pool
This results in an issue during boot.
I think the following is required:
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bfc88d42ef0d..aa6ad8d93266 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1804,8 +1804,8 @@ void free_huge_folio(struct folio *folio)
h->resv_huge_pages++;
if (folio_test_hugetlb_temporary(folio)) {
- folio_clear_hugetlb_temporary(folio);
remove_hugetlb_folio(h, folio, false);
+ folio_clear_hugetlb_temporary(folio);
spin_unlock_irqrestore(&hugetlb_lock, flags);
update_and_free_hugetlb_folio(h, folio, true);
} else if (h->surplus_huge_pages_node[nid] &&
I'll test real quick whether that resolves CI issues ...
--
Cheers,
David