cpumask_local_spread(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… cpumask_local_spread(9) β€” a Kernel API Manual moment

okay so bestie, welcome to the Kernel API Manual πŸ’– this one's called cpumask_local_spread and it's genuinely iconic once u get it, i promise.


✨ NAME ✨

cpumask_local_spread β€” pick the i'th cpu based on NUMA distances πŸ—ΊοΈ


🌸 SYNOPSIS 🌸

unsigned int cpumask_local_spread (unsigned int i , int node );

πŸŽ€ ARGUMENTS πŸŽ€

  • i β€” the index number, like which one u want in the lineup πŸ’…
  • node β€” the local numa_node, aka ur home base 🏠

πŸ¦‹ RETURN πŸ¦‹

returns an online CPU according to a numa aware policy β€” and the order is the whole vibe, bestie:

  1. local cpus come back first πŸ₯‡
  2. then the non-local ones 🚢
  3. then it wraps around πŸ”

πŸ”₯ DESCRIPTION πŸ”₯

so if ur the kind of person who wants to enumerate all the CPUs based on their NUMA distances β€” i.e. u wanna call this function in a loop β€” it looks like this:

for (i = 0; i < num_online_cpus; i++) {
    cpu = cpumask_local_spread(i, node);
    do_something(cpu);
}

but bestie, there's a better alternative based on for_each-like iterators:

for_each_numa_hop_mask(mask, node) {
    for_each_cpu_andnot(cpu, mask, prev)
        do_something(cpu);
    prev = mask;
}

the docs say it's simpler and more verbose than the above (yes, that's literally what it says πŸ’€ just relaying the message fr fr).

as for complexity, ngl this is the part u screenshot:

  • iterator-based enumeration is O(sched_domains_numa_levels * nr_cpu_ids) πŸ‘‘
  • cpumask_local_spread when called for each cpu is O(sched_domains_numa_levels * nr_cpu_ids * log(nr_cpu_ids)) 😭
so like... the iterator version is the one ur actually gonna want. take the hint, periodt.

πŸ’œ SEE ALSO πŸ’œ

go read those next, iykwim 🫢


and that's the page!! 🧚 this little masterpiece lives in ./lib, dated October 2026, and it's filed under cpumask_local_spread(9). mwah πŸ’‹ slay, bye! πŸ’–βœ¨

πŸ“¦ where this page comes from