From: Yonghong Song <yonghong.song@linux.dev>
To: Yafang Shao <laoar.shao@gmail.com>,
ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] bpf: Mitigate latency spikes associated with freeing non-preallocated htab
Date: Tue, 26 Mar 2024 09:50:04 -0700 [thread overview]
Message-ID: <8caa200a-f8a4-4381-9269-da706a22f990@linux.dev> (raw)
In-Reply-To: <20240326081207.73375-1-laoar.shao@gmail.com>
On 3/26/24 1:12 AM, Yafang Shao wrote:
> Following the recent upgrade of one of our BPF programs, we encountered
> significant latency spikes affecting other applications running on the same
> host. After thorough investigation, we identified that these spikes were
> primarily caused by the prolonged duration required to free a
> non-preallocated htab with approximately 2 million keys.
>
> Notably, our kernel configuration lacks the presence of CONFIG_PREEMPT. In
> scenarios where kernel execution extends excessively, other threads might
> be starved of CPU time, resulting in latency issues across the system. To
> mitigate this, we've adopted a proactive approach by incorporating
> cond_resched() calls within the kernel code. This ensures that during
> lengthy kernel operations, the scheduler is invoked periodically to provide
> opportunities for other threads to execute.
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
> kernel/bpf/hashtab.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 3a088a5349bc..d3d5aad045cc 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -1489,6 +1489,7 @@ static void delete_all_elements(struct bpf_htab *htab)
> hlist_nulls_for_each_entry_safe(l, n, head, hash_node) {
> hlist_nulls_del_rcu(&l->hash_node);
> htab_elem_free(htab, l);
> + cond_resched();
> }
should we put cond_resched() here inside the top 'for' loop, but outside
the bucket loop? Do you really have a long link list for a particular bucket?
Otherwise, the patch looks good to me. In hashtab.c, we have cond_resched()
in some other places to mitigate similar issues.
> }
> migrate_enable();
next prev parent reply other threads:[~2024-03-26 16:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 8:12 [PATCH bpf-next] bpf: Mitigate latency spikes associated with freeing non-preallocated htab Yafang Shao
2024-03-26 16:50 ` Yonghong Song [this message]
2024-03-27 3:05 ` Yafang Shao
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=8caa200a-f8a4-4381-9269-da706a22f990@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.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