Re: [PATCH 13/22] mm/hugetlb: restrict pool growth to common memory
From: Gregory Price (Meta)
Date: Wed Nov 18 2026 - 10:25:53 EST
On 2026-11-18 15:32 +0800, Richard Cheng wrote:
> > @@ -3802,23 +3801,21 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
> > unsigned long allocated;
> > struct folio *folio;
> > LIST_HEAD(page_list);
> > - NODEMASK_ALLOC(nodemask_t, node_alloc_noretry, GFP_KERNEL);
> > + NODEMASK_ALLOC(struct nodemask_scratch, scratch, GFP_KERNEL);
> >
> > - /*
> > - * Bit mask controlling how hard we retry per-node allocations.
> > - * If we can not allocate the bit mask, do not attempt to allocate
> > - * the requested huge pages.
> > - */
> > - if (node_alloc_noretry)
> > - nodes_clear(*node_alloc_noretry);
> > - else
> > + /* Scratch masks for allocation eligibility and per-node retries. */
> > + if (!scratch)
> > return -ENOMEM;
> > + nodes_clear(scratch->mask2);
> >
> > /*
> > * resize_lock mutex prevents concurrent adjustments to number of
> > * pages in hstate via the proc/sysfs interfaces.
> > */
> > mutex_lock(&h->resize_lock);
> > +
> > + /* Fresh pool pages come from the ordinary allocation domain. */
> > + nodes_and(scratch->mask1, *nodes_allowed, node_states[N_MEMORY_COMMON]);
>
> For a global request the caller passes &node_states[N_MEMORY], so before this patch
> the grow loop read the live mask on every alloc_pool_huge_folio().
> Now the mask is sampled once, before the loop.
>
> The loop drops hugetlb_lock and can run for a long time. If a node gets its first
> memoroy in that window, the old code would start using it. The new code won't, until
> the next write to nr_hugepages.
>
> So the pool can end up uneven, or smaller than requested if the other nodes are full.
>
> I think the nodes_and() should be placed inside the loop to keep the old behavior ?
I can make the adjustment, but the concern is that previously we'd
start spreading the distribution of hugepages differently when there's a
race between hugetlb allocation and memory hotplug?
That seems like a pretty innocuous corner case to be worried about.
I can see about retaining the old behavior, but i'm not sure what you're
describing is reliable behavior already.
--
~Gregory