linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/5] Significantly Improve BTF Type Lookup Performance
@ 2025-10-20  9:39 Donglin Peng
  2025-10-20  9:39 ` [RFC PATCH v2 1/5] btf: search local BTF before base BTF Donglin Peng
                   ` (4 more replies)
  0 siblings, 5 replies; 32+ messages in thread
From: Donglin Peng @ 2025-10-20  9:39 UTC (permalink / raw)
  To: ast; +Cc: linux-kernel, bpf, Donglin Peng

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

This patch series optimizes btf_find_by_name_kind() by:
1. Sorting BTF types by kind and name to enable binary search
2. Changing the search order to check local BTF before base BTF

Performance testing shows dramatic improvement:

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

Before:
 # time cat trace | wc -l
 124176
 real    0m16.154s
 user    0m0.000s
 sys     0m15.962s

After:
 # time cat trace | wc -l
 124176
 real    0m0.948s
 user    0m0.000s
 sys     0m0.973s

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


Donglin Peng (5):
  btf: search local BTF before base BTF
  btf: sort BTF types by kind and name to enable binary search
  libbpf: check if BTF is sorted to enable binary search
  selftests/bpf: add tests for BTF deduplication and sorting
  btf: add CONFIG_BPF_SORT_BTF_BY_KIND_NAME

 include/linux/btf.h                          |  21 ++-
 kernel/bpf/Kconfig                           |   8 +
 kernel/bpf/Makefile                          |   1 +
 kernel/bpf/btf.c                             |  36 ++--
 kernel/bpf/btf_sort.c                        |   2 +
 scripts/Makefile.btf                         |   5 +
 tools/lib/bpf/Build                          |   2 +-
 tools/lib/bpf/btf.c                          | 169 +++++++++++++++---
 tools/lib/bpf/btf.h                          |   2 +
 tools/lib/bpf/btf_sort.c                     | 159 +++++++++++++++++
 tools/lib/bpf/libbpf_internal.h              |   6 +
 tools/testing/selftests/bpf/prog_tests/btf.c | 171 +++++++++++++++++++
 12 files changed, 541 insertions(+), 41 deletions(-)
 create mode 100644 kernel/bpf/btf_sort.c
 create mode 100644 tools/lib/bpf/btf_sort.c

-- 
2.34.1


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

end of thread, other threads:[~2025-10-24  3:20 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20  9:39 [RFC PATCH v2 0/5] Significantly Improve BTF Type Lookup Performance Donglin Peng
2025-10-20  9:39 ` [RFC PATCH v2 1/5] btf: search local BTF before base BTF Donglin Peng
2025-10-21  1:06   ` Eduard Zingerman
2025-10-21  8:31     ` Donglin Peng
2025-10-21 15:56       ` Eduard Zingerman
2025-10-22  3:08         ` Donglin Peng
2025-10-20  9:39 ` [RFC PATCH v2 2/5] btf: sort BTF types by kind and name to enable binary search Donglin Peng
2025-10-21 17:24   ` Alan Maguire
2025-10-22  4:47     ` Donglin Peng
2025-10-21 18:59   ` Eduard Zingerman
2025-10-22  3:02     ` Donglin Peng
2025-10-22 20:50       ` Eduard Zingerman
2025-10-23 10:35         ` Donglin Peng
2025-10-23 15:52           ` Alexei Starovoitov
2025-10-23 16:28             ` Andrii Nakryiko
2025-10-23 18:37               ` Alexei Starovoitov
2025-10-23 19:39                 ` Andrii Nakryiko
2025-10-24  1:59                   ` Donglin Peng
2025-10-24  2:23                     ` Donglin Peng
2025-10-24  2:32                       ` Eduard Zingerman
2025-10-24  3:04                         ` Donglin Peng
2025-10-24  3:15                           ` Eduard Zingerman
2025-10-24  3:19                             ` Donglin Peng
2025-10-20  9:39 ` [RFC PATCH v2 3/5] libbpf: check if BTF is sorted " Donglin Peng
2025-10-20  9:39 ` [RFC PATCH v2 4/5] selftests/bpf: add tests for BTF deduplication and sorting Donglin Peng
2025-10-21 19:07   ` Eduard Zingerman
2025-10-23 11:20     ` Donglin Peng
2025-10-20  9:39 ` [RFC PATCH v2 5/5] btf: add CONFIG_BPF_SORT_BTF_BY_KIND_NAME Donglin Peng
2025-10-21  0:50   ` Eduard Zingerman
2025-10-21  8:33     ` Donglin Peng
2025-10-21 17:27   ` Alan Maguire
2025-10-22  1:15     ` 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).