Re: [PATCH bpf-next v8] selftests/bpf: trace_helpers.c: optimize kallsyms cache

From: Jiri Olsa
Date: Sun Aug 27 2023 - 05:40:01 EST


On Sun, Aug 27, 2023 at 10:48:44AM +0800, Yafang Shao wrote:
> On Sat, Aug 26, 2023 at 10:46 PM Rong Tao <rtoax@xxxxxxxxxxx> wrote:
> >
> > From: Rong Tao <rongtao@xxxxxxxx>
> >
> > Static ksyms often have problems because the number of symbols exceeds the
> > MAX_SYMS limit. Like changing the MAX_SYMS from 300000 to 400000 in
> > commit e76a014334a6("selftests/bpf: Bump and validate MAX_SYMS") solves
> > the problem somewhat, but it's not the perfect way.
> >
> > This commit uses dynamic memory allocation, which completely solves the
> > problem caused by the limitation of the number of kallsyms.
> >
> > Acked-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
> > Signed-off-by: Rong Tao <rongtao@xxxxxxxx>
> > ---
> > v8: Resolves inter-thread contention for ksyms global variables.
> > v7: https://lore.kernel.org/lkml/tencent_BD6E19C00BF565CD5C36A9A0BD828CFA210A@xxxxxx/
> > Fix __must_check macro.
> > v6: https://lore.kernel.org/lkml/tencent_4A09A36F883A06EA428A593497642AF8AF08@xxxxxx/
> > Apply libbpf_ensure_mem()
> > v5: https://lore.kernel.org/lkml/tencent_0E9E1A1C0981678D5E7EA9E4BDBA8EE2200A@xxxxxx/
> > Release the allocated memory once the load_kallsyms_refresh() upon error
> > given it's dynamically allocated.
> > v4: https://lore.kernel.org/lkml/tencent_59C74613113F0C728524B2A82FE5540A5E09@xxxxxx/
> > Make sure most cases we don't need the realloc() path to begin with,
> > and check strdup() return value.
> > v3: https://lore.kernel.org/lkml/tencent_50B4B2622FE7546A5FF9464310650C008509@xxxxxx/
> > Do not use structs and judge ksyms__add_symbol function return value.
> > v2: https://lore.kernel.org/lkml/tencent_B655EE5E5D463110D70CD2846AB3262EED09@xxxxxx/
> > Do the usual len/capacity scheme here to amortize the cost of realloc, and
> > don't free symbols.
> > v1: https://lore.kernel.org/lkml/tencent_AB461510B10CD484E0B2F62E3754165F2909@xxxxxx/
> > ---
> > samples/bpf/Makefile | 4 +
> > samples/bpf/offwaketime_user.c | 7 +-
> > samples/bpf/sampleip_user.c | 9 +-
> > samples/bpf/spintest_user.c | 7 +-
> > samples/bpf/task_fd_query_user.c | 13 +-
> > samples/bpf/trace_event_user.c | 7 +-
> > .../selftests/bpf/prog_tests/bpf_cookie.c | 7 +-
> > .../selftests/bpf/prog_tests/fill_link_info.c | 9 +-
> > .../bpf/prog_tests/get_stack_raw_tp.c | 10 +-
> > .../bpf/prog_tests/kprobe_multi_test.c | 13 +-
> > .../prog_tests/kprobe_multi_testmod_test.c | 13 +-
> > tools/testing/selftests/bpf/trace_helpers.c | 116 ++++++++++++------
> > tools/testing/selftests/bpf/trace_helpers.h | 10 +-
> > 13 files changed, 154 insertions(+), 71 deletions(-)
>
> I think we'd better split it into two patches: one for samples/bpf/
> and another for tools/testing/selftests/bpf.
>
> BTW, why can't we just load it once for all ? IOW, load the kallsyms
> before we start each individual test, and free it after all tests
> finish.

there are bpf_testmod tests that unload module so we need fresh
symbols after that

jirka