Skip to content

bpf: inline bpf_map_lookup_elem()

Alexei Starovoitov netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6bpf: move fixup_bpf_calls() functionkernel/bpf/syscall.c kernel/bpf/verifier.c+57 -560 replies
2/6bpf: refactor fixup_bpf_calls()kernel/bpf/verifier.c+35 -410 replies
3/6bpf: adjust insn_aux_data when patching insnskernel/bpf/verifier.c+39 -50 replies
4/6bpf: add helper inlining infra and optimize map_array lookupinclude/linux/bpf.h include/linux/bpf_verifier.h include/linux/filter.h +2 more+77 -40 replies
5/6bpf: inline htab_map_lookup_elem()kernel/bpf/hashtab.c+30 -10 replies
6/6samples/bpf: add map_lookup microbenchmarksamples/bpf/map_perf_test_kern.c samples/bpf/map_perf_test_user.c+65 -00 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchDaniel Borkmann
1/6A-b
2/6A-b
3/6A-b
4/6A-b
5/6A-b
6/6A-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 net-next 0/6] bpf: inline bpf_map_lookup_elem()

bpf_map_lookup_elem() is one of the most frequently used helper functions. Improve JITed program performance by inlining this helper.

bpf_map_type before after
hash 58M 74M
array 174M 280M

The values are number of lookups per second in ideal conditions measured by micro-benchmark in patch 6.

The 'perf report' for HASH map type:
before:

    54.23%  map_perf_test  [kernel.kallsyms]  [k] __htab_map_lookup_elem
    14.24%  map_perf_test  [kernel.kallsyms]  [k] lookup_elem_raw
     8.84%  map_perf_test  [kernel.kallsyms]  [k] htab_map_lookup_elem
     5.93%  map_perf_test  [kernel.kallsyms]  [k] bpf_map_lookup_elem
     2.30%  map_perf_test  [kernel.kallsyms]  [k] bpf_prog_da4fc6a3f41761a2
     1.49%  map_perf_test  [kernel.kallsyms]  [k] kprobe_ftrace_handler

after:

    60.03%  map_perf_test  [kernel.kallsyms]  [k] __htab_map_lookup_elem
    18.07%  map_perf_test  [kernel.kallsyms]  [k] lookup_elem_raw
     2.91%  map_perf_test  [kernel.kallsyms]  [k] bpf_prog_da4fc6a3f41761a2
     1.94%  map_perf_test  [kernel.kallsyms]  [k] _einittext
     1.90%  map_perf_test  [kernel.kallsyms]  [k] __audit_syscall_exit
     1.72%  map_perf_test  [kernel.kallsyms]  [k] kprobe_ftrace_handler

so the cost of htab_map_lookup_elem() and bpf_map_lookup_elem() is gone after inlining.

'per-cpu' and 'lru' map types can be optimized similarly in the future.

Note the sparse will complain that bpf is addictive ;) kernel/bpf/hashtab.c:438:19: sparse: subtraction of functions? Share your drugs kernel/bpf/verifier.c:3342:38: sparse: subtraction of functions? Share your drugs it's not a new warning, just in new places.

Alexei Starovoitov (6):
bpf: move fixup_bpf_calls() function
bpf: refactor fixup_bpf_calls()
bpf: adjust insn_aux_data when patching insns
bpf: add helper inlining infra and optimize map_array lookup
bpf: inline htab_map_lookup_elem()
samples/bpf: add map_lookup microbenchmark

 include/linux/bpf.h              |   1 +
 include/linux/bpf_verifier.h     |   5 +-
 include/linux/filter.h           |  10 +++
 kernel/bpf/arraymap.c            |  29 +++++++++
 kernel/bpf/hashtab.c             |  31 +++++++++-
 kernel/bpf/syscall.c             |  56 -----------------
 kernel/bpf/verifier.c            | 129 ++++++++++++++++++++++++++++++++++++---
 samples/bpf/map_perf_test_kern.c |  33 ++++++++++
 samples/bpf/map_perf_test_user.c |  32 ++++++++++
 9 files changed, 261 insertions(+), 65 deletions(-)
Signature · 1 line
2.8.0