Re: [RFC PATCH bpf-next 0/2] libbpf: Improve BPF load performance by selectively loading kmod BTFs

Andrii Nakryiko <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <CAEf4BzZbsH2kyq9wb=eCNEOioWJnO2jSwsvbL3uWeyL51OnzVw@mail.gmail.com>
On Wed, Aug 5, 2026 at 9:21 PM Fuyu Zhao <[email protected]> wrote:
>
> Currently, during BPF object loading, load_module_btfs() unconditionally
> iterates over all loaded kernel modules and loads their BTFs. This
> introduces unnecessary overhead when a BPF program only needs a specific,
> small subset of modules. In environments with hundreds of modules,
> loading all module measurably increases the loading time.
>
> This series introduces a ".kmod_btfs" ELF section, allowing BPF programs
> to declare the modules that need BTF loading. libbpf parses this
> section, collects the module names, and skips loading BTFs for any
> module not in the list, thereby reducing overhead. It also stops the
> iteration early once all declared modules are found.
>
> Usage example:
>
>   DEFINE_KMOD_BTFS(_needed_kmods) = { "bpf_testmod" };
>
> Performance impact (<skel>__open_and_load() time):
>
>   Modules loaded | Without .kmod_btfs | With .kmod_btfs | Speedup
>   ---------------|--------------------|-----------------|--------
>   1              | 35.0 ms            | 35.0 ms         | Baseline
>   10             | 36.5 ms            | 35.1 ms         | +3.8%
>   100            | 46.2 ms            | 35.9 ms         | +22.3%
>   300            | 65.2 ms            | 38.0 ms         | +41.7%

First, is 30ms start up overhead really such a big deal when it comes
to one-time thing that sets up a bunch of BPF programs? Can you
elaborate on the use case you have that actually is harmed by this
libbpf behavior?

>
> Fuyu Zhao (2):
>   libbpf: support selective kernel module BTF loading via .kmod_btfs
>     section
>   selftests/bpf: add tests for selective kmod BTF loading
>
>  tools/lib/bpf/bpf_helpers.h                   |  14 +++
>  tools/lib/bpf/libbpf.c                        | 112 ++++++++++++++++++
>  .../selftests/bpf/prog_tests/kmod_btfs.c      |  47 ++++++++
>  tools/testing/selftests/bpf/progs/kmod_btfs.c |  14 +++
>  .../selftests/bpf/progs/kmod_btfs_mix.c       |  15 +++
>  .../selftests/bpf/progs/kmod_btfs_nonexist.c  |  17 +++
>  6 files changed, 219 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/kmod_btfs.c
>  create mode 100644 tools/testing/selftests/bpf/progs/kmod_btfs.c
>  create mode 100644 tools/testing/selftests/bpf/progs/kmod_btfs_mix.c
>  create mode 100644 tools/testing/selftests/bpf/progs/kmod_btfs_nonexist.c
>
> --
> 2.34.1
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.