Skip to content

Reduce kmalloc / kfree churn in the verifier

Lorenz Bauer bpf lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: verifier: improve function state reallocationkernel/bpf/verifier.c+100 -950 replies
2/3bpf: verifier: use copy_array for jmp_historykernel/bpf/verifier.c+5 -80 replies
3/3bpf: verifier: allocate idmap scratch in verifier envinclude/linux/bpf_verifier.h kernel/bpf/verifier.c+23 -311 reply

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchEdward Cree
1/3
2/3
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf-next 0/3] Reduce kmalloc / kfree churn in the verifier

github.com/cilium/ebpf runs integration tests with libbpf in a vm on CI. I recently did some work to increase the code coverage from that, and started experiencing OOM-kills in the VM. That led me down a rabbit hole looking at verifier memory allocation patterns. I didn't figure out what triggered the OOM-kills but refactored some often called memory allocation code.

The key insight is that often times we don't need to do a full kfree / kmalloc, but can instead just reallocate. The first patch adds two helpers which do just that for the use cases in the verifier, which are sufficiently different that they can't use stock krealloc_array and friends.

The series makes bpf_verif_scale about 10% faster in my VM set up, which is especially noticeable when running with KASAN enabled.

Lorenz Bauer (3):
bpf: verifier: improve function state reallocation
bpf: verifier: use copy_array for jmp_history
bpf: verifier: allocate idmap scratch in verifier env

 include/linux/bpf_verifier.h |   8 ++
 kernel/bpf/verifier.c        | 254 +++++++++++++++++------------------
 2 files changed, 128 insertions(+), 134 deletions(-)
Signature · 1 line
2.27.0