mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hongfu Li <hongfu.li@linux.dev>
To: Hugh Dickins <hughd@google.com>,
	David Hildenbrand <david@kernel.org>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	 Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>
Cc: hongfu.li@linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,  Hongfu Li <lihongfu@kylinos.cn>
Subject: [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()
Date: Tue, 17 Nov 2026 18:53:12 +0800	[thread overview]
Message-ID: <20261117-for-memfd-v1-2-fa68f433171e@kylinos.cn> (raw)
In-Reply-To: <20261117-for-memfd-v1-0-fa68f433171e@kylinos.cn>

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


  parent reply	other threads:[~2026-11-17 10:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-17 11:15   ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Muchun Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117-for-memfd-v1-2-fa68f433171e@kylinos.cn \
    --to=hongfu.li@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=lihongfu@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®