Skip to content

veristat: memory accounting for bpf programs

Eduard Zingerman bpf 3 versions – Applied

Status from this message: applied to bpf-next, thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 1 replyApplied 1/2
  2. v22 patches 10 repliesSuperseded
  3. v12 patches 11 repliesSuperseded

Changes in v3 from the cover letter

- bpf_verifier_state->jmp_history and bpf_verifier_env->explored_states allocations are switched from GFP_USER to GFP_KERNEL_ACCOUNT (Andrii, Alexei);
- veristat.c:STR macro removed, PATH_MAX-1 == 4095 is hard-coded in scanf format strings (Andrii);
- env->{orig,stat}_cgroup size changed to PATH_MAX (Andrii);
- snprintf_trunc() is removed, flag -Wno-format-truncation
is added to CFLAGS for veristat.o when compiled with gcc;

Patches in v3 Applied · 1/2

#Subject and filesSizeRepliesApplied
1/2bpf: include verifier memory allocations in memcg statisticskernel/bpf/btf.c kernel/bpf/verifier.c+43 -410 repliesApplied
2/2veristat: memory accounting for bpf programstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/veristat.c+249 -71 reply

Reviews trailers per patch

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

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/2] veristat: memory accounting for bpf programs

When working on the verifier, it is sometimes interesting to know how a particular change affects memory consumption. This patch-set modifies veristat to provide such information. As a collateral, kernel needs an update to make allocations reachable from BPF program load accountable in memcg statistics.

Here is a sample output:

  Program          Peak states  Peak memory (MiB)
  ---------------  -----------  -----------------
  lavd_select_cpu         2153                 43
  lavd_enqueue            1982                 41
  lavd_dispatch           3480                 28

Technically, this is implemented by creating and entering a new cgroup at the start of veristat execution. The difference between values from cgroup "memory.peak" file before and after bpf_object__load() is used as a metric.

To minimize measurements jitter data is collected in megabytes.

Changelog:
v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3:
- bpf_verifier_state->jmp_history and bpf_verifier_env->explored_states allocations are switched from GFP_USER to GFP_KERNEL_ACCOUNT (Andrii, Alexei);
- veristat.c:STR macro removed, PATH_MAX-1 == 4095 is hard-coded in scanf format strings (Andrii);
- env->{orig,stat}_cgroup size changed to PATH_MAX (Andrii);
- snprintf_trunc() is removed, flag -Wno-format-truncation
is added to CFLAGS for veristat.o when compiled with gcc;

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
- a single cgroup, created at the beginning of execution, is now used for measurements (Andrii, Mykyta);
- cgroup namespace is not created, as it turned out to be useless (Andrii);
- veristat no longer mounts cgroup fs or changes subtree_control, instead it looks for an existing mount point and reports an error if memory.peak file can't be opened (Andrii, Alexei);
- if 'mem_peak' statistics is not enabled, veristat skips cgroup setup;
- code sharing with cgroup_helpers.c was considered but was decided against to simplify veristat github sync.

Eduard Zingerman (2):
bpf: include verifier memory allocations in memcg statistics
veristat: memory accounting for bpf programs

 kernel/bpf/btf.c                       |  15 +-
 kernel/bpf/verifier.c                  |  69 +++----
 tools/testing/selftests/bpf/Makefile   |   8 +
 tools/testing/selftests/bpf/veristat.c | 248 ++++++++++++++++++++++++-
 4 files changed, 292 insertions(+), 48 deletions(-)
Signature · 1 line
2.47.1