[RFC PATCH bpf-next 0/2] libbpf: Improve BPF load performance by selectively loading kmod BTFs
Fuyu Zhao <[email protected]>
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
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%
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