bpf: Mitigate latency spikes associated with freeing non-preallocated htab
authorYafang Shao <laoar.shao@gmail.com>
Wed, 27 Mar 2024 03:20:22 +0000 (11:20 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 29 Mar 2024 01:31:40 +0000 (18:31 -0700)
commitee3bad033d01066348913f3220ea81987721ed53
tree1a48e38c1129daf5ac5a5a62a61a04016db06dcf
parenta461a51e519aedee8aff518167451b250ce913b3
bpf: Mitigate latency spikes associated with freeing non-preallocated htab

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>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20240327032022.78391-1-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/hashtab.c