bpf: Avoid unnecessary extra percpu memory allocation
authorYonghong Song <yonghong.song@linux.dev>
Fri, 22 Dec 2023 03:17:34 +0000 (19:17 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 4 Jan 2024 05:08:25 +0000 (21:08 -0800)
commit9beda16c257d55213f70adee2f16d7f13a8502e1
tree808b110d7b573d9567de037bfad6783898857d6c
parent417fa6d163df6f13fb2cfad5132eff354c8a472e
bpf: Avoid unnecessary extra percpu memory allocation

Currently, for percpu memory allocation, say if the user
requests allocation size to be 32 bytes, the actually
calculated size will be 40 bytes and it further rounds
to 64 bytes, and eventually 64 bytes are allocated,
wasting 32-byte memory.

Change bpf_mem_alloc() to calculate the cache index
based on the user-provided allocation size so unnecessary
extra memory can be avoided.

Suggested-by: Hou Tao <houtao1@huawei.com>
Acked-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231222031734.1288400-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/memalloc.c