From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: Re: [PATCH bpf-next v2 2/2] bpf: use realloc in bpf_patch_insn_data
Date: Thu, 7 Aug 2025 16:02:06 +0000 [thread overview]
Message-ID: <aJTN/rQxfyr5BjVk@mail.gmail.com> (raw)
In-Reply-To: <20250807010205.3210608-3-eddyz87@gmail.com>
On 25/08/06 06:02PM, Eduard Zingerman wrote:
> Avoid excessive vzalloc/vfree calls when patching instructions in
> do_misc_fixups(). bpf_patch_insn_data() uses vzalloc to allocate new
> memory for env->insn_aux_data for each patch as follows:
>
> struct bpf_prog *bpf_patch_insn_data(env, ...)
> {
> ...
> new_data = vzalloc(... O(program size) ...);
> ...
> adjust_insn_aux_data(env, new_data, ...);
> ...
> }
>
> void adjust_insn_aux_data(env, new_data, ...)
> {
> ...
> memcpy(new_data, env->insn_aux_data);
> vfree(env->insn_aux_data);
> env->insn_aux_data = new_data;
> ...
> }
>
> The vzalloc/vfree pair is hot in perf report collected for e.g.
> pyperf180 test case. It can be replaced with a call to vrealloc in
> order to reduce the number of actual memory allocations.
Given that I am in any case looking at the code around,
I've rebased on top of this change and tested it:
Tested-by: Anton Protopopov <a.s.protopopov@gmail.com>
> This is a stop-gap solution, as bpf_patch_insn_data is still hot in
> the profile. More comprehansive solutions had been discussed before
> e.g. as in [1].
>
> [1] https://lore.kernel.org/bpf/CAEf4BzY_E8MSL4mD0UPuuiDcbJhh9e2xQo2=5w+ppRWWiYSGvQ@mail.gmail.com/
>
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
[snip]
next prev parent reply other threads:[~2025-08-07 15:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 1:02 [PATCH bpf-next v2 0/2] bpf: use vrealloc() in bpf_patch_insn_data() Eduard Zingerman
2025-08-07 1:02 ` [PATCH bpf-next v2 1/2] bpf: removed unused 'env' parameter from is_reg64 and insn_has_def32 Eduard Zingerman
2025-08-07 15:26 ` Kumar Kartikeya Dwivedi
2025-08-07 1:02 ` [PATCH bpf-next v2 2/2] bpf: use realloc in bpf_patch_insn_data Eduard Zingerman
2025-08-07 16:00 ` Kumar Kartikeya Dwivedi
2025-08-07 16:02 ` Anton Protopopov [this message]
2025-08-07 16:20 ` [PATCH bpf-next v2 0/2] bpf: use vrealloc() in bpf_patch_insn_data() patchwork-bot+netdevbpf
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=aJTN/rQxfyr5BjVk@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.