From: Eduard Zingerman <eddyz87@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>,
Donglin Peng <dolinux.peng@gmail.com>
Cc: ast@kernel.org, andrii <andrii@kernel.org>,
acme@kernel.org, daniel@iogearbox.net, mhiramat@kernel.org,
song@kernel.org, haoluo@google.com, yonghong.song@linux.dev,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v3] bpf: Using binary search to improve the performance of btf_find_by_name_kind
Date: Mon, 17 Jun 2024 15:27:07 -0700 [thread overview]
Message-ID: <90031b58d659e359aaf569565d40757b63a6b72c.camel@gmail.com> (raw)
In-Reply-To: <66e5356f-6b92-450c-b57e-7a8644a80ebf@oracle.com>
On Mon, 2024-06-17 at 15:18 +0100, Alan Maguire wrote:
[...]
> If the plan is to fold the sorting into dedup, pahole will inherit it by
> default I suppose. Would it be worth making sorting optional (or at
> least providing a way to switch if off) via a dedup_opts option? If we
> had an on/off switch we could control sorting via a --btf_features
> option to pahole.
I'd avoid adding more flags if not absolutely necessary.
> One thing we lose with sorting is that currently the base and often-used
> types tend to cluster at initial BTF ids, so in some cases linear
> searches find what they're looking for pretty quickly. Would it be worth
> maintaining a name-sorted index for BTF perhaps? That would mean not
> changing type id order (so linear search is unaffected), but for
> btf_find_by_name_kind() searches the index could be used.
Instrumented kernel code as follows:
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -555,10 +555,13 @@ s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
continue;
tname = btf_name_by_offset(btf, t->name_off);
- if (!strcmp(tname, name))
+ if (!strcmp(tname, name)) {
+ printk("btf_find_by_name_kind: kind=%d, name='%s', id=%d\n", kind, name, i);
return i;
+ }
}
+ printk("btf_find_by_name_kind: kind=%d, name='%s', id=-1\n", kind, name);
return -ENOENT;
}
And analyzed the log generated when test_progs are run.
The summary of results is as follows:
| # of lookups | kind | name | id |
|--------------+------+---------------------+--------|
| 3480 | 4 | bpf_refcount | -1 |
| 3439 | 4 | bpf_rb_root | -1 |
| 3434 | 4 | bpf_rb_node | -1 |
| 3340 | 4 | bpf_list_head | -1 |
| 3339 | 4 | bpf_list_node | -1 |
| 3165 | 4 | bpf_spin_lock | -1 |
| 759 | 4 | foo | 30 |
| 659 | 4 | bpf_cpumask | 65569 |
| 194 | 4 | prog_test_ref_kfunc | 29619 |
| 146 | 4 | bpf_spin_lock | 8 |
| 123 | 4 | bpf_list_node | 31 |
| 123 | 4 | bpf_list_head | 11 |
| 116 | 4 | bar | 38 |
| ... 59 rows, 10<N<100 lookups each ... |
| ... 227 rows, N<10 lookups each ... |
(24680 lookups in total)
I'd say that 'bpf_spin_lock', 'bpf_list_node' and 'bpf_list_head'
could be considered as types that would be found quickly by the linear
search. Their total share is ~1.6% of all lookups. I don't think we
should add a special case for such low number of "hot" cases.
Also, the share of -1 results is surprising.
[...]
prev parent reply other threads:[~2024-06-17 22:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 14:08 [RFC PATCH v3] bpf: Using binary search to improve the performance of btf_find_by_name_kind Donglin Peng
2024-06-09 7:23 ` Masami Hiramatsu
2024-06-09 16:12 ` Donglin Peng
2024-06-11 10:13 ` Eduard Zingerman
2024-06-15 11:49 ` Donglin Peng
2024-06-15 14:59 ` Donglin Peng
2024-06-17 14:18 ` Alan Maguire
2024-06-17 22:27 ` Eduard Zingerman [this message]
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=90031b58d659e359aaf569565d40757b63a6b72c.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dolinux.peng@gmail.com \
--cc=haoluo@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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