On Mon, May 11, 2026 at 12:36:59PM -0400, Gregory Price wrote: > On Mon, May 11, 2026 at 05:03:02AM -0400, Michael S. Tsirkin wrote: > > Convert the hugetlb fault and fallocate paths to use __GFP_ZERO. > > For pages allocated from the buddy allocator, post_alloc_hook() > > handles zeroing. > > > > Hugetlb surplus pages need special handling because they can be > > pre-allocated into the pool during mmap (by hugetlb_acct_memory) > > before any page fault. Pool pages are kept around and may need > > zeroing long after buddy allocation, so a buddy-level zeroed > > hint (consumed at allocation time) cannot track their state. > > > > Add a bool *zeroed output parameter to alloc_hugetlb_folio() > > so callers know whether the page needs zeroing. Buddy-allocated > > pages are always zeroed (zeroed by post_alloc_hook). Pool > > pages use a new HPG_zeroed flag to track whether the page is > > known-zero (freshly buddy-allocated, never mapped to userspace). > > The flag is set in alloc_surplus_hugetlb_folio() after buddy > > allocation and cleared in free_huge_folio() when a user-mapped > > page returns to the pool. > > > > Callers that do not need zeroing (CoW, migration) pass NULL for > > zeroed and 0 for gfp. > > > > Signed-off-by: Michael S. Tsirkin <[email protected]> > > Assisted-by: Claude:claude-opus-4-6 > > Assisted-by: cursor-agent:GPT-5.4-xhigh > > --- > > fs/hugetlbfs/inode.c | 10 ++++++-- > > include/linux/hugetlb.h | 8 +++++-- > > mm/hugetlb.c | 52 ++++++++++++++++++++++++++++++----------- > > 3 files changed, 53 insertions(+), 17 deletions(-) > > > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > > index 8b05bec08e04..24e42cb10ade 100644 > > --- a/fs/hugetlbfs/inode.c > > +++ b/fs/hugetlbfs/inode.c > > @@ -810,14 +810,20 @@ static long hugetlbfs_fallocate(struct file *file, > > int mode, loff_t offset, > > * folios in these areas, we need to consume the reserves > > * to keep reservation accounting consistent. > > */ > > - folio = alloc_hugetlb_folio(&pseudo_vma, addr, false); > > + { > > + bool zeroed; > > + > > + folio = alloc_hugetlb_folio(&pseudo_vma, addr, false, > > + __GFP_ZERO, &zeroed); > > This feels like a very odd pattern: > > 1) ask for __GFP_ZERO > 2) Have to check whether it was actually zeroed > > Seems like the zeroing piece should just be sunk in if you're going to > ask for __GFP_ZERO anyway. And in that case, maybe just `bool zero` as > an argument, rather than GFP (to avoid future overloading of flags). > > ~Gregory
Heh. The reason is that it either allocates from buddy - using gfp flags or from the pool, in which case it zeroes. We could even avoid the bool - just test __GFP_ZERO inside alloc_hugetlb_folio. Would that be better? -- MST

