Re: [PATCH v7 17/31] mm: hugetlb: add gfp parameter and skip zeroing for zeroed pages
From: Michael S. Tsirkin
Date: Tue May 12 2026 - 19:09:16 EST
On Tue, May 12, 2026 at 06:03:39PM -0400, Gregory Price wrote:
> On Tue, May 12, 2026 at 05:06:37PM -0400, Michael S. Tsirkin wrote:
> > Add a gfp_t parameter to alloc_hugetlb_folio(). When __GFP_ZERO
> > is set, the function guarantees the returned folio is zeroed:
> > - Fresh allocations (buddy or gigantic): zeroed by
> > post_alloc_hook via __GFP_ZERO.
> > - Pool pages with HPG_zeroed set: already zeroed, skip.
> > - Pool pages without HPG_zeroed: zeroed via folio_zero_user().
> >
> > The address parameter is renamed to user_addr; the function
> > aligns it internally for reservation and NUMA policy lookups.
> > For pool pages that need zeroing, user_addr is passed to
> > folio_zero_user() for cache-friendly zeroing near the faulting
> > subpage. All callers pass a page-aligned address; the
> > hugetlb_no_page caller passes vmf->real_address & PAGE_MASK
> > for consistency.
> >
> > HPG_zeroed (stored in hugetlb folio->private bits) tracks
> > known-zero pool pages. It is set when alloc_surplus_hugetlb_folio
> > allocates with __GFP_ZERO, and cleared in free_huge_folio when
> > the page returns to the pool after userspace use.
> >
> > Suggested-by: Gregory Price <gourry@xxxxxxxxxx>
> > Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
> > Assisted-by: Claude:claude-opus-4-6
> > Assisted-by: cursor-agent:GPT-5.4-xhigh
> > ---
> > fs/hugetlbfs/inode.c | 3 +--
> > include/linux/hugetlb.h | 5 ++++-
> > mm/hugetlb.c | 47 ++++++++++++++++++++++++++++++-----------
> > 3 files changed, 40 insertions(+), 15 deletions(-)
> >
>
> This seems much much cleaner this way. One nit, doesn't need a respin
> unless you feel like it.
>
> Reviewed-by: Gregory Price <gourry@xxxxxxxxxx>
>
>
> > @@ -2980,6 +2993,11 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
> >
> > spin_unlock_irq(&hugetlb_lock);
> >
> > + if ((gfp & __GFP_ZERO) && from_pool &&
> > + !folio_test_hugetlb_zeroed(folio))
>
> stupid question:
>
> if (!from_pool) - wouldn't folio_test_hugetlb_zeroed(folio) be true
> because __GFP_ZERO is passed?
>
> If not, SHOULD it be true (i.e. should we be setting that in the
> non-pool allocation path when __GFP_ZERO is passed and allocation
> succeeds?)
>
> If so, can this just be simplified to:
>
> if ((gfp & __GFP_ZERO) && !folio_test_hugetlb_zeroed(folio))
>
> Maybe that lets you eliminate the bool entirely?
>
> ~Gregory
Agreed. I will include this if I need to respin.
--
MST