bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/2] veristat: memory accounting for bpf programs
@ 2025-06-05 23:06 Eduard Zingerman
  2025-06-05 23:06 ` [PATCH bpf-next v1 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
  2025-06-05 23:06 ` [PATCH bpf-next v1 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
  0 siblings, 2 replies; 14+ messages in thread
From: Eduard Zingerman @ 2025-06-05 23:06 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:

    File       Program               Peak states  Peak memory (KiB)
    ---------  --------------------  -----------  -----------------
    bpf.bpf.o  lavd_select_cpu              1311              26256
    bpf.bpf.o  lavd_enqueue                 1140              22720
    bpf.bpf.o  layered_enqueue               777              11504
    ...

Technically, this is implemented by creating and entering a new cgroup
before verifying each program. The difference in memory.peak values
before and after bpf_object__load() is reported as the metric.

This incurs some overhead in veristat runtime. For example:
- increase from 82s to 102s on test_progs BPF binaries;
- increase from 42s to 47s on sched_ext BPF binaries.

Measurements are not completely stable and might change from run to
run by +-256Kb or something close. For sched_ext binaries I observe a
rate of 3 changes per run from a total of 188 programs. Mostly affects
very small programs.

I tried a different scheme, where new cgroup was allocated only once,
and then a combination of "echo 32G > memory.reclaim" and
"echo reset > memory.peak" (via fd) was executed before each program
load. For reasons unclear this approach did not produce stable
measurements.

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                  |  49 ++---
 tools/testing/selftests/bpf/veristat.c | 249 ++++++++++++++++++++++++-
 3 files changed, 275 insertions(+), 38 deletions(-)

-- 
2.48.1


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

end of thread, other threads:[~2025-06-09 22:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 23:06 [PATCH bpf-next v1 0/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-05 23:06 ` [PATCH bpf-next v1 1/2] bpf: include verifier memory allocations in memcg statistics Eduard Zingerman
2025-06-05 23:06 ` [PATCH bpf-next v1 2/2] veristat: memory accounting for bpf programs Eduard Zingerman
2025-06-06  1:03   ` Eduard Zingerman
2025-06-06  2:17     ` Alexei Starovoitov
2025-06-06  2:33       ` Eduard Zingerman
2025-06-06  2:35         ` Alexei Starovoitov
2025-06-06  2:46           ` Eduard Zingerman
2025-06-06 16:53   ` Mykyta Yatsenko
2025-06-06 17:03     ` Eduard Zingerman
2025-06-06 18:19       ` Andrii Nakryiko
2025-06-07  8:13         ` Eduard Zingerman
2025-06-09 20:57           ` Andrii Nakryiko
2025-06-09 22:45             ` 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).