From: Donglin Peng <dolinux.peng@gmail.com>
To: andrii@kernel.org, eddyz87@gmail.com
Cc: ast@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org,
bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Donglin Peng <dolinux.peng@gmail.com>
Subject: [PATCH v4 0/3] bpf: Using binary search to improve the performance of btf_find_by_name_kind
Date: Tue, 29 Oct 2024 08:22:05 +0800 [thread overview]
Message-ID: <20241029002208.1947947-1-dolinux.peng@gmail.com> (raw)
Currently, we are only using the linear search method to find the type
id by the name, which has a time complexity of O(n). This change involves
sorting the names of btf types in ascending order and using binary search,
which has a time complexity of O(log(n)). This idea was inspired by the
following patch:
60443c88f3a8 ("kallsyms: Improve the performance of kallsyms_lookup_name()").
At present, this improvement is only for searching in vmlinux's and module's BTFs.
Another change is the search direction, where we search the BTF first and
then its base, the type id of the first matched btf_type will be returned.
Here is a time-consuming result that finding 87590 type ids by their names in
vmlinux's BTF.
Before: 158426 ms
After: 114 ms
The average lookup performance has improved more than 1000x in the above scenario.
v4:
- Divide the patch into two parts: kernel and libbpf
- Use Eduard's code to sort btf_types in the btf__dedup function
- Correct some btf testcases due to modifications of the order of btf_types.
v3:
- Link: https://lore.kernel.org/all/20240608140835.965949-1-dolinux.peng@gmail.com/
- Sort btf_types during build process other than during boot, to reduce the
overhead of memory and boot time.
v2:
- Link: https://lore.kernel.org/all/20230909091646.420163-1-pengdonglin@sangfor.com.cn
Donglin Peng (3):
libbpf: Sort btf_types in ascending order by name
bpf: Using binary search to improve the performance of
btf_find_by_name_kind
libbpf: Using binary search to improve the performance of
btf__find_by_name_kind
include/linux/btf.h | 1 +
kernel/bpf/btf.c | 157 +++++++++-
tools/lib/bpf/btf.c | 274 +++++++++++++---
tools/testing/selftests/bpf/prog_tests/btf.c | 296 +++++++++---------
.../bpf/prog_tests/btf_dedup_split.c | 64 ++--
5 files changed, 555 insertions(+), 237 deletions(-)
--
2.34.1
next reply other threads:[~2024-10-29 0:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 0:22 Donglin Peng [this message]
2024-10-29 0:22 ` [PATCH v4 1/3] libbpf: Sort btf_types in ascending order by name Donglin Peng
2024-10-29 21:58 ` Andrii Nakryiko
2024-10-30 15:12 ` Donglin Peng
2024-10-30 17:35 ` Andrii Nakryiko
2024-10-29 0:22 ` [PATCH v4 2/3] bpf: Using binary search to improve the performance of btf_find_by_name_kind Donglin Peng
2024-10-29 22:13 ` Andrii Nakryiko
2024-10-30 15:00 ` Donglin Peng
2024-10-30 17:33 ` Andrii Nakryiko
2024-10-31 11:57 ` Donglin Peng
2024-10-29 0:22 ` [PATCH v4 3/3] libbpf: Using binary search to improve the performance of btf__find_by_name_kind Donglin Peng
2024-10-29 22:15 ` Andrii Nakryiko
2024-10-30 15:24 ` 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=20241029002208.1947947-1-dolinux.peng@gmail.com \
--to=dolinux.peng@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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