selftests/bpf: Remove duplicate copies of the arena spinlock qnodes

bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
every translation unit including it emits a copy. __weak makes them all
resolve to one instance, but bpftool gen object merges only the symbols
and concatenates each input's .addr_space.1 bytes, leaving the surplus
copies unreferenced in the linked object.

libarena links ten such units, so nine copies were dead weight (bytes):

  object                             before       after
  -----------------------------------------------------
  .addr_space.1 in libarena.bpf.o    676200       86376
  libarena.skel.h                   2100123      892371
  libarena_asan.skel.h              2641124     1466477

Declare qnodes in the header and let each program define it once:
libarena in src/common.bpf.c, and the arena_spin_lock test beside the
lock it guards.

Tested with test_progs -t arena_spin_lock and -t libarena.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/bpf/20260817160249.655916-1-changwoo@igalia.com
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
Changwoo Min 2026-08-18 01:02:49 +09:00 committed by Kumar Kartikeya Dwivedi
parent 3d9393ff98
commit 9d19ca5d0e
No known key found for this signature in database
GPG Key ID: 472D377B63542F83
3 changed files with 15 additions and 6 deletions

View File

@ -103,12 +103,7 @@ struct arena_qnode {
#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
/*
* The qnodes are marked __weak so we can define them in the header
* while still ensuring all compilation units use the same struct
* instance.
*/
struct arena_qnode __weak __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
extern struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
static inline u32 encode_tail(int cpu, int idx)
{

View File

@ -7,6 +7,13 @@
struct buddy __arena buddy;
volatile u32 zero = 0;
/*
* Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
* linking the arena spinlock provides exactly one definition, so that the array
* is emitted once rather than once per translation unit.
*/
struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
int arena_fls(__u64 word)
{
if (!word)

View File

@ -23,6 +23,13 @@ int cs_count;
#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
arena_spinlock_t __arena lock;
int test_skip = 1;
/*
* Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
* linking the arena spinlock provides exactly one definition; libarena's lives
* in libarena/src/common.bpf.c.
*/
struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
#else
int test_skip = 2;
#endif