From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
kernel-team@fb.com, yonghong.song@linux.dev,
Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next v1 0/2] veristat: memory accounting for bpf programs
Date: Thu, 5 Jun 2025 16:06:07 -0700 [thread overview]
Message-ID: <20250605230609.1444980-1-eddyz87@gmail.com> (raw)
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
next reply other threads:[~2025-06-05 23:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 23:06 Eduard Zingerman [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250605230609.1444980-1-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.