mm/memfd: reserve hugetlb folios before allocation
authorVivek Kasireddy <vivek.kasireddy@intel.com>
Wed, 18 Jun 2025 05:30:54 +0000 (22:30 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:42:15 +0000 (22:42 -0700)
commit717cf9357325055ab6b41c4e0581f4d67601eb58
tree15ae38c923350aa808ff2dc403855da513117e3e
parent986f5f2b4be3b7eab9ecd85c472d03a2191d6fc0
mm/memfd: reserve hugetlb folios before allocation

When we try to allocate a folio via alloc_hugetlb_folio_reserve(), we need
to ensure that there is an active reservation associated with the
allocation.  Otherwise, our allocation request would fail if there are no
active reservations made at that moment against any other allocations.
This is because alloc_hugetlb_folio_reserve() checks h->resv_huge_pages
before proceeding with the allocation.

Therefore, to address this issue, we just need to make a reservation (by
calling hugetlb_reserve_pages()) before we try to allocate the folio.
This will also ensure that proper region/subpool accounting is done
associated with our allocation.

Link: https://lkml.kernel.org/r/20250618053415.1036185-3-vivek.kasireddy@intel.com
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: Steve Sistare <steven.sistare@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/hugetlb.h
mm/hugetlb.c
mm/memfd.c