linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v3 0/3] Significantly Improve BTF Type Lookup Performance
@ 2025-10-27 13:54 Donglin Peng
  2025-10-27 13:54 ` [RFC PATCH v3 1/3] btf: implement BTF type sorting for accelerated lookups Donglin Peng
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Donglin Peng @ 2025-10-27 13:54 UTC (permalink / raw)
  To: ast; +Cc: linux-kernel, bpf, Donglin Peng

The funcgraph-args feature frequently calls btf_find_by_name_kind(), which
currently uses a linear search algorithm. With large BTF datasets like vmlinux
 (containing over 80,000 named types), this causes significant performance overhead.

This patch series introduces a new libbpf interface btf__permute(), which allows
tools like pahole to sort BTF types by kind and name. After generating a sorted
type ID array, these tools can invoke the new interface to perform in-place BTF
sorting. During BTF parsing, btf_check_sorted() verifies whether the types are
sorted.

Performance testing shows dramatic improvement after sorting by kind and name, as
demonstrated below:

# echo 1 > options/funcgraph-args
# echo function_graph > current_tracer

Before:
# time cat trace | wc -l
58098

real    0m7.514s
user    0m0.010s
sys     0m7.374s

After:
# time cat trace | wc -l
58837

real    0m0.371s
user    0m0.000s
sys     0m0.383s

This represents about 20x performance improvement for BTF type lookups.

v2:
https://lore.kernel.org/all/20251020093941.548058-1-dolinux.peng@gmail.com/

v2 -> v3:
- Remove sorting logic from libbpf and provide a generic btf__permute() interface
- Remove the search direction patch since sorted lookup provides sufficient performance
  and changing search order could cause conflicts between BTF and base BTF
- Include btf_sort.c directly in btf.c to reduce function call overhead

Donglin Peng (3):
  btf: implement BTF type sorting for accelerated lookups
  selftests/bpf: add tests for BTF type permutation
  btf: Reuse libbpf code for BTF type sorting verification and binary
    search

 kernel/bpf/btf.c                             |  34 +--
 tools/lib/bpf/btf.c                          | 262 +++++++++++++++++--
 tools/lib/bpf/btf.h                          |  17 ++
 tools/lib/bpf/btf_sort.c                     | 174 ++++++++++++
 tools/lib/bpf/btf_sort.h                     |  11 +
 tools/lib/bpf/libbpf.map                     |   6 +
 tools/lib/bpf/libbpf_version.h               |   2 +-
 tools/testing/selftests/bpf/prog_tests/btf.c | 109 ++++++--
 8 files changed, 559 insertions(+), 56 deletions(-)
 create mode 100644 tools/lib/bpf/btf_sort.c
 create mode 100644 tools/lib/bpf/btf_sort.h

-- 
2.34.1


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

end of thread, other threads:[~2025-10-29  5:04 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 13:54 [RFC PATCH v3 0/3] Significantly Improve BTF Type Lookup Performance Donglin Peng
2025-10-27 13:54 ` [RFC PATCH v3 1/3] btf: implement BTF type sorting for accelerated lookups Donglin Peng
2025-10-27 14:20   ` bot+bpf-ci
2025-10-27 18:40   ` Eduard Zingerman
2025-10-28  2:15     ` Donglin Peng
2025-10-27 19:06   ` Eduard Zingerman
2025-10-28  2:18     ` Donglin Peng
2025-10-28 18:15     ` Andrii Nakryiko
2025-10-28 18:38   ` Andrii Nakryiko
2025-10-29  5:04     ` Donglin Peng
2025-10-27 13:54 ` [RFC PATCH v3 2/3] selftests/bpf: add tests for BTF type permutation Donglin Peng
2025-10-27 18:53   ` Eduard Zingerman
2025-10-28  2:23     ` Donglin Peng
2025-10-27 13:54 ` [RFC PATCH v3 3/3] btf: Reuse libbpf code for BTF type sorting verification and binary search Donglin Peng
2025-10-27 19:55   ` Alexei Starovoitov
2025-10-29  1:57     ` Donglin Peng
2025-10-28 18:40   ` Andrii Nakryiko
2025-10-29  2:03     ` Donglin Peng

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).