Re: [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp

From: Xu Kuohai

Date: Fri Nov 27 2026 - 10:16:15 EST


On 11/27/2026 4:17 AM, Alexei Starovoitov wrote:
On Thu, Nov 26, 2026 at 07:02 AM Xu Kuohai <xukuohai@xxxxxxxxxxxxxxx> wrote:
After further profiling, I found that this collapse is
mainly caused by Firecracker instances queuing on the
global pack_mutex in bpf_prog_pack_alloc(). So a better
approach is to replace the global mutex to per-pack locks.
I will work on that instead.

Makes sense to fix it there. Every prog load benefits.
But I doubt that per-pack locks help.
bpf_prog_pack_alloc() walks pack_list from the head and takes the first
pack that has room. All loaders pick the same pack and queue on its lock.

I suspect the hold time comes from these:

path under pack_mutex what it does
----- -------------------------- --------------------------------
alloc bpf_arch_pred_flush() x86: IBPB via on_each_cpu()
free bpf_arch_text_invalidate() x86: text_poke_set(), text_mutex
free bpf_arch_text_invalidate() arm64: kick_all_cpus_sync()

Every free marks its pack dirty. A cBPF alloc from a dirty pack flushes.
The log of commit a9b1f19a6a67 ("bpf: Prefer packs that won't trigger
an IBPB flush on allocation") has ideas how to flush less.

bpf_arch_text_invalidate() doesn't need pack_mutex. The bits of the
chunks are still set in pack->bitmap at that point, so nobody can take
the chunks or free the pack.

What do you see in your profile?

Hi Alexei,

You are correct.

The benchmark server is arm64. The lock hold times in bpf_prog_pack_alloc()
and bpf_prog_pack_free() are typically 8–16 us and 256–512 us, respectively.

The free path is dominated by bpf_arch_text_invalidate(), which sends IPIs
to all CPUs and waits for completion. The wait happens after put_cpu(), so
the task is preemptible. If the task is preempted, other lock waiters remain
blocked until it is scheduled back and releases the lock. This can extend
the lock hold time to seconds.

Below is a sample of the captured preemption stack:

-> bpf_prog_pack_free
-> bpf_arch_text_invalidate
-> aarch64_insn_set
-> __text_poke
-> kick_all_cpus_sync
-> smp_call_function_many_cond
-> el1h_64_irq
-> el1h_64_irq_handler
-> el1_interrupt
-> arm64_exit_to_kernel_mode_preempt
-> irqentry_exit_cond_resched
-> preempt_schedule_irq
-> __schedule

After moving bpf_arch_text_invalidate() out of pack_mutex, the p99 VM
startup latency drops from 2.79 s to 170 ms under the same workload.

I will post the patch once it is ready.