From: Alexei Starovoitov max_entries of an arena is its size in pages. The kernel rejects 0. Thus each prog must select a number, and the same number is a different size on a kernel with a different page size. A large arena has almost no cost. The kernel reserves 4 Gbyte of kernel addresses for each arena, small or large. Only allocated pages use memory. When max_entries is not set, make the arena 1 Gbyte. libbpf calculates max_entries from the page size. libbpf maps the full arena into the process that loads the object. Thus VmSize of this process grows by 1 Gbyte. If the process called mlockall(MCL_FUTURE), the kernel populates all these pages. Signed-off-by: Alexei Starovoitov --- tools/lib/bpf/libbpf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fb8a1f07c5b6..1d4f04aa35f1 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -552,6 +552,12 @@ struct bpf_struct_ops { #define STRUCT_OPS_SEC ".struct_ops" #define STRUCT_OPS_LINK_SEC ".struct_ops.link" #define ARENA_SEC ".addr_space.1" +/* + * The size of the arena map when max_entries is not set. It's in bytes: + * max_entries of arena is in pages and the size of a page depends on + * the kernel. Only the pages that are allocated take memory. + */ +#define ARENA_DEFAULT_SZ ((size_t)1 << 30) enum libbpf_map_type { LIBBPF_MAP_UNSPEC, @@ -3148,6 +3154,8 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict, return -EINVAL; } obj->arena_map_idx = i; + if (!map->def.max_entries) + map->def.max_entries = ARENA_DEFAULT_SZ / sysconf(_SC_PAGE_SIZE); if (obj->efile.arena_data) { err = init_arena_map_data(obj, map, obj->efile.arena_data->d_buf, -- 2.55.0