Re: [PATCH v2 12/15] mm/hugetlb: keep surplus folios that are reserved
From: Oscar Salvador (SUSE)
Date: Thu Nov 19 2026 - 04:21:58 EST
On Mon, Nov 16, 2026 at 07:29:33PM +0100, David Hildenbrand (Arm) 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 ]
> Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
> Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Acked-by: Oscar Salvador (SUSE) <osalvador@xxxxxxxxxx>
--
Oscar Salvador
SUSE Labs