From: Xu Kuohai Place the percpu chunks in the bpf arena, alongside the global arena data. When full-range ldimm64 offset is supported, the global data sits at the end of the arena, place the percpu chunks right before it: +------------+---------+---------+----+---------+--------+ | | percpu | percpu |... | percpu | global | | | chunk 0 | chunk 1 | | chunk N | data | +------------+---------+---------+----+---------+--------+ Otherwise, the global data region sits at the beginning, place the percpu chunks right after it: +---------+---------+---------+----+---------+------------+ | global | percpu | percpu |... | percpu | | | data | chunk 0 | chunk 1 | | chunk N | | +---------+---------+---------+----+---------+------------+ Signed-off-by: Xu Kuohai --- tools/lib/bpf/libbpf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 02ee57e3f6c7..6fc8c7f549d9 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -833,6 +833,7 @@ struct bpf_object { void *chunk; /* copy from section .arena.percpu, zero-padded to chunk size */ size_t chunk_sz; /* chunk size, page-aligned */ size_t nr_chunks; /* how many chunks, one chunk per possible cpu */ + size_t offset; /* offset within the arena */ bool present; } arena_percpu; @@ -8212,8 +8213,12 @@ static int bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_pat } /* place globals at the end of the arena (if supported) */ - if (kernel_supports(obj, FEAT_LDIMM64_FULL_RANGE_OFF)) - obj->arena_data_off = mmap_sz - data_sz; + if (kernel_supports(obj, FEAT_LDIMM64_FULL_RANGE_OFF)) { + obj->arena_data_off = data_sz ? mmap_sz - data_sz : 0; + obj->arena_percpu.offset = mmap_sz - data_sz - percpu_sz; + } else { + obj->arena_percpu.offset = data_sz; + } } err = bpf_object__relocate_data_ptrs(obj); -- 2.47.3