Re: [PATCH 1/2] mm/memfd: drop redundant hugetlb allocation mask narrowing
From: Hongfu Li
Date: Wed Nov 18 2026 - 21:40:22 EST
在 11/18/26 19:47, Muchun Song 写道:
On Nov 17, 2026, at 18:53, Hongfu Li <hongfu.li@xxxxxxxxx> wrote:You didn't mention why __GFP_HIGHMEM can be removed safely. I have to
From: Hongfu Li <lihongfu@xxxxxxxxxx>
memfd_alloc_folio() derives its allocation mask from htlb_alloc_mask()
and then clears __GFP_HIGHMEM and __GFP_MOVABLE. This mask handling was
introduced by commit 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios()
for pinning memfd folios"), when the fallback path in
alloc_hugetlb_folio_nodemask() could still call
alloc_migrate_hugetlb_folio() and reach the buddy allocator, so the mask
decided the zone and migratetype of freshly allocated pages.
Since commit 26a8ea80929c ("mm/hugetlb: fix memfd_pin_folios
resv_huge_pages leak"), this call site uses alloc_hugetlb_folio_reserve(),
which only dequeues folios from the existing hugetlb pool and never falls
back to the buddy allocator. The mask therefore no longer decides where
any page comes from.
Long-term pinning safety no longer depends on the mask either:
memfd_pin_folios() obtains its folios (dequeued from the pool, or freshly
allocated) under memalloc_pin_save(), so PF_MEMALLOC_PIN makes
dequeue_hugetlb_folio_node_exact() skip any folio that fails
folio_is_longterm_pinnable(), and current_gfp_context() already clears
__GFP_MOVABLE from any page allocator request made under PF_MEMALLOC_PIN.
Drop the narrowing, which has had no effect since 26a8ea80929c.
Signed-off-by: Hongfu Li <lihongfu@xxxxxxxxxx>
---
mm/memfd.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/memfd.c b/mm/memfd.c
index 0e3ff3eebfa8..8905e3e9efc8 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -85,7 +85,6 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
u32 hash;
gfp_mask = htlb_alloc_mask(h);
- gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
investigate the reason myself.
During review, __GFP_HIGHMEM was cleared because "these pages might need
to be accessible by some DMA driver, so you have HIGHMEM constraints.",
refer to https://lore.kernel.org/all/ZmvNLSUgUgFETR0M@localhost.localdomain/
I think that restriction is unnecessary now: DMA and existing memfd_pin_folios()
users operate on pages or scatterlists and support highmem, while the
shmem path already permits highmem folios. The hugetlb path therefore
does not need a separate lowmem constraint.
Hi Muchun,
Thanks a lot for the review, and for tracking down the __GFP_HIGHMEM
history yourself; the explanation is very clear and much appreciated.
I was not fully sure about that part, which is why the commit message did
not describe it much. I'll add the following to the commit message in v2:
Clearing __GFP_HIGHMEM was a lowmem constraint for these folios, which
were meant to be accessed by a DMA driver. It is not required any more:
the users of memfd_pin_folios() work on pages and scatterlists, which
support highmem, as does the shmem path with its default
GFP_HIGHUSER_MOVABLE mask.
Because you have removed the constrains, why you didn't remove the comment
along the way?
/*
* The folio would most likely be accessed by a DMA driver,
* therefore, we have zone memory constraints where we can
* alloc from. Also, the folio will be pinned for an indefinite
* amount of time, so it is not expected to be migrated away.
*/
You are right, that comment describes the zone constraints that patch 1
removes, so it is stale once the constraints are gone. I removed it in
patch 2, together with the mask computation. Will do that in v2: move the
removal into patch 1 and drop patch 2.
--idx >>= huge_page_order(h);
/*
--
2.54.0
Best regards,
Hongfu