BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Mitigate latency spikes associated with freeing non-preallocated htab
@ 2024-03-26  8:12 Yafang Shao
  2024-03-26 16:50 ` Yonghong Song
  0 siblings, 1 reply; 3+ messages in thread
From: Yafang Shao @ 2024-03-26  8:12 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, Yafang Shao

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();
 		}
 	}
 	migrate_enable();
-- 
2.30.1 (Apple Git-130)


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

end of thread, other threads:[~2024-03-27  3:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-03-27  3:05   ` Yafang Shao

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