All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH bpf-next v3 0/2] libbpf: Improve BPF load performance by selectively loading kmod BTFs
@ 2026-08-19  9:04 Fuyu Zhao
  2026-08-19  9:04 ` [RFC PATCH bpf-next v3 1/2] libbpf: support selective kernel module BTF loading via bpf_object_open_opts Fuyu Zhao
  2026-08-19  9:04 ` [RFC PATCH bpf-next v3 2/2] selftests/bpf: add tests for selective kmod BTF loading Fuyu Zhao
  0 siblings, 2 replies; 7+ messages in thread
From: Fuyu Zhao @ 2026-08-19  9:04 UTC (permalink / raw)
  To: bpf, andrii.nakryiko, alan.maguire
  Cc: andrii, ast, daniel, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, shuah, yatsenko,
	linux-kernel, linux-kselftest, Fuyu Zhao

Currently, during BPF object loading, load_module_btfs() unconditionally
iterates over all kernel module BTFs and loads each one. This introduces
unnecessary overhead when a BPF program only needs BTFs from a specific,
small subset of modules. In environments with hundreds of modules,
loading all module BTFs can measurably increase the loading time.

In our Android testing, BPF programs are loaded on demand rather than
preloaded to avoid unnecessary memory usage from unused programs. With
93 module BTFs present, the total BPF loading time exceeds 300 ms, with
module BTF loading accounting for around 69% of the total loading time.

The existing module qualification in SEC(), such as
SEC("fentry/mymod:foo"), does not address this issue. It only affects
BTF ID lookup after module BTFs have already been loaded by
load_module_btfs(), and does not reduce the number of module BTFs loaded.

This series adds kmod_btf_names and kmod_btf_names_cnt fields to
bpf_object_open_opts, allowing users to specify a list of kernel modules
whose BTFs should be loaded. libbpf uses this information to skip
unrelated module BTFs during iteration and stops iterating once all
requested module BTFs have been loaded. Without these options, the
existing behavior remains unchanged.

Performance impact (BPF skeleton open and load time):

  Modules loaded | Default (load all) | With kmod_btf_names | Speedup
  ---------------|--------------------|---------------------|--------
  1              | 35.6 ms            | 35.6 ms             | Baseline
  10             | 37.1 ms            | 35.8 ms             | +3.5%
  100            | 46.7 ms            | 36.7 ms             | +21.4%
  300            | 65.1 ms            | 38.7 ms             | +40.6%

Changelog:
v3:
- Use bpf_object_open_opts to specify kernel module BTFs to load rather
  than introducing a new .kmod_btfs ELF section, as suggested by Andrii.

v2:
- Link: https://lore.kernel.org/bpf/20260813032613.2755-1-zhaofuyu@vivo.com/
- Addressed issues with allocation error handling, multiple .kmod_btfs
  sections, the transient stack pointer in is_kmod_btf_needed(), and
  selftest dependency and comment formatting. (sashiko-bot)
- Removed KMODS_BTF_LOADED and KMODS_BTF_UNLOADED and simplified the
  related logic.

v1:
- Link: https://lore.kernel.org/bpf/20260806042042.3239428-1-zhaofuyu@vivo.com/

Fuyu Zhao (2):
  libbpf: support selective kernel module BTF loading via
    bpf_object_open_opts
  selftests/bpf: add tests for selective kmod BTF loading

 tools/lib/bpf/libbpf.c                        | 133 ++++++++++++
 tools/lib/bpf/libbpf.h                        |  16 +-
 .../selftests/bpf/prog_tests/kmod_btfs.c      | 196 ++++++++++++++++++
 tools/testing/selftests/bpf/progs/kmod_btfs.c |  13 ++
 4 files changed, 357 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/kmod_btfs.c
 create mode 100644 tools/testing/selftests/bpf/progs/kmod_btfs.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-19  9:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19  9:04 [RFC PATCH bpf-next v3 0/2] libbpf: Improve BPF load performance by selectively loading kmod BTFs Fuyu Zhao
2026-08-19  9:04 ` [RFC PATCH bpf-next v3 1/2] libbpf: support selective kernel module BTF loading via bpf_object_open_opts Fuyu Zhao
2026-08-19  9:12   ` sashiko-bot
2026-08-19  9:35   ` bot+bpf-ci
2026-08-19  9:04 ` [RFC PATCH bpf-next v3 2/2] selftests/bpf: add tests for selective kmod BTF loading Fuyu Zhao
2026-08-19  9:12   ` sashiko-bot
2026-08-19  9:50   ` bot+bpf-ci

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.