bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] veristat: memory accounting for bpf programs
@ 2025-06-12 13:08 Eduard Zingerman
  2025-06-12 13:08 ` [PATCH bpf-next v2 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
  2025-06-12 13:08 ` [PATCH bpf-next v2 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
  0 siblings, 2 replies; 13+ messages in thread
From: Eduard Zingerman @ 2025-06-12 13:08 UTC (permalink / raw)
  To: bpf, ast
  Cc: andrii, daniel, martin.lau, kernel-team, yonghong.song,
	Eduard Zingerman

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:
v1: https://lore.kernel.org/bpf/20250605230609.1444980-1-eddyz87@gmail.com/
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                  |  63 +++---
 tools/testing/selftests/bpf/veristat.c | 266 ++++++++++++++++++++++++-
 3 files changed, 299 insertions(+), 45 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-06-16  8:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 13:08 [PATCH bpf-next v2 0/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-12 13:08 ` [PATCH bpf-next v2 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
2025-06-13  0:05   ` Andrii Nakryiko
2025-06-13  0:15     ` Eduard Zingerman
2025-06-13  0:18       ` Andrii Nakryiko
2025-06-13  0:53         ` Alexei Starovoitov
2025-06-13  1:29           ` Eduard Zingerman
2025-06-13  2:25             ` Alexei Starovoitov
2025-06-16  8:02               ` Eduard Zingerman
2025-06-12 13:08 ` [PATCH bpf-next v2 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-13  0:01   ` Andrii Nakryiko
2025-06-13  0:31     ` Eduard Zingerman
2025-06-13  7:09     ` Eduard Zingerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).