From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Kernel Team <kernel-team@fb.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH bpf-next v2 1/2] bpf: include verifier memory allocations in memcg statistics
Date: Thu, 12 Jun 2025 18:29:35 -0700 [thread overview]
Message-ID: <60dc085263d7d746f5c223f8df85f55679786c7f.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQJxQMEdbdTrDSZyb+SWxdwjJYWx6F6jmkff=OAeEoSTPQ@mail.gmail.com>
On Thu, 2025-06-12 at 17:53 -0700, Alexei Starovoitov wrote:
> On Thu, Jun 12, 2025 at 5:18 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Thu, Jun 12, 2025 at 5:15 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > >
> > > On Thu, 2025-06-12 at 17:05 -0700, Andrii Nakryiko wrote:
> > >
> > > [...]
> > >
> > > > We have a bunch of GFP_USER allocs as well, e.g. for instruction
> > > > history and state hashmap. At least the former is very much
> > > > interesting, so should we add __GFP_ACCOUNT to those as well?
> > >
> > > Thank you for pointing this out.
> > > GFP_USER allocations are in 4 places in verifier.c:
> > > 1. copy of state->jmp_history in copy_verifier_state
> > > 2. realloc of state->jmp_history in push_jmp_history
> > > 3. allocation of struct bpf_prog for every subprogram in jit_subprograms
> > > 4. env->explored_states fixed size array of list heads in bpf_check
> > >
> > > GFP_USER is not used in btf.c and log.c.
> > >
> > > Is there any reason to keep 1-4 as GFP_USER?
> > > From gfp_types.h:
> > >
> > > * %GFP_USER is for userspace allocations that also need to be directly
> > > * accessibly by the kernel or hardware. It is typically used by hardware
> > > * for buffers that are mapped to userspace (e.g. graphics) that hardware
> > > * still must DMA to. cpuset limits are enforced for these allocations. a
> > >
> > > I assume for (3) this might be used for programs offloading (?),
> > > but 1,2,4 are internal to verifier.
> > >
> > > Wdyt?
> >
> > Alexei might remember more details, but I think the thinking was that
> > all these allocations are user-induced based on specific BPF program
> > code, so at some point we were marking them as GFP_USER. But clearly
> > this is inconsistent, so perhaps just unifying to GFP_KERNEL_ACCOUNT
> > is a better way forward?
>
> Beetlejuice.
> 1,2,4 can be converted to GFP_KERNEL_ACCOUNT,
> since it's a temp memory for the purpose of verification.
> 3 should probably stay as GFP_USER, since it's a long term memory.
> GFP_USER is more restrictive than GFP_KERNEL, since
> it requires memory to be within cpuset limits set for the current task.
> The pages allocated for user space needs should be GFP_USER.
> One can argue that bpf prog is not accessed by any user task
> and prog itself is more like kernel module, so GFP_KERNEL is fine,
> but it will require a bigger code audit.
Thank you, I've converted 1,2,4.
For 3 I'd avoid accounting same way I avoided it in jit, assuming that
this memory does not belong to cgroup, but to some common kernel pool.
Looks maximal memory consumption did not change by much compared to
measurements for SCC series, top consumers for sched_ext:
Program Peak memory (MiB)
------------------------------- -----------------
lavd_select_cpu 42
lavd_enqueue 41
lavd_dispatch 28
layered_dispatch 28
layered_enqueue 12
Top consumers for selftests:
File Program Peak memory (MiB)
----------------------- ------------------------------ -----------------
pyperf600.bpf.o on_event 267
pyperf180.bpf.o on_event 213
strobemeta.bpf.o on_event 199
verifier_loops1.bpf.o loop_after_a_conditional_jump 128
pyperf100.bpf.o on_event 118
next prev parent reply other threads:[~2025-06-13 1:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=60dc085263d7d746f5c223f8df85f55679786c7f.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@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 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).