Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/memfd: drop stale hugetlb allocation mask handling
@ 2026-11-17 10:53 Hongfu Li
  2026-11-17 10:53 ` [PATCH 1/2] mm/memfd: drop redundant hugetlb allocation mask narrowing Hongfu Li
  2026-11-17 10:53 ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Hongfu Li
  0 siblings, 2 replies; 4+ messages in thread
From: Hongfu Li @ 2026-11-17 10:53 UTC (permalink / raw)
  To: Hugh Dickins, David Hildenbrand, Baolin Wang, Andrew Morton,
	Muchun Song, Oscar Salvador
  Cc: hongfu.li, linux-mm, linux-kernel, Hongfu Li

The hugetlb allocation mask computed in memfd_alloc_folio() no longer has
an effect. The call site only dequeues folios from the hugetlb pool, so
the mask selects neither a zone nor a migratetype any more. Remove it,
along with the gfp_mask argument it feeds into
alloc_hugetlb_folio_reserve().

Patch 1 drops the redundant narrowing. Patch 2 drops the gfp_mask
argument of alloc_hugetlb_folio_reserve(), whose only caller passes
exactly htlb_alloc_mask(h), and derives that mask inside the helper
instead.

---
Hongfu Li (2):
      mm/memfd: drop redundant hugetlb allocation mask narrowing
      mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()

 include/linux/hugetlb.h |  4 ++--
 mm/hugetlb.c            |  3 ++-
 mm/memfd.c              | 14 +-------------
 3 files changed, 5 insertions(+), 16 deletions(-)
---
base-commit: 0bce4c3c7589a80b09a4f21fcb41811cca5153a1
change-id: 20261117-for-memfd-e11675edfe65

Best regards,
--  
Hongfu Li <lihongfu@kylinos.cn>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] mm/memfd: drop redundant hugetlb allocation mask narrowing
  2026-11-17 10:53 [PATCH 0/2] mm/memfd: drop stale hugetlb allocation mask handling Hongfu Li
@ 2026-11-17 10:53 ` Hongfu Li
  2026-11-17 10:53 ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Hongfu Li
  1 sibling, 0 replies; 4+ messages in thread
From: Hongfu Li @ 2026-11-17 10:53 UTC (permalink / raw)
  To: Hugh Dickins, David Hildenbrand, Baolin Wang, Andrew Morton,
	Muchun Song, Oscar Salvador
  Cc: hongfu.li, linux-mm, linux-kernel, Hongfu Li

From: Hongfu Li <lihongfu@kylinos.cn>

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@kylinos.cn>
---
 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);
 		idx >>= huge_page_order(h);
 
 		/*

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()
  2026-11-17 10:53 [PATCH 0/2] mm/memfd: drop stale hugetlb allocation mask handling Hongfu Li
  2026-11-17 10:53 ` [PATCH 1/2] mm/memfd: drop redundant hugetlb allocation mask narrowing Hongfu Li
@ 2026-11-17 10:53 ` Hongfu Li
  2026-11-17 11:15   ` Muchun Song
  1 sibling, 1 reply; 4+ messages in thread
From: Hongfu Li @ 2026-11-17 10:53 UTC (permalink / raw)
  To: Hugh Dickins, David Hildenbrand, Baolin Wang, Andrew Morton,
	Muchun Song, Oscar Salvador
  Cc: hongfu.li, linux-mm, linux-kernel, Hongfu Li

From: Hongfu Li <lihongfu@kylinos.cn>

alloc_hugetlb_folio_reserve() takes a gfp_mask argument that
memfd_alloc_folio() always sets to exactly htlb_alloc_mask(h), which the
helper can derive by itself.

Derive the mask inside alloc_hugetlb_folio_reserve() as
alloc_hugetlb_folio() does, and drop the argument.

No functional change intended.

Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
 include/linux/hugetlb.h |  4 ++--
 mm/hugetlb.c            |  3 ++-
 mm/memfd.c              | 13 +------------
 3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 69732e4cc03e..a88c59476e79 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -735,7 +735,7 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid,
 				nodemask_t *nmask, gfp_t gfp_mask,
 				bool allow_alloc_fallback);
 struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
-					  nodemask_t *nmask, gfp_t gfp_mask);
+					  nodemask_t *nmask);
 
 int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *mapping,
 			pgoff_t idx);
@@ -1161,7 +1161,7 @@ static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
 
 static inline struct folio *
 alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
-			    nodemask_t *nmask, gfp_t gfp_mask)
+			    nodemask_t *nmask)
 {
 	return NULL;
 }
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 88c9aa700533..e84203406da3 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2221,8 +2221,9 @@ struct folio *alloc_buddy_hugetlb_folio(struct hstate *h,
 }
 
 struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
-		nodemask_t *nmask, gfp_t gfp_mask)
+		nodemask_t *nmask)
 {
+	gfp_t gfp_mask = htlb_alloc_mask(h);
 	struct hugetlb_cgroup *h_cg = NULL;
 	size_t nr_pages = pages_per_huge_page(h);
 	struct folio *folio;
diff --git a/mm/memfd.c b/mm/memfd.c
index 8905e3e9efc8..08b9d54b0d8a 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -69,22 +69,14 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
 {
 #ifdef CONFIG_HUGETLB_PAGE
 	struct folio *folio;
-	gfp_t gfp_mask;
 
 	if (is_file_hugepages(memfd)) {
-		/*
-		 * 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.
-		 */
 		struct inode *inode = file_inode(memfd);
 		struct hstate *h = hstate_file(memfd);
 		int err = -ENOMEM;
 		long nr_resv;
 		u32 hash;
 
-		gfp_mask = htlb_alloc_mask(h);
 		idx >>= huge_page_order(h);
 
 		/*
@@ -101,10 +93,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
 			goto out_unlock;
 		}
 
-		folio = alloc_hugetlb_folio_reserve(h,
-						    numa_node_id(),
-						    NULL,
-						    gfp_mask);
+		folio = alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL);
 		if (folio) {
 			/*
 			 * Zero the folio to prevent information leaks to userspace.

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()
  2026-11-17 10:53 ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Hongfu Li
@ 2026-11-17 11:15   ` Muchun Song
  0 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2026-11-17 11:15 UTC (permalink / raw)
  To: Hongfu Li
  Cc: Hugh Dickins, David Hildenbrand, Baolin Wang, Andrew Morton,
	Oscar Salvador, linux-mm, linux-kernel, Hongfu Li



> On Nov 17, 2026, at 18:53, Hongfu Li <hongfu.li@linux.dev> wrote:
> 
> From: Hongfu Li <lihongfu@kylinos.cn>
> 
> alloc_hugetlb_folio_reserve() takes a gfp_mask argument that
> memfd_alloc_folio() always sets to exactly htlb_alloc_mask(h), which the
> helper can derive by itself.
> 
> Derive the mask inside alloc_hugetlb_folio_reserve() as
> alloc_hugetlb_folio() does, and drop the argument.
> 
> No functional change intended.
> 
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
> ---
> include/linux/hugetlb.h |  4 ++--
> mm/hugetlb.c            |  3 ++-
> mm/memfd.c              | 13 +------------
> 3 files changed, 5 insertions(+), 15 deletions(-)
> 
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 69732e4cc03e..a88c59476e79 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -735,7 +735,7 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid,
> 				nodemask_t *nmask, gfp_t gfp_mask,
> 				bool allow_alloc_fallback);
> struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
> -					  nodemask_t *nmask, gfp_t gfp_mask);
> +					  nodemask_t *nmask);

To be honest, I'm not a fan of this change. This is a memory allocation
interface, and we shouldn't couple it with a fixed GFP mask. Sorry, I
can't ack.

Thanks,
Muchun

> 
> int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *mapping,
> 			pgoff_t idx);
> @@ -1161,7 +1161,7 @@ static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
> 
> static inline struct folio *
> alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
> -			    nodemask_t *nmask, gfp_t gfp_mask)
> +			    nodemask_t *nmask)
> {
> 	return NULL;
> }
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 88c9aa700533..e84203406da3 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2221,8 +2221,9 @@ struct folio *alloc_buddy_hugetlb_folio(struct hstate *h,
> }
> 
> struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid,
> -		nodemask_t *nmask, gfp_t gfp_mask)
> +		nodemask_t *nmask)
> {
> +	gfp_t gfp_mask = htlb_alloc_mask(h);
> 	struct hugetlb_cgroup *h_cg = NULL;
> 	size_t nr_pages = pages_per_huge_page(h);
> 	struct folio *folio;
> diff --git a/mm/memfd.c b/mm/memfd.c
> index 8905e3e9efc8..08b9d54b0d8a 100644
> --- a/mm/memfd.c
> +++ b/mm/memfd.c
> @@ -69,22 +69,14 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
> {
> #ifdef CONFIG_HUGETLB_PAGE
> 	struct folio *folio;
> -	gfp_t gfp_mask;
> 
> 	if (is_file_hugepages(memfd)) {
> -		/*
> -		 * 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.
> -		 */
> 		struct inode *inode = file_inode(memfd);
> 		struct hstate *h = hstate_file(memfd);
> 		int err = -ENOMEM;
> 		long nr_resv;
> 		u32 hash;
> 
> -		gfp_mask = htlb_alloc_mask(h);
> 		idx >>= huge_page_order(h);
> 
> 		/*
> @@ -101,10 +93,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
> 			goto out_unlock;
> 		}
> 
> -		folio = alloc_hugetlb_folio_reserve(h,
> -						    numa_node_id(),
> -						    NULL,
> -						    gfp_mask);
> +		folio = alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL);
> 		if (folio) {
> 			/*
> 			 * Zero the folio to prevent information leaks to userspace.
> 
> -- 
> 2.54.0
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 11:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 10:53 [PATCH 0/2] mm/memfd: drop stale hugetlb allocation mask handling Hongfu Li
2026-11-17 10:53 ` [PATCH 1/2] mm/memfd: drop redundant hugetlb allocation mask narrowing Hongfu Li
2026-11-17 10:53 ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Hongfu Li
2026-11-17 11:15   ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox