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 v2] mm/memfd: drop redundant hugetlb allocation mask narrowing
Date: Thu, 19 Nov 2026 17:49:45 +0800	[thread overview]
Message-ID: <20261119-for-memfd-v2-1-59f2d8c9752d@kylinos.cn> (raw)

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.

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.

Drop the narrowing, which has had no effect since 26a8ea80929c.

Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
Changes in v2:
- Drop patch 2.
- Remove the now stale comment about the zone and migration constraints
  in patch 1.
- Update the commit message to explain why __GFP_HIGHMEM can be removed
  in patch 1.
- Link to v1: https://patch.msgid.link/20261117-for-memfd-v1-0-fa68f433171e@kylinos.cn
---
 mm/memfd.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/mm/memfd.c b/mm/memfd.c
index 0e3ff3eebfa8..4c359d0fa923 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -72,12 +72,6 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
 	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;
@@ -85,7 +79,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);
 
 		/*

---
base-commit: 0bce4c3c7589a80b09a4f21fcb41811cca5153a1
change-id: 20261117-for-memfd-e11675edfe65

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


             reply	other threads:[~2026-11-19  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:49 Hongfu Li [this message]
2026-11-19 13:34 ` Muchun Song
2026-11-19 14:06 ` Oscar Salvador (SUSE)
2026-11-19 16:47 ` David Hildenbrand (Arm)
2026-11-19 16:49 ` David Hildenbrand

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=20261119-for-memfd-v2-1-59f2d8c9752d@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®