[PATCH bpf-next v2 0/4] bpf: Add memory usage for arena and selftest

From: Jiayuan Chen

Date: Fri Jul 17 2026 - 07:44:52 EST


arena is the only map type whose map_mem_usage() still returns 0, so
bpftool and fdinfo always show 0 memlock for it no matter how many pages
it holds. This series adds the accounting, runs the arena selftests
serially so they don't OOM a small CI VM, and adds a test for it.

v1 -> v2:
- split the scratch_page -> arena refactor into a prep patch (no
functional change)
- use WRITE_ONCE() for nr_pages to pair with the lockless reader
- reword the "run serially" commit message
- selftest: alloc prog returns 0 so the failure check is reached

v1: https://lore.kernel.org/bpf/20260716142746.8794-1-jiayuan.chen@xxxxxxxxx/

Jiayuan Chen (4):
bpf: Pass arena instead of scratch_page to the pte callbacks
bpf: Add memory usage for arena
selftests/bpf: Run arena tests serially
selftests/bpf: Add tests for memory usage for arena

kernel/bpf/arena.c | 27 ++--
.../selftests/bpf/prog_tests/arena_atomics.c | 2 +-
.../bpf/prog_tests/arena_direct_value.c | 2 +-
.../selftests/bpf/prog_tests/arena_htab.c | 2 +-
.../selftests/bpf/prog_tests/arena_list.c | 2 +-
.../bpf/prog_tests/arena_mem_usage.c | 122 ++++++++++++++++++
.../bpf/prog_tests/arena_spin_lock.c | 2 +-
.../bpf/prog_tests/arena_strsearch.c | 2 +-
.../selftests/bpf/prog_tests/libarena.c | 2 +-
.../selftests/bpf/prog_tests/libarena_asan.c | 2 +-
.../selftests/bpf/progs/arena_mem_usage.c | 40 ++++++
11 files changed, 186 insertions(+), 19 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_mem_usage.c
create mode 100644 tools/testing/selftests/bpf/progs/arena_mem_usage.c

--
2.43.0