STRUCT BPF_CPUMASK(9)
π struct bpf_cpumask(9) β the refcounted BPF cpumask wrapper, bestie edition π
okay so real talk, this is struct bpf_cpumask(9) from the Kernel API Manual, and it's giving tiny struct, big responsibilities. Let me tell you everything, no cap.
β¨ NAME β¨
struct bpf_cpumask β a refcounted BPF cpumask wrapper structure. that's it, that's the vibe π«Ά
π SYNOPSIS π
struct bpf_cpumask {
cpumask_t cpumask;
refcount_t usage;
};
literally two fields, and yet she's iconic π
πΈ Members πΈ
cpumaskβ the actual cpumask embedded in the struct. she's the whole point, honestly πusageβ the object reference counter. the way this works: when the refcount goes to0, the memory is released back to the BPF allocator, which provides RCU safety. so like, when nobody's holding on anymore, she goes home π¦
π Description π
okay so here's the tea, and it's a whole design decision: we explicitly embed a cpumask_t rather than a cpumask_var_t. why? because the typedef of cpumask_var_t changes depending on whether CONFIG_CPUMASK_OFFSTACK is defined or not, and that would confuse the verifier. not the verifier getting confused π so it's done deliberately. check the details in <linux/cpumask.h> if you want the full lore, iykyk.
the consequence (and yes, there is a consequence, bestie): this structure is likely a bit larger than it needs to be when CONFIG_CPUMASK_OFFSTACK is defined, because it embeds the whole NR_CPUS-size bitmap. but ngl, the extra memory overhead is minimal. and for the more typical case of CONFIG_CPUMASK_OFFSTACK not being defined, the structure is the same size regardless. slay π
π₯ SEE ALSO π₯
start with the kernel file: ./kernel/bpf/cpumask.c, then the whole friend group:
bpf_cpumask_create(9)bpf_cpumask_acquire(9)bpf_cpumask_release(9)bpf_cpumask_first(9)bpf_cpumask_first_zero(9)bpf_cpumask_first_and(9)bpf_cpumask_set_cpu(9)bpf_cpumask_clear_cpu(9)bpf_cpumask_test_cpu(9)bpf_cpumask_test_and_set_cpu(9)bpf_cpumask_test_and_clear_cpu(9)bpf_cpumask_setall(9)bpf_cpumask_clear(9)bpf_cpumask_and(9)bpf_cpumask_or(9)bpf_cpumask_xor(9)bpf_cpumask_equal(9)bpf_cpumask_intersects(9)bpf_cpumask_subset(9)bpf_cpumask_empty(9)bpf_cpumask_full(9)bpf_cpumask_copy(9)bpf_cpumask_any_distribute(9)bpf_cpumask_any_and_distribute(9)bpf_cpumask_weight(9)bpf_cpumask_populate(9)
and that's the whole page, bestie!! this little fairy π§ came to you from ./kernel/bpf, dated October 2026, and yes she's still listed under struct bpf_cpumask(9) at the bottom like the main character she is πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms