Re: [PATCH] kfence: Allow selecting static keys mode at boot
From: Chris Down
Date: Sat Nov 14 2026 - 18:02:42 EST
Hi Marco,
Marco Elver writes:
On which systems have you found static keys to provide a significant
improvement? Can you share benchmarks?
I don't have numbers that show a significant improvement. To be clear,
the hosts that use static keys have had it set that way since long
before I started looking at this, so it may well just be cargo culted
by now :-) Given that, I had a go at measuring the saving on its own.
It's there, but it's small.
From a quick check I did in an 8 CPU x86 VM, a
kmem_cache_alloc()/kmem_cache_free() pair takes 8.0ns in static keys
mode, which is the same as with KFENCE off. With the dynamic branch it
takes 8.4ns. A kmalloc()/kfree() pair takes 13.3ns in all three. Both
are the same with either branch layout.
So static keys saves about half a nanosecond per allocation at best, in
a loop that does nothing else. At a million allocations a second on a
CPU, that accounts for 0.05% of it.
IMHO, I was thinking of deleting the CONFIG_KFENCE_STATIC_KEYS mode,
because on most systems, it's not worth the complexity for the small
(if any) performance improvement anymore.
I agree, and I think the numbers above are enough evidence for that.
Deleting it is better than this patch, because all we want is one kernel
across the fleet, and that gets us there with less code. I'm happy to
send the removal, if you'd like.
Thanks!
Chris