Re: [PATCH 12/15] mm/hugetlb: keep surplus folios that are reserved
From: Muchun Song
Date: Mon Nov 02 2026 - 03:12:26 EST
> On Oct 29, 2026, at 04:13, David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
>
> From: Chris Mason <mason@xxxxxxxxxx>
>
> free_huge_folio() may restore a reservation, but still returns the folio
> to the page allocator if its node has surplus huge pages.
>
> For example, start with no hugetlb folios and allow one surplus 2 MiB
> folio:
>
> 1. Mount hugetlbfs with pagesize=2M,min_size=2M. This allocates and
> reserves one surplus folio: free=1, reserved=1.
> 2. Create a 2 MiB file and write to a shared mapping of it. The fault
> consumes the folio and its reservation: free=0, reserved=0.
> 3. Unmap the file and truncate it to zero. The mount's reservation is
> restored, but the surplus folio is freed: free=0, reserved=1.
>
> Besides losing a hugetlb folio that is required for a reservation, this
> can also make available_huge_pages() underflow and cause other issues.
>
> Keep the folio in the pool if it is needed to cover reservations,
> including any reservation we just restored.
>
> Fix generated by an LLM and sent by Chris Mason in private.
>
> Fixes: 07443a85ad90 ("mm, hugetlb: return a reserved page to a reserved pool if failed")
> Cc: stable@xxxxxxxxxx
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: simplify comment and description ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
Thanks.