Re: [PATCH] bpf/verifier: implement slab cache for verifier state list
From: Kumar Kartikeya Dwivedi
Date: Mon Jan 12 2026 - 13:15:51 EST
On Mon, 12 Jan 2026 at 13:28, wujing <realwujing@xxxxxx> wrote:
>
> The BPF verifier's state exploration logic in is_state_visited()
> frequently allocates and deallocates 'struct bpf_verifier_state_list'
> nodes to track explored states and prune the search space.
>
> Currently, these allocations use generic kzalloc(), which can lead to
> unnecessary memory fragmentation and performance overhead when
> verifying high-complexity BPF programs with thousands of potential
> states.
>
> This patch introduces a dedicated slab cache, 'bpf_verifier_state_list',
> to manage these allocations more efficiently. This provides better
> allocation speed, reduced fragmentation, and improved cache locality
> during the verification process.
>
> Summary of changes:
> - Define global 'bpf_verifier_state_list_cachep'.
> - Initialize the cache via late_initcall() in bpf_verifier_init().
> - Use kmem_cache_zalloc() in is_state_visited() to allocate new states.
> - Replace kfree() with kmem_cache_free() in maybe_free_verifier_state(),
> is_state_visited() error paths, and free_states().
>
> Signed-off-by: wujing <realwujing@xxxxxx>
> Signed-off-by: Qiliang Yuan <yuanql9@xxxxxxxxxxxxxxx>
> ---
>
Did you run any numbers on whether this improves verification performance?
Without any compelling evidence, I would leave things as-is.