From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin Lau <kafai@meta.com>, Kernel Team <kernel-team@meta.com>,
Eduard <eddyz87@gmail.com>, Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v2 0/2] libbpf: Add bpf_program__clone() for individual program loading
Date: Mon, 23 Feb 2026 13:57:31 +0000 [thread overview]
Message-ID: <260229af-3ea8-43c3-bfd7-fe6b3471e75d@gmail.com> (raw)
In-Reply-To: <CAADnVQJFHzGQX0xh5pSVm1AKH=ONM4NYRnv=+qdWOAW4PmrVQg@mail.gmail.com>
On 2/20/26 22:48, Alexei Starovoitov wrote:
> On Fri, Feb 20, 2026 at 11:18 AM Mykyta Yatsenko
> <mykyta.yatsenko5@gmail.com> wrote:
>> This series adds bpf_program__clone() to libbpf and converts veristat to
>> use it, replacing the costly per-program object re-opening pattern.
>>
>> veristat needs to load each BPF program in isolation to collect
>> per-program verification statistics. Previously it achieved this by
>> opening a fresh bpf_object for every program, disabling autoload on all
>> but the target, and loading the whole object. For object files with many
>> programs this meant repeating ELF parsing and BTF processing N times.
>>
>> Patch 1 introduces bpf_program__clone(), which loads a single program
>> from a prepared object into the kernel and returns an fd owned by the
>> caller. It resolves BTF attach targets, fills in func/line info,
>> fd_array, and other load parameters from the prepared object
>> automatically, while letting callers override any field via
>> bpf_prog_load_opts.
>>
>> Patch 2 converts veristat to prepare the object once and clone each
>> program individually, eliminating redundant work.
>>
>> Performance
>> Tested on selftests: 918 objects, ~4270 programs:
>> - Wall time: 36.88s -> 23.18s (37% faster)
>> - User time: 20.80s -> 16.07s (23% faster)
>> - Kernel time: 12.07s -> 6.06s (50% faster)
>>
>> Per-program loading also improves coverage: 83 programs that previously
>> failed now succeed.
> Wait what? How is that possible?
Thanks for asking. Take for example verifier_unpriv.bpf.o object,
all progs fail to load on the system veristat, the errors are:
```
libbpf: map 'map_prog1_socket': failed to initialize slot [1]
to prog 'dummy_prog_loop1_socket' fd=-2: -EBADF
...
libbpf: map 'map_prog1_socket': failed to initialize slot
[0] to prog 'dummy_prog_42_socket' fd=-2: -EBADF
...
etc
```
I understand this is due to the libbpf trying to initialize
all PROG_ARRAY maps during object load, regardless if the corresponding
program is loading or not (currently only 1 program is
enabled at a time, so object that has those PROG_ARRAY has no
chance to succeed)
This root cause is the only reason for all 83
improvements.
This is not intentional, but it sounds like a nice side-effect,
so I mention it.
Is this something we would like to address in libbpf?
prev parent reply other threads:[~2026-02-23 13:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 19:18 [PATCH bpf-next v2 0/2] libbpf: Add bpf_program__clone() for individual program loading Mykyta Yatsenko
2026-02-20 19:18 ` [PATCH bpf-next v2 1/2] libbpf: Introduce bpf_program__clone() Mykyta Yatsenko
2026-02-23 17:25 ` Emil Tsalapatis
2026-02-23 17:59 ` Mykyta Yatsenko
2026-02-23 18:04 ` Emil Tsalapatis
2026-02-24 19:28 ` Eduard Zingerman
2026-02-24 19:32 ` Eduard Zingerman
2026-02-24 20:47 ` Mykyta Yatsenko
2026-03-06 17:22 ` [External] " Andrey Grodzovsky
2026-03-10 0:08 ` Mykyta Yatsenko
2026-03-11 13:35 ` Andrey Grodzovsky
2026-03-11 22:52 ` Andrii Nakryiko
2026-03-16 14:23 ` Andrey Grodzovsky
2026-03-11 23:03 ` Andrii Nakryiko
2026-02-20 19:18 ` [PATCH bpf-next v2 2/2] selftests/bpf: Use bpf_program__clone() in veristat Mykyta Yatsenko
2026-02-23 17:49 ` Emil Tsalapatis
2026-02-23 18:39 ` Mykyta Yatsenko
2026-02-23 18:54 ` Emil Tsalapatis
2026-02-24 2:03 ` Eduard Zingerman
2026-02-24 12:20 ` Mykyta Yatsenko
2026-02-24 19:08 ` Eduard Zingerman
2026-02-24 19:12 ` Mykyta Yatsenko
2026-02-24 19:16 ` Eduard Zingerman
2026-02-20 22:48 ` [PATCH bpf-next v2 0/2] libbpf: Add bpf_program__clone() for individual program loading Alexei Starovoitov
2026-02-23 13:57 ` Mykyta Yatsenko [this message]
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=260229af-3ea8-43c3-bfd7-fe6b3471e75d@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kafai@meta.com \
--cc=kernel-team@meta.com \
--cc=yatsenko@meta.com \
/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.