Re: [PATCHv2 1/2] kprobes: Increase the kprobe hash table size
From: Jiri Olsa
Date: Wed Nov 25 2026 - 17:05:41 EST
On Wed, Nov 25, 2026 at 11:21:20PM +0900, Masami Hiramatsu (Google) wrote:
SNIP
> > > If this change is intended solely to improve performance for an extremely
> > > unlikely use case, I would, at the very least, make the size configurable
> > > via Kconfig.
> > >
> > > Since this change affects all architectures, those working with small,
> > > embedded-system chips might be reluctant to "pay" 32 KB for a use case
> > > that is highly unlikely to ever occur.
> >
> > I can add CONFIG_KPROBE_HASH_BITS with range 6-16. I'd keep 6 for
> > CONFIG_BASE_SMALL, so small systems don't pay anything, and use
> > 10 (8KB on 64-bit) as the default otherwise, which gets most of the
> > speedup from the table in the changelog
>
> That is good. If you introduce the inline function support which is
> enabled by some kconfig, that kconfig can increase the hash bits. That
> should be more reasonable.
yes, good idea, something like below, I'll send that as part of the
inline tracing changes
thanks,
jirka
---
diff --git a/arch/Kconfig b/arch/Kconfig
index 1163736de1f9..350144df6863 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -141,6 +141,23 @@ config KPROBES
for kernel debugging, non-intrusive instrumentation and testing.
If in doubt, say "N".
+config KPROBE_HASH_BITS
+ int "Kprobe hash table size in bits" if EXPERT
+ depends on KPROBES
+ range 6 16
+ default 10 if DEBUG_INFO_BTF_INLINE
+ default 6
+ help
+ Size of the kprobe hash table as a power of two. The default
+ of 6 (64 buckets) is enough for a small number of probes.
+
+ Attaching to inlined functions can register thousands of
+ kprobes at once, so the default is raised to 10 (1024 buckets,
+ 8KB on 64-bit) when the inline site information is available
+ (DEBUG_INFO_BTF_INLINE).
+
+ If in doubt, keep the default.
+
config JUMP_LABEL
bool "Optimize very unlikely/likely branches"
depends on HAVE_ARCH_JUMP_LABEL
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f14f7ff45961..eba446e8ae37 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -50,7 +50,7 @@
#include <asm/errno.h>
#include <linux/uaccess.h>
-#define KPROBE_HASH_BITS 6
+#define KPROBE_HASH_BITS CONFIG_KPROBE_HASH_BITS
#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
#if !defined(CONFIG_OPTPROBES) || !defined(CONFIG_SYSCTL)