Re: [PATCH 11/11] nodemask: add cpumask-style operation size bounds

From: Yury Norov

Date: Tue Dec 01 2026 - 19:01:53 EST


On Mon, Nov 30, 2026 at 02:59:37PM -0500, Gregory Price (Meta) wrote:
> On 2026-11-27 18:01 -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 Ubuntu default MAX_NUMNODES to 1024, while the
> > actual number of nodes is typically smaller. All nodemask operations
> > currently refer to the MAX_NUMNODES, which adds a substantial overhead
> > on every traversing operation.
> >
> > Simple switch to the runtime nr_node_ids might hurt users configuring
> > their MAX_NUMNODES to reasonable small values because the runtime value
> > breaks compile-time optimizations in the underlying bitmap API.
> >
> > Thus, switch to using small_nodemask_bits, large_nodemask_bits, or
> > the precise nr_node_ids, as appropriate.
> >
> > Bloat-o-meter reports 1-8KB decrease of .text, depending on NR_CPUS
> > and MAX_NUMNODES. With nr_node_ids == 2 and MAX_NUMNODES == 1024, basic
> > operations like nodes_copy() are ~4x faster
> >
> > Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
>
> This breaks cpuset.mems :
>
> 2 node host - {0,1}
>
> echo 0-3:1/4 > cpuset.mems
> before: succeeds - result: {0}
> now: ERANGE

Here user explicitly refers non-existing nodes 2 and 3. So, as for the
patch #3, it's unclear, do we erroneously accept the invalid input?

Any example with explicit boundaries is vulnerable. The above 0-3:1/4
would work fine for 2-node machine with MAX_NUMNODES == 1024. But if I
will recompile my kernel with MAX_NUMNODES == 2, it will return ERANGE.
It already happens on master, and nobody complains.

> echo 0-1:1/_ > cpuset.mems
> before: succeeds - result: {0}
> now: {0,1}

Did you mean 0-1:1/N?

I'm one of those who invented that N notation, and I'm pretty
confident that "2 nodes and 0-1:1/N" simply means all node".

> i think nodelist_parse probably still needs to use MAX_NUMNODES or the
> cpuset code needs a change as well.

The current state of things is simply inconsistent. Cpumasks use the
runtime nr_cpu_ids, which totally make sense to me, but nodemasks use
some random number from distro config, absolutely non-relevant to your
particular machine. It's not even exported to user, but we rely on it
to check for requests correctness

> But this also has me concerned there are other non-obvious, silent
> changes this patch produces.

I asked AI to find an example of using N in the group part of nodelist
description, and it found nothing deployed. I asked to check all distros
and major apps that would immediately observe this switch to runtime
nr_node_ids, and it found nothing again.

Are you aware of any specific example? If not, I think we're safe to
switch to nr_node_ids for good.

Thanks,
Yury

PS: Please check c4f392a35c4f39ebb2c ("nodemask: reduce bitmap width
to nr_node_ids in __nodemask_pr_numnodes()"). It changed the ABI, and
didn't break anything so far.