Re: [PATCH] kfence: Allow selecting static keys mode at boot
From: Marco Elver
Date: Mon Nov 16 2026 - 02:00:35 EST
On Sun, 15 Nov 2026 at 00:02, Chris Down <chris@xxxxxxxxxxxxxx> wrote:
>
> 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.
Thanks for the investigation. On x86 I thought as much; I'm just not
entirely sure about other architectures, and before deletion, that
might need some investigation.
> >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.
While eventual deletion would be my preference, what you say here
doesn't make sense. "One kernel across the fleet" does not necessitate
deleting this Kconfig option from the upstream kernel. You control
your .config, and the Kconfig option is default-off nor is anyone
forced to enable it.
An intermediate step would be to e.g. not make
CONFIG_KFENCE_STATIC_KEYS selectable on certain architectures where we
are sure it causes more problems (global IPIs on systems with 100s of
CPUs) than performance improvements. We could do that for x86, and I'd
Ack that right away.