Re: [PATCH 00/11] nodemask: switch to runtime nr_node_ids
From: Yury Norov
Date: Wed Dec 02 2026 - 17:02:47 EST
On Wed, Dec 02, 2026 at 08:50:25PM +0000, Lorenzo Stoakes (ARM) wrote:
> Yuri - you may have missed the below because it was sent as a follow up to
> original feedback, thanks.
I tried to answer this and some other questions, and summarized it in the
html here:
https://lore.kernel.org/all/aw8XThqaTZg_yJWR@yury/
I'll walk through your questions inplace.
Thanks,
Yury
> On Mon, Nov 30, 2026 at 12:20:00PM +0000, Lorenzo Stoakes (ARM) wrote:
> > On Mon, Nov 30, 2026 at 11:51:02AM +0000, Lorenzo Stoakes (ARM) 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.
> >
> > Also, in general, this cover letter is pretty incomplete.
> >
> > What is the motivation here? Is it purely cleanup?
Cleanup, performance and consistency considerations - all are on the
table.
> I mean I don't think
> > anybody's hitting perf hot paths because of this? Or did you encounter something
> > in a real workload that was impacted somehow?
It's 4x faster in microbenchmark, and 5% faster in set_mempolicy(MPOL_BIND)
test.
> > 8K of .text being saved is also surely neither here nor there also?
It's 8K of kernel image, which means L1 cache memory almost
automatically. To me it's definitely 'here'.
> > I think if
> > it's a cleanup it should say so because 'saves 8K and speeds up operations
> > nobody cares about' isn't hugely motivating.
I'm OK if you consider it as a cleanup because it's a nice cleanup
after all. Some other people, including me, find the performance and
memory improvements significant.
'Nobody cares' is not a strong argument, can't address it.
> > What are the user-visible changes?
I tested the performance of the obvious target: set_mempolicy(MPOL_BIND),
and it's 5% faster. LMK if you have other tests in mind
The other user-visible change is on the ABI side. It was discussed in
the other subthread, here's the summary:
Consider a machine with MAX_NUMNODES == 1K and NR_CPUS == 8K. The
actual number of CPUs and nodes is 2.
Then when you pass cpulist "0-3:1/4" to the kernel, it will correctly
reject it because it refers non-possible CPUs. When you pass the same
as nodelist, the kernel would accept the request because it checks user
input against (quite random) MAX_NUMNODES, not nr_node_ids.
The worst part is that if you decide to trim MAX_NUMNODES to the
actual number of possible nodes on your machine, you'll have the same
nodelist rejected after reboot.
> > Is MAX_NUMNODES retained and used for something else? How do the configs change?
In kernel it's only used for nodemasks. Kernel config is unchanged.
It's not exposed to user via kernel headers, only with NODES_SHIFT
config. User can also check Mems_allowed in /proc/<pid>/status to
calculate the possible nodes.
Before c4f392a35c4f39ebb2c ("nodemask: reduce bitmap width to nr_node_ids
in __nodemask_pr_numnodes()") it printed the nodemask based on
MAX_NUMNODES. Now it's switched to nr_node_ids.
> > What testing did you do? I do worry about somebody somewhere making assumptions
> > about MAX_NR_NODES that this potentially breaks.
Check this for testing:
https://lore.kernel.org/all/aw8XThqaTZg_yJWR@yury/
I ran my AI against all popular distros and apps to check if they
refer MAX_NUMNODES, CONFIG_NODES_SHIFT or check /proc for
Mems_allowed.
Some container (Kubernetes IIRC) refers Mems_allowed, but it's already
switched, and nobody complained. Some apps have wrappers around cpuset
interface etc., but nobody explicitly makes requests based on
MAX_NUMNODES.
> > Also can hot-onlining CPUs or weird CXL stuff break anything here? Do the locks
> > suffice etc.?
nr_node_ids is set at system boot. Neither hotplug nor CXL can't
change it.
> > Asking claude to dig in it seems like it doesn't touch anything like that, also
> > probably worth saying that in the cover letter too.
Codex agreed.