🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24908

Re: [PATCH net] ipv6: do not wait for a running gc in ip6_dst_gc()

#24908
From: David Ahern
Date: Tue, 01 Dec 2026 02:34
79 lines
11520 bytes
On 11/30/26 6:55 PM, Willem de Bruijn wrote:
> From: Chris Mason <mason@kernel.org>
> 
> With more than net.ipv6.route.gc_thresh cached routes, CPUs that
> allocate an IPv6 route while the route garbage collector runs can stall
> for as many gc runs as there are CPUs waiting, with bottom halves
> disabled.
> 
> While more than net.ipv6.route.gc_thresh cached routes exist,
> dst_alloc() calls ip6_dst_gc(), which starts a gc run, fib6_run_gc(),
> unless the last one ended less than gc_min_interval ago. A gc run holds
> fib6_gc_lock with bottom halves disabled, and sets ip6_rt_last_gc, the
> time at which the last gc run ended, only at its end. But ip6_dst_gc()
> tests ip6_rt_last_gc before it takes the lock, so each CPU that passes
> the test during a gc run spins for the lock and then starts a gc run of
> its own.
> 
> Commit 2ac3ac8f86f2 ("ipv6: prevent fib6_run_gc() contention") in v3.11
> fixed this contention, which it reported as soft lockups on a
> high-traffic router with many processors, by having ip6_dst_gc() only
> try the lock unless the number of entries exceeded max_size. Commit
> 14956643550f ("ipv6: slight optimization in ip6_dst_gc") in v3.16 made
> ip6_dst_gc() wait for the lock again in all cases, on the premise that
> the number of entries always exceeds max_size at that point. That does
> not hold once gc_min_interval has passed since the last gc run.
> 
> The fix used here is to give ip6_dst_gc() a variant of fib6_run_gc(),
> fib6_try_run_gc(), which returns at once if another CPU holds
> fib6_gc_lock, and repeats the test of ip6_rt_last_gc under the lock.
> 
> Found and fixed with an LLM; reproduced on an unmodified kernel with an
> LLM-generated reproducer in a 16-CPU KVM guest. Verified with the
> reproducer and IPv6 route selftests (fib_tests.sh, fib_nexthops.sh).
> 
> Fixes: 14956643550f ("ipv6: slight optimization in ip6_dst_gc")
> Cc: <stable@vger.kernel.org> # 6.18.x: 12eddc685744: ipv6: annotate data-races around sysctl.ip6_rt_gc_interval
> Cc: <stable@vger.kernel.org> # 6.18.x
> Signed-off-by: Chris Mason <mason@kernel.org>
> [willemb: add lockdep_assert_held() and WRITE_ONCE() on ip6_rt_last_gc,
>  expand commit message]
> Signed-off-by: Willem de Bruijn <willemb@google.com>
> ---
>  include/net/ip6_fib.h |  1 +
>  net/ipv6/ip6_fib.c    | 44 +++++++++++++++++++++++++++++++++++--------
>  net/ipv6/route.c      |  4 +++-
>  3 files changed, 40 insertions(+), 9 deletions(-)
> 

ipv4 has gc_thresh set to ~0 in its dst_ops. At this point seems like
ipv6 should be able to move in that direction.

Double checking my thinking with claude (sonnet-5.5):

IPv6 already bounds its dst cache the way IPv4 does, so the only code
change is setting the gc_thresh default to ~0 (like IPv4 does).

How IPv4 limits growth (net/ipv4/route.c)
- There is no .gc callback and ipv4_dst_ops.gc_thresh = ~0, so nothing
is enforced by dst count.
- Cached exceptions (fnhe) sit in hash buckets. On insert,
fnhe_remove_oldest() evicts entries once a bucket's depth passes a
randomized FNHE_RECLAIM_DEPTH.
- Everything else is bounded by the number of nexthops.

IPv6 already does the same
- __rt6_insert_exception() caps each bucket at a randomized
FIB6_MAX_DEPTH and evicts with rt6_exception_remove_oldest().
- Per-cpu routes are allocated DST_NOCOUNT and are bounded by nexthops.
- max_size is already INT_MAX.

The exception count per FIB entry is bounded by bucket depth times
FIB6_GC_BUCKET_SIZE, which I didn't check. The bound could still be
large with many nexthops, and the same is true for IPv4.

###

IPv6 has a timer that calls fib6_run_gc every gc_interval seconds to
control for example the RAs.
Technical Details
Message-ID: <a9387bf6-f09f-424c-a567-1a969393c7a4@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374633-linux-kernel-netdev=dewy.ru
References: <20261201015652.38202-1-willemb@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374633-linux-kernel-netdev=dewy.ru
From: dsahern@kernel.org (David Ahern)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] ipv6: do not wait for a running gc in ip6_dst_gc()
Date: Mon, 30 Nov 2026 19:34:26 -0700
Organization: Usenet Network
Message-ID: <a9387bf6-f09f-424c-a567-1a969393c7a4@kernel.org>
References: <20261201015652.38202-1-willemb@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1592251"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/dNLJLAamcUzOoj3QF/Psh/3RZw= sha256:Dc6qzB5CDBMsQAguKNGfGbWnMJtA/XcPlSHYx8d7cL8=
	sha1:BgLZ+M5rfhZuB7XTC7UbpZNSYV0= sha256:jTel50Hc7woyAGDB2CaGZFkXwhoheP3Xkgm6zTcJZVA=
Content-Language: en-US
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 08BD0118020; Tue,  1 Dec 2026 05:34:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 4-LnZUPlmUqf;
	Tue,  1 Dec 2026 05:34:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374633-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 66295C9997; Tue,  1 Dec 2026 05:34:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3E6CD29D74; Tue,  1 Dec 2026 02:34:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796092474;
	b=X5Rji/OAlepB8qm/4ThSUqPB0Uo7byag5LJR7CSR+vkjybFDGRgAJS9KcS6Qrvbj8GzM
	 JNqWduUJRd2GN+IoLQEPLWRl76Dh+cNmzUPkCKUoe/1ZUjLJdMQVsVgjsLOKjcwspML14
	 jDyfT1WqlvXKL+9cfF2gFWaF5AccjUt7et2aIi4JUTioBqjpI27Y958R5l6xxclNONQCW
	 n2rPDsu1yWG3ksA9vL5CubL6c8+3DBnNjlV7MmWnLREgBI+sqiyu0gT14P2fIZEI4ygTe
	 S0dFYoNxyTSMJUVV0ZTqlMmzw0xVbgNoolMrmzKJH/rnmAoShW2RfJYNaOGNXOcfnaQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796092474;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:Content-Language:To:Cc:References:From:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding;
	bh=k2MG6X9JN2t0GIFfz+bPz0ObWjkJP75ts/6FLNUVBEg=;
	b=gVPh4cbrIqaws3fUBWqIq4ltB5JqFmlKEN7PaqMthwrGa4Jjht2sgpifPP1HCet+WHVX
	 qPHlZiizVJdiztueXmAQo2Ke1Y02HyiRRTJwf32Y3TQgPA/rKKZsOWWYPxaGc58oXHHyZ
	 Cce8tLU+d+JcAwlBgMCJWRmfEXjgw/amp+t7gGxGafQrRl2KlP6s/rx9P9aIVr+taLMCt
	 LK2EdjOvp46yOe5RnfMVAM0hbk8kuWRd7ARJN6cKQObspX/VkzTDbldGhfXMCremt/HCG
	 kWLTN8E0MksIfJCknBJZn80FHyNlxC9YJKvkr7pqhpbcoWHX9Gsp2Ss5ewlnCP2BUQw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nIBS8wbO;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 179D7606A32C;
	Tue,  1 Dec 2026 02:34:34 +0000 (UTC)
X-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=nIBS8wbO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796092468;
	b=yMpA06AurobvjBhHicpqsZEbqAK+cG0LJROWP8HfTgYOBmqAcQF+TiDiqXTMX1bCGzXd
	 mPk2TIBn+XD6xwDYY+Tc8XTTZNNp1LamAHkz/V0XUIe0ohRHbx/zeYUfY9bJYljDUznYv
	 4APZw3BhcumhRpmRAHxvXrOlKFPEhQ2lsBemRqNf93v7Hvw4RBKha1C8vwXDBxkflOxbM
	 qrIFg3zA/3lMjRxkOhIWunTNrHXpc8nM95oGdEnf6wx9/I17JYOl2rDAWxhCU7ccdyWy/
	 q1+Tnw6882XBJyDZ4n8HelVqdqQeZEMMF0/xVflt1OLMSSxLzvF4vgrZxAFj7/5NWOw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796092468;
	h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:Content-Language:To:Cc:References:From:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding;
	bh=k2MG6X9JN2t0GIFfz+bPz0ObWjkJP75ts/6FLNUVBEg=;
	b=muwPjaG2i1gVmpTycOVXH1z+Gmo9r88Eqe3zHNXTyxoLATHtc9Q6QauSEPl1JA9J+AjC
	 6fZBrRlJ45y5RClRlbAbfNspzftxT18p+GGZBQLcMD/feE/seJrWNxXDONdprvoYPOutQ
	 M4fMDpq/uRM4P9xdgs5YgwRzhL6bNqerW6bdW4/yGsOKc74eJ6rwCZUcUVsLGa+5xinKx
	 Gt4TFWJ5PEH7XLxHIK44JJS22fDmW4hFikowlGyy+k9AnCk/JpyVh01HS4mTAcd0OYIw/
	 IrwVpdUKgXLua6jLtd+MUd6BgVWfvP+9S+pwl3dW/yiX0+MPxI7Qz1Ve/vzhk5d/Wuw==
X-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=nIBS8wbO;
	arc=none smtp.remote-ip=100.103.45.18
X-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 2DAC8606A31A;
	Tue,  1 Dec 2026 02:34:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AFC91F000C1;
	Tue,  1 Dec 2026 02:34:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796092467;
	bh=k2MG6X9JN2t0GIFfz+bPz0ObWjkJP75ts/6FLNUVBEg=;
	h=Date:Subject:To:Cc:References:From:In-Reply-To;
	b=nIBS8wbO0XIEgGHMfYxepubQNirlwptLlK2xnIV/hx/WOJItRY+zmRJBXwDB1VT6R
	 tMOjA3c/rZ7Np+D9qMbeO0KHtcFt0wkTZzkcPfzvJyBlYJNsT3WD1nbrZCvkHqmFBK
	 uqNSX+/Mk9HGqOf5Uj7qbJ4b29LQyJ+dTEgXAb2ndX1M/SM8Xe+Nmwy/DuJkx0Ssbr
	 vUEf8Zw6/x1fUTIaU5EWPXUmpMeNbZn0Nn7wyn6ibJgucje27t/HNeBwzOwaf/SIkp
	 l8ash0VlzG2xL3PcwxHA+wE3nOecntW5x/DtirXbkVPVvP3QzpBnOljCoHr0BY8K6P
	 lwc8qeiKRU5bQ==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Ido Schimmel <idosch@nvidia.com>, "David S . Miller"
 <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>,
 Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
 Simon Horman <horms@kernel.org>, Chris Mason <mason@kernel.org>,
 stable@vger.kernel.org
X-In-Reply-To: <20261201015652.38202-1-willemb@google.com>