Re: [PATCH 2/2] mm/hugetlb: remove the gfp_mask argument from alloc_hugetlb_folio_reserve()
From: Muchun Song
Date: Tue Nov 17 2026 - 06:15:36 EST
> On Nov 17, 2026, at 18:53, Hongfu Li <hongfu.li@xxxxxxxxx> wrote:
>
> From: Hongfu Li <lihongfu@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> ---
> 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
>