Re: [PATCH bpf-next 00/16] Add percpu variable support for bpf arena

From: Alexei Starovoitov

Date: Wed Oct 21 2026 - 13:01:49 EST


On Wed, Oct 21, 2026 at 06:53 AM Xu Kuohai <xukuohai@xxxxxxxxxxxxxxx> wrote:
> 1. The table wastes a pointer (8 bytes) for each non-exist CPUs, as the
> global data is populated at load time by libbpf. On my debian machine,
> the CONFIG_NR_CPUS is 8192, while the machine has just a dozen CPUs, so
> the 64 KB bytes per variable are almost all wasted. An alternative way
> is to allocate the pointers at load time.

Right. It shouldn't be per variable.
'type' can be a struct with all percpu variables of the prog. Then it's
one table per prog, like the kernel has a single
__per_cpu_offset[NR_CPUS].
Allocating the table from the prog at init works too. nr_cpu_ids can
come from user space via rodata.

> 2. For small variables, the page rounding is a big cost as this series. A
> better way is to make percpu copies on the same NUMA node share the same
> page.

With the struct it's one page per cpu for all variables.
I think it's better to share a page between variables of one cpu than
between cpus. Copies of different cpus in one page need cache line
padding to avoid false sharing. The kernel percpu units are page
aligned too.