Re: [PATCH 00/11] nodemask: switch to runtime nr_node_ids
From: Yury Norov
Date: Tue Dec 01 2026 - 19:35:36 EST
On Mon, Nov 30, 2026 at 11:18:11AM -0800, Joshua Hahn wrote:
> On Mon, Nov 30, 2026 at 08:48:24AM -0800, Joshua Hahn wrote:
> > On Fri, Nov 27, 2026 at 06:01:17PM -0500, Yury Norov wrote:
> > > Nodemasks have a compile-time capacity of MAX_NUMNODES, and
> > > nr_node_ids describes the runtime node ID usage.
> > >
> > > Modern distros, like my Ubuntu, default MAX_NUMNODES to 1024, while the
> > > actual number of nodes is typically smaller. All nodemask functions
> > > currently refer to the MAX_NUMNODES, which adds a substantial overhead
> > > on every traversing operation.
> > >
> > > This series switches the kernel to runtime length of nodemasks, which
> > > also saves up to 8K of .text for minimal config, and accelerates basic
> > > nodemask operations ~4x if MAX_NUMNODES == 1024 and nr_node_ids == 2.
> >
> > Hi Yury,
> >
> > Thanks for the series. I think it looks good and a 4x speedup on the
> > nodemask operations is pretty awesome. I had a question that was a bit
> > orthogonal to this series, I wanted your opinion on right-sizing
> > MAX_NUMNODES.
> >
> > Something that's been bugging me is how much memory is wasted by
> > statically allocating MAX_NUMNODES sized arrays, e.g:
> >
> > - mm/page_alloc.c: node_load[MAX_NUMNODES]
> > - mm/mempolicy.c: preferred_node_policy[MAX_NUMNODES]
> > - mm/hugetlb_cma.c: hugetlb_cma[MAX_NUMNODES]
> > hugetlb_cma_size_in_node[MAX_NUMNODES]
> > hugetlb_cma_percent_in_node[MAX_NUMNODES]
> > ... etc ...
> >
> > In addition to the script to build the configs to match the local
> > configs... I was wondering if you've thought about this side of the
> > problem too. To be honest I'm not sure if there is much we can do, but
> > I thought I would just bring it up : -)
>
> On reflecting on this over lunch...
>
> I did a quick check and it turns out that the static overhead associated
> with wastage coming from MAX_NUMNODES >> nr_node_ids isn't really that
> big. I do believe the real cost comes in the nodemask iterations, which
> you handle here.
That's ~8K of compile time and 4M of runtime overhead for me. Compare
it to your L1/2 i- and d-cache sizes to estimate if it's big enough for
you.
Check my reply to Andrew for more numbers:
https://lore.kernel.org/all/aw8XThqaTZg_yJWR@yury/