Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v4 0/3] bpf: Using binary search to improve the performance of btf_find_by_name_kind
@ 2024-10-29  0:22 Donglin Peng
  2024-10-29  0:22 ` [PATCH v4 1/3] libbpf: Sort btf_types in ascending order by name Donglin Peng
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Donglin Peng @ 2024-10-29  0:22 UTC (permalink / raw)
  To: andrii, eddyz87
  Cc: ast, rostedt, mhiramat, bpf, linux-trace-kernel, linux-kselftest,
	linux-kernel, Donglin Peng

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


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

end of thread, other threads:[~2024-10-31 11:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-29  0:22 [PATCH v4 0/3] bpf: Using binary search to improve the performance of btf_find_by_name_kind Donglin Peng
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox