All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongfu Li <hongfu.li@linux.dev>
To: Muchun Song <muchun.song@linux.dev>
Cc: hongfu.li@linux.dev, Hugh Dickins <hughd@google.com>,
	David Hildenbrand <david@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Oscar Salvador <osalvador@suse.de>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Hongfu Li <lihongfu@kylinos.cn>
Subject: Re: [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()
Date: Wed, 18 Nov 2026 09:48:14 +0800	[thread overview]
Message-ID: <54e548ad-9641-4348-819a-11f29cc35ff4@linux.dev> (raw)
In-Reply-To: <DF9FCBFB-C1E3-497F-B7AB-567F44873B05@linux.dev>


在 11/17/26 19:15, Muchun Song 写道:
>
>> 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.

Hi Muchun,

Thanks for the review. Understood, I'll drop the interface change and keep
the gfp_mask argument in alloc_hugetlb_folio_reserve().

Also, patch 1 is the part I'm least confident about. Your comments on
it would be much appreciated when you have time.

>> 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
>>
-- 
Best regards,
Hongfu



      reply	other threads:[~2026-11-18  1:48 UTC|newest]

Thread overview: 5+ 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 ` [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve() Hongfu Li
2026-11-17 11:15   ` Muchun Song
2026-11-18  1:48     ` Hongfu Li [this message]

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=54e548ad-9641-4348-819a-11f29cc35ff4@linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.