mbox series

[v5,bpf-next,0/5] bpf: add percpu stats for bpf_map

Message ID 20230706133932.45883-1-aspsk@isovalent.com (mailing list archive)
Headers show
Series bpf: add percpu stats for bpf_map | expand

Message

Anton Protopopov July 6, 2023, 1:39 p.m. UTC
This series adds a mechanism for maps to populate per-cpu counters on
insertions/deletions. The sum of these counters can be accessed by a new kfunc
from map iterator and tracing programs.

The following patches are present in the series:

  * Patch 1 adds a generic per-cpu counter to struct bpf_map
  * Patch 2 adds a new kfunc to access the sum of per-cpu counters
  * Patch 3 utilizes this mechanism for hash-based maps
  * Patch 4 extends the preloaded map iterator to dump the sum
  * Patch 5 adds a self-test for the change

The reason for adding this functionality in our case (Cilium) is to get signals
about how full some heavy-used maps are and what the actual dynamic profile of
map capacity is. In the case of LRU maps this is impossible to get this
information anyhow else. The original presentation can be found here [1].

  [1] https://lpc.events/event/16/contributions/1368/

v4 -> v5:
* don't pass useless empty opts when creating a link, pass NULL (Hou)
* add a debug message (Hou)
* make code more readable (Alexei)
* remove the selftest which only checked that elem_count != NULL

v3 -> v4:
* fix selftests:
  * added test code for batch map operations
  * added a test for BPF_MAP_TYPE_HASH_OF_MAPS (Hou)
  * added tests for BPF_MAP_TYPE_LRU* with BPF_F_NO_COMMON_LRU (Hou)
  * map_info was called multiple times unnecessarily (Hou)
  * small fixes + some memory leaks (Hou)
* fixed wrong error path for freeing a non-prealloc map (Hou)
* fixed counters for batch delete operations (Hou)

v2 -> v3:
- split commits to better represent update logic (Alexei)
- remove filter from kfunc to allow all tracing programs (Alexei)
- extend selftests (Alexei)

v1 -> v2:
- make the counters generic part of struct bpf_map (Alexei)
- don't use map_info and /proc/self/fdinfo in favor of a kfunc (Alexei)

Anton Protopopov (5):
  bpf: add percpu stats for bpf_map elements insertions/deletions
  bpf: add a new kfunc to return current bpf_map elements count
  bpf: populate the per-cpu insertions/deletions counters for hashmaps
  bpf: make preloaded map iterators to display map elements count
  selftests/bpf: test map percpu stats

 include/linux/bpf.h                           |  30 +
 kernel/bpf/hashtab.c                          |  22 +-
 kernel/bpf/map_iter.c                         |  39 +-
 kernel/bpf/preload/iterators/iterators.bpf.c  |   9 +-
 .../iterators/iterators.lskel-little-endian.h | 526 +++++++++---------
 .../bpf/map_tests/map_percpu_stats.c          | 447 +++++++++++++++
 .../selftests/bpf/progs/map_percpu_stats.c    |  24 +
 7 files changed, 834 insertions(+), 263 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/map_tests/map_percpu_stats.c
 create mode 100644 tools/testing/selftests/bpf/progs/map_percpu_stats.c

Comments

patchwork-bot+netdevbpf@kernel.org July 6, 2023, 8:40 p.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu,  6 Jul 2023 13:39:27 +0000 you wrote:
> This series adds a mechanism for maps to populate per-cpu counters on
> insertions/deletions. The sum of these counters can be accessed by a new kfunc
> from map iterator and tracing programs.
> 
> The following patches are present in the series:
> 
>   * Patch 1 adds a generic per-cpu counter to struct bpf_map
>   * Patch 2 adds a new kfunc to access the sum of per-cpu counters
>   * Patch 3 utilizes this mechanism for hash-based maps
>   * Patch 4 extends the preloaded map iterator to dump the sum
>   * Patch 5 adds a self-test for the change
> 
> [...]

Here is the summary with links:
  - [v5,bpf-next,1/5] bpf: add percpu stats for bpf_map elements insertions/deletions
    https://git.kernel.org/bpf/bpf-next/c/25954730461a
  - [v5,bpf-next,2/5] bpf: add a new kfunc to return current bpf_map elements count
    https://git.kernel.org/bpf/bpf-next/c/803370d3d375
  - [v5,bpf-next,3/5] bpf: populate the per-cpu insertions/deletions counters for hashmaps
    https://git.kernel.org/bpf/bpf-next/c/9bc421b6be95
  - [v5,bpf-next,4/5] bpf: make preloaded map iterators to display map elements count
    https://git.kernel.org/bpf/bpf-next/c/515ee52b2224
  - [v5,bpf-next,5/5] selftests/bpf: test map percpu stats
    https://git.kernel.org/bpf/bpf-next/c/6c1b8cb6a70a

You are awesome, thank you!