From: Donglin Peng <dolinux.peng@gmail.com>
To: ast@kernel.org
Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	Donglin Peng <dolinux.peng@gmail.com>
Subject: [RFC PATCH v3 0/3] Significantly Improve BTF Type Lookup Performance
Date: Mon, 27 Oct 2025 21:54:20 +0800	[thread overview]
Message-ID: <20251027135423.3098490-1-dolinux.peng@gmail.com> (raw)
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
next             reply	other threads:[~2025-10-27 13:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27 13:54 Donglin Peng [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20251027135423.3098490-1-dolinux.peng@gmail.com \
    --to=dolinux.peng@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
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).