From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214663; b=Qk5+cwj/RtWS9QDyjPdhU869GhmEn3JG6VFRof7UjgzknOSYyKFMpJpRdapCiUiO8o8p LHKQADTrzTG65d1tKovdRYQPWFiO/iPuvXsIF/JHkymEhsMqOe8RBg1Gpwddvoohr3p65 l3fVNFtzHe2qm+oKGPlLWH7NKRmDh1YhhEIu4japBW+j4reWf8b2S9HoOfmNPrlYxSOkC FY2CoYSxvZKapWT0sYfvqoSvccgpncCBVCeqEGvtC8hMAshwTmJDNdHidPb7dAXOXiTci SyVuK8LwvGR1KOkdbOhtY4QByUcPdWjJHxdF+mmCD54yBivWcnVI/n8qryED97AdwZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214663; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6rU0xv6hSWpTdbzYh4cO4MqAUNJvuAhtlbrQBaG+Fas=; b=TMFMYAjvoatL7tYhLAdD6u8YHMCKarIgUE00IBKppfFBSIyYTWZIisNiQ95GGU00bjLO mVYpqcBrV0w2E9luues+Yz54oLF7WSYsxoyU2s2DVCDOUtqkb9VPHPOdNqFIkFJpGDudl kyHy63ZfLa16BsOuhNCJIC5xenV7Yb5WxtGoNiE2yRYFG1+Gjpg7E2g8x9CoBLBcfQw41 Yo4DYJ5FNzNTWIslaoeUB61y38gUzY8trvN1nf/V6dR1BGZ2935RjJ9rR5/u80bcCF1cn fqIr9kWRkUxq3JDYxph1SWjiBOQbrPVFIWdciLarI3B68OY5trIynfEIv5S00F1zpsg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OPE50CzO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E1C7606A323; Wed, 2 Dec 2026 12:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OPE50CzO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D0481F0089F; Wed, 2 Dec 2026 12:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214662; bh=6rU0xv6hSWpTdbzYh4cO4MqAUNJvuAhtlbrQBaG+Fas=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OPE50CzOrQBJ5ivx5QB4Gmdp1LySlVTAdx7CORra2M3Kl69PsYBLadwojBYWDtwF/ HblHx8pfXl/V/8fxYyA1mjFalURSPp1S82aEuJ/2OjCyLjfJdNZpeliuuFuiL+zXpK To6W3OrwDphzC33t8AXPvOl2mCMehxEVHabgG+LbzlNPWoQX37bArU4ExFgO1ChdzW eBjYYZIjdt5/eklpgdHLoJr0gO2PzO20uITUt3cRaY1QCd86OAHvooGP++4D0ITh0R L38pVRye9JDNb8Dj94OlVBXgVXQSH205sgQ3gPuNjgBHwcmaQuo0e+Qi3aQojX47bU xfd2n3eFn6AQA== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , Quentin Monnet , Alan Maguire Subject: [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Date: Wed, 2 Dec 2026 13:30:06 +0100 Message-ID: <20261202123035.10335-3-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The kprobe hash table has 64 buckets, so with 20000 probes registered each get_kprobe() call walks a chain of more than 300 entries on average. On x86 the registration path calls get_kprobe() for each byte or decoded instruction it has to check around the new probe, and most of these lookups miss and walk the whole chain. It is also called on every probe hit. This matters for attaching to inlined functions, where a few functions specified by name can end up with thousands of kprobes. Add CONFIG_KPROBE_HASH_BITS with range 6-16. The default stays at 6 and is raised to 10 (1024 buckets, 8KB on 64-bit) with CONFIG_DEBUG_INFO_BTF_INLINE. Time to register the probes with the kprobe_many_example sample module [1] in a KVM guest, mean of 5 runs: bits buckets table memory 20000 probes 50000 probes 6 64 512 B 4.71 s 29.99 s 8 256 2 KB 2.05 s 9.90 s 10 1024 8 KB 1.39 s 4.63 s 12 4096 32 KB 1.30 s 3.64 s 14 16384 128 KB 1.28 s 3.41 s 16 65536 512 KB 1.28 s 3.38 s With 10 bits the registration is 3.4 times faster for 20000 probes and 6.5 times faster for 50000 probes. Bigger tables help only with very high numbers of probes. [1] https://lore.kernel.org/bpf/20261109195827.1091410-1-jolsa@kernel.org/ Suggested-by: Masami Hiramatsu (Google) Signed-off-by: Jiri Olsa --- arch/Kconfig | 17 +++++++++++++++++ kernel/kprobes.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) 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 #include -#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) -- 2.56.1