mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] kfence: don't allow static keys mode on x86
@ 2026-11-28 18:22 Chris Down
  0 siblings, 0 replies; only message in thread
From: Chris Down @ 2026-11-28 18:22 UTC (permalink / raw)
  To: Alexander Potapenko, Marco Elver
  Cc: Dmitry Vyukov, Andrew Morton, Jonathan Corbet, Shuah Khan,
	Randy Dunlap, kasan-dev, linux-mm, linux-kernel, linux-doc,
	kernel-team

KFENCE can gate allocations by toggling a static key for each sample, or
by leaving the key enabled and checking an allocation gate. Static keys
mode saves a load and compare per allocation, but sends IPIs to all CPUs
each time it toggles the key, which is twice per sample interval.

On x86 the saving is too small to be worth that. 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.

So static keys mode saves about half a nanosecond per allocation at
best. At a million allocations a second on a CPU, that accounts for
0.05% of it. Toggling the key, on the other hand, takes milliseconds on
machines with hundreds of CPUs and can hurt tail latencies, which is why
commit 4f612ed3f748 ("kfence: default to dynamic branch instead of
static keys mode") made the dynamic branch the default.

Given this, let's stop offering CONFIG_KFENCE_STATIC_KEYS on x86. x86
configs that have it set will get the dynamic branch from now on. Other
architectures keep the option for now, because we don't have numbers for
them yet.

Signed-off-by: Chris Down <chris@chrisdown.name>
---
v1 at https://lore.kernel.org/r/auA7FdubFEDVPB7v@chrisdown.name

v2: Drop the boot parameter and stop offering CONFIG_KFENCE_STATIC_KEYS
    on x86 instead (Marco)

 Documentation/dev-tools/kfence.rst | 3 ++-
 lib/Kconfig.kfence                 | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/dev-tools/kfence.rst b/Documentation/dev-tools/kfence.rst
index b03d1201ddae..88acca8a00e6 100644
--- a/Documentation/dev-tools/kfence.rst
+++ b/Documentation/dev-tools/kfence.rst
@@ -264,7 +264,8 @@ through the main allocator's fast-path by relying on static branches via the
 static keys infrastructure. The static branch is toggled to redirect the
 allocation to KFENCE. Depending on sample interval, target workloads, and
 system architecture, this may perform better than the simple dynamic branch.
-Careful benchmarking is recommended.
+Careful benchmarking is recommended. This option is not available on x86, where
+it saves too little to be worth the IPIs that toggling the static branch sends.
 
 KFENCE objects each reside on a dedicated page, at either the left or right
 page boundaries selected at random. The pages to the left and right of the
diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence
index 6fbbebec683a..0b11010934b6 100644
--- a/lib/Kconfig.kfence
+++ b/lib/Kconfig.kfence
@@ -60,6 +60,7 @@ config KFENCE_DEFERRABLE
 config KFENCE_STATIC_KEYS
 	bool "Use static keys to set up allocations" if EXPERT
 	depends on JUMP_LABEL
+	depends on !X86 # Saves too little to be worth the IPI broadcasts
 	help
 	  Use static keys (static branches) to set up KFENCE allocations. This
 	  option is only recommended when using very large sample intervals, or

base-commit: 23cd682622886800b912219e307cf46a99f69c10
-- 
2.56.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-28 18:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 18:22 [PATCH v2] kfence: don't allow static keys mode on x86 Chris Down

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®