Skip to content

bpf: introduce per-cpu maps

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: introduce BPF_MAP_TYPE_PERCPU_HASH mapinclude/uapi/linux/bpf.h kernel/bpf/hashtab.c+229 -470 replies
2/6bpf: introduce BPF_MAP_TYPE_PERCPU_ARRAY mapinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/arraymap.c+93 -110 replies
3/6bpf: add lookup/update support for per-cpu hash and array mapsinclude/linux/bpf.h kernel/bpf/arraymap.c kernel/bpf/hashtab.c +1 more+201 -260 replies
4/6samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_HASHsamples/bpf/test_maps.c+96 -00 replies
5/6samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_ARRAYsamples/bpf/test_maps.c+92 -00 replies
6/6samples/bpf: update tracex[23] examples to use per-cpu mapssamples/bpf/tracex2_kern.c samples/bpf/tracex2_user.c samples/bpf/tracex3_kern.c +1 more+25 -130 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH net-next 0/6] bpf: introduce per-cpu maps

We've started to use bpf to trace every packet and atomic add instruction (event JITed) started to show up in perf profile. The solution is to do per-cpu counters.
For PERCPU_(HASH|ARRAY) map the existing bpf_map_lookup() helper returns per-cpu area which bpf programs can use to store and increment the counters. The BPF_MAP_LOOKUP_ELEM syscall command returns areas from all cpus and user process aggregates the counters. The usage example is in patch 6. The api turned out to be very easy to use from bpf program and from user space.
Long term we were discussing to add 'bounded loop' instruction, so bpf programs can do aggregation within the program which may help some use cases. Right now user space aggregation of per-cpu counters fits the best.

This patch set is new approach for per-cpu hash and array maps. I've reused the map tests written by Martin and Ming, but implementation and api is new. Old discussion here:
http://thread.gmane.org/gmane.linux.kernel/2123800/focus=2126435

Alexei Starovoitov (4):
bpf: introduce BPF_MAP_TYPE_PERCPU_HASH map
bpf: introduce BPF_MAP_TYPE_PERCPU_ARRAY map
bpf: add lookup/update support for per-cpu hash and array maps samples/bpf: update tracex[23] examples to use per-cpu maps

Martin KaFai Lau (1):
samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_HASH

[email protected] (1):
samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_ARRAY

 include/linux/bpf.h        |  24 ++++
 include/uapi/linux/bpf.h   |   2 +
 kernel/bpf/arraymap.c      | 166 ++++++++++++++++++++--
 kernel/bpf/hashtab.c       | 340 ++++++++++++++++++++++++++++++++++++++-------
 kernel/bpf/syscall.c       |  57 +++++---
 samples/bpf/test_maps.c    | 188 +++++++++++++++++++++++++
 samples/bpf/tracex2_kern.c |   2 +-
 samples/bpf/tracex2_user.c |   7 +-
 samples/bpf/tracex3_kern.c |   8 +-
 samples/bpf/tracex3_user.c |  21 ++-
 10 files changed, 727 insertions(+), 88 deletions(-)
Signature · 1 line
2.4.6