[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251112175939.2365295-1-ameryhung@gmail.com>
Date: Wed, 12 Nov 2025 09:59:34 -0800
From: Amery Hung <ameryhung@...il.com>
To: bpf@...r.kernel.org
Cc: netdev@...r.kernel.org,
alexei.starovoitov@...il.com,
andrii@...nel.org,
daniel@...earbox.net,
martin.lau@...nel.org,
memxor@...il.com,
kpsingh@...nel.org,
yonghong.song@...ux.dev,
song@...nel.org,
ameryhung@...il.com,
kernel-team@...a.com
Subject: [PATCH RFC bpf-next 0/2] Switch to kmalloc_nolock() in BPF local storage
Hi,
This patchset tries to simplify bpf_local_storage.c by switching to
kmalloc_nolock() unconditionally. Currently, local storage adopted
BPF memory allocator in task and cgroup local storage or when PREEMPT_RT
is enabled to allow getting memory in different context without deadlock.
However, due to performance reasons socket local storage did not switch.
Using different memory allocators added a decent amount of complexity.
Therefore, to make [1] and other future work in local storage simpler,
this patchset consolidates the memory allocation/deallocation paths by
switching to kmalloc_nolock() unconditionally.
Benchmark
./bench -p 1 local-storage-create --storage-type <socket,task> \
--batch-size <16,32,64>
The benchmark is a microbenchmark stress-testing how fast local storage
can be created. For task local storage, switching from BPF memory
allocator to kmalloc_nolock() yields a small amount of improvement. For
socket local storage, it losses some when switching from kzalloc() to
kmalloc_nolock().
Socket local storage
memory alloc batch creation speed creation speed diff
--------------- ---- ------------------ ----
kzalloc 16 104.217 ± 0.974k/s 4.15 kmallocs/create
(before) 32 104.355 ± 0.606k/s 4.13 kmallocs/create
64 103.611 ± 0.707k/s 4.15 kmallocs/create
kmalloc_nolock 16 100.566 ± 0.560k/s 1.13 kmallocs/create -3.5%
(after) 32 99.708 ± 0.684k/s 1.15 kmallocs/create -4.5%
64 98.375 ± 1.757k/s 1.13 kmallocs/create -5.1%
Task local storage
memory alloc batch creation speed creation speed diff
--------------- ---- ------------------ ----
BPF memory 16 24.668 ± 0.121k/s 2.54 kmallocs/create
allocator 32 22.899 ± 0.097k/s 2.67 kmallocs/create
(before) 64 22.559 ± 0.076k/s 2.56 kmallocs/create
kmalloc_nolock 16 25.399 ± 0.142k/s 2.51 kmallocs/create +3.0%
(after) 32 23.495 ± 1.285k/s 2.66 kmallocs/create +2.6%
64 23.701 ± 0.207k/s 2.63 kmallocs/create +5.1%
[1] https://lore.kernel.org/bpf/20251002225356.1505480-1-ameryhung@gmail.com/
---
Amery Hung (2):
bpf: Always charge/uncharge memory when allocating/unlinking storage
elements
bpf: Use kmalloc_nolock() in local storage unconditionally
include/linux/bpf_local_storage.h | 12 +-
kernel/bpf/bpf_cgrp_storage.c | 2 +-
kernel/bpf/bpf_inode_storage.c | 2 +-
kernel/bpf/bpf_local_storage.c | 283 +++++-------------------------
kernel/bpf/bpf_task_storage.c | 2 +-
net/core/bpf_sk_storage.c | 6 +-
6 files changed, 53 insertions(+), 254 deletions(-)
--
2.47.3
Powered by blists - more mailing lists