๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5076

Re: [PATCH net v6] net: schedule a purge when the defer queue rejects a free

#5076
From: Eric Dumazet
Date: Mon, 19 Oct 2026 17:58
109 lines
14041 bytes
Le lun. 19 oct. 2026 ร  19:43, Joseph Kain <jkain@nuro.ai> a รฉcrit :
>
> __skb_defer_free_flush() can leave defer_count at or above skb_defer_max
> with an empty defer_list. That state is absorbing: every producer then
> takes the nodefer path without queueing, so the list never refills.
> Deferred freeing stays off for that (cpu, node) until reboot, and
> cross-CPU frees fall back to the page allocator, which is the contention
> deferral exists to avoid.
>
> skb_attempt_defer_free() increments before testing the limit and keeps
> the increment when it rejects, so a rejected free leaves the counter
> raised with nothing queued.
>
> Nothing brings it back down. The reject path returns before
> kick_defer_list_purge(), so once the counter is stuck no producer
> schedules a flush on the owner CPU. A CPU that never raises NET_RX itself
> -- an application CPU doing TX while NIC IRQs are pinned elsewhere and
> RPS is off -- then never runs the flush at all, so clearing the counter
> inside the flush cannot help it either. proc_do_skb_defer_max() neither
> resets the counters nor schedules a flush when the limit changes.
>
> It is reachable with no race at all:
>
>   sysctl -w net.core.skb_defer_max=1    # frees increment, then reject
>   sysctl -w net.core.skb_defer_max=128  # does not recover
>
> skb_defer_max has .extra1 = SYSCTL_ZERO and no .extra2, so 1 is settable.
> From v7.1 on, 0 is safe because proc_do_skb_defer_max() flips
> skb_defer_disable_key and the producer returns before incrementing. On
> 6.18 through 7.0, which carry the llist conversion but not commit
> 08dc30de1a40 ("net: add skb_defer_disable_key static key"), setting 0 and
> restoring the previous value strands the counter the same way -- and 0 is
> the documented way to turn the feature off.
>
> Kick the purge from the reject path instead. The reject is the one place
> that observes a full queue, so scheduling the flush there is what stops
> the counter outliving the list, and it does not depend on the owner CPU
> ever raising NET_RX on its own. kick_defer_list_purge() already coalesces
> through sd->defer_ipi_scheduled, so a burst of rejects costs one IPI.
>
> This also covers the case where skb_defer_max is lowered below the
> current defer_count. The kick condition tests equality with half the
> limit, so a reduction can move that point behind the counter and no
> later producer ever reaches it; rejecting without a kick then strands a
> non-empty list the same way. The reject-path kick recovers both.
>
> While here, test the limit with > rather than >=, so the effective limit
> is skb_defer_max rather than skb_defer_max - 1, matching what
> Documentation/admin-guide/sysctl/net.rst describes.
>
> That also makes the half-capacity kick reachable at small limits. At
> skb_defer_max = 1 nothing was ever queued, so no kick was ever sent, and
> at 2 the equality was never hit; both now kick. That is what commit
> c09b0cd2cc6c ("net: avoid strange behavior with skb_defer_max == 1") set
> out to allow.
>
> Also drain before clearing in the flush. A producer that queues between
> the clear and the drain currently has its skb drained but its increment
> kept, which over-counts and costs deferral until the next flush.
> Draining first matches the ordering __dev_xmit_skb() already uses for the
> qdisc defer_list.
>
> Found by manual code inspection, LLM-assisted, while backporting the
> llist conversion to 6.1 after hitting the sd->defer_lock contention it
> removes. The latch itself was not hit in production; it was reproduced by
> lowering net.core.skb_defer_max.
>
> Fixes: 844c9db7f7f5 ("net: use llist for sd->defer_list")
> Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Joseph Kain <jkain@nuro.ai>
> ---

Say not to very verbose changelog, that nobody will read.

Since commit 844c9db7f7f5 ("net: use llist for sd->defer_list"),
skb_attempt_defer_free() increments sdn->defer_count before testing
it against skb_defer_max, and keeps the increment when it rejects.
__skb_defer_free_flush() returns early on an empty list without
clearing the counter.

With skb_defer_max == 1, every free is rejected and nothing is ever
queued, so the counter grows without bound and is never reset.
Restoring a larger skb_defer_max does not recover: deferred freeing
stays disabled for that (cpu, node) until reboot.

  sysctl -w net.core.skb_defer_max=1
  sysctl -w net.core.skb_defer_max=128   # does not recover

Test the limit with '>' instead of '>=', so that the first skb after
a reset is always queued, and a counter above the limit implies a
non-empty list that a flush will clear. This also makes the effective
limit match the documentation, and makes the half-capacity kick
reachable for skb_defer_max of 1 and 2.

When rejecting, kick the owner CPU if the list is not empty, so that
lowering skb_defer_max below the current count cannot leave the list
waiting for a NET_RX on the owner CPU that may never come.
kick_defer_list_purge() coalesces through sd->defer_ipi_scheduled.

Also clear the counter after llist_del_all() rather than before,
as __dev_xmit_skb() does, so a racing producer is under-counted
rather than over-counted.
Technical Details
Message-ID: <CAL4WiipkRkOnc_QJ51g6_9uB=pTeCSp6U8L-YVD2ytuZn4g5Qg@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348772-linux-kernel-netdev=dewy.ru
References: <20261019174258.1375583-1-jkain@nuro.ai>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348772-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6] net: schedule a purge when the defer queue rejects
 a free
Date: Mon, 19 Oct 2026 19:58:19 +0200
Organization: Usenet Network
Message-ID: <CAL4WiipkRkOnc_QJ51g6_9uB=pTeCSp6U8L-YVD2ytuZn4g5Qg@mail.gmail.com>
References: <20261019174258.1375583-1-jkain@nuro.ai>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3685837"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BcWvzA+/U7QNMZ/T7d22UQxAIOU= sha256:ohKYk8nE6nhJoXvtw8W1rXiLvdZTaavIeUwrGoWEzSA=
	sha1:gQ+XQCxvCc6oNsLxLfw8rlI8u3k= sha256:fwMtYk4OvaTpcF6rFcg5Kgme/MgW0T7LzBGZGTAfc9E=
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 DBB8F110AC9; Mon, 19 Oct 2026 21:32:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.729
X-Spam-Status: No, score=-3.729 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, 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 PdW5jRr-P4QE;
	Mon, 19 Oct 2026 21:32:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-348772-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 4917C110A35; Mon, 19 Oct 2026 21:32:12 +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 72722C62E5; Mon, 19 Oct 2026 17:58:33 +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=1792432712;
	b=UveDJiVkIY+f9IjRrl7J13R6Yfyl3YqJmYNFv+wKCx0aObVk0PZTzYqj0KjoVOJ1imcC
	 c+1btj4+tyqVQVb2CyXJDcZqMcZVDXupWOwGIFA1QRgAyt/rzUjH0On7PagsQ7SDWtx2k
	 7UjlZWqlBrFLfhoblzA1AdTOmH3ylYMI0djRjJhR0O9UyuTkIgIx6GKtXxMyx1fxRK0DP
	 RyeHuomhzHxsBWZh128wQmlVFarBr7+o6IUdXSuniNj+dln9drQucBj2l3ebbMW1Pv4lc
	 UCZQce8SJy+o/u3wYYnISY+w+uxLUj2/yX7Qtt/JGJR4LnfIFHkHgSQt7ncd59K6j5A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792432712;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=EPl+s8Alb278lktSJ9Y4SjPtdKUrddbwq+zPo72cjqg=;
	b=z5D4rtvJslyx42HSQeAaA/dTQkKr64FJriMd7KAlfrnQ58zJfd5FadzQwq8ndz9c/LYw
	 Ff4qHjiE6vVFHx3IayJ9KvMFD09QAw/OnY5sTZUKJMY31ZKiUj3AHTALR5k+SVUA99Qvx
	 aeIVxdmbfbdi3jxnkXuvcNT+jbrRsNIvm7/6y6jxAAVpC339r1mtZtaQz4ajU6f/mqrsI
	 XudI6hLBMDDdV3fD0gMN/PSo5zKeoy6nokalSZ6RsFvakHL0/isE0si+fR8t1tN1XTbBe
	 7WkSKkuybScrX0SlzeK41dEHv/tMUGYzyP/x2N8CjCOUfWCkZ49FoRQ/xfQ1HYzuDHw==
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=XTgQXl7m;
	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 CC448606A31C;
	Mon, 19 Oct 2026 17:58:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XTgQXl7m
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=1792432712;
	b=hDH8XGdIGGdczw6QpZspB/NneN+7IiYz9BpUHpXXI7K58bYzaYBJulEegci2pPzswfpO
	 LbUfk18JUZjbSFYeZhBTpmLHckAZR2uopzkhD9FQ7+sx0lwDUN2HdprtTavjd6mQpoQ0P
	 7+PcghNVKzthm6HFX58co6VLhc2K+PWXZa86pD390XiX+Qx95IbO+wwRiM5IsM3bb5MjG
	 wqRtYruOCzKKq3Xf9vEAK7bp339N2dM/X8TqqPv4s1VM84FkcAPr61Twqey3nUjBmaKas
	 UWKWc4CrrX09rWKnfQzC6ACx/i+2JlJBDFkYy4h7/JJkFe8w0rBVWZFyb8HLPDTrmsQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792432712;
	h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
	 MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=EPl+s8Alb278lktSJ9Y4SjPtdKUrddbwq+zPo72cjqg=;
	b=CwQ2THiyw+kmhlpssbmu/frzkkDAMHrAldaCir9t5EWJngxbhkwgllU505cqj7w6FvtJ
	 SPHBfvCVJnrSApR7QeTqE+si8sefmBBZnmHkQetV8sccYQ+zPRhQIiW7Vu/bbvfa0BUoA
	 KShKOVuZec/ddWV+NoJphtjHza5EL/HpPz55ZpAguDd/Mqhxns7ymTICOY4bDSfRVdqiX
	 IjUwepJu63cCB9AMahvCKoBTwyp6wWjdT3i+b1+DJi+VWk4oMUlGD5T0boDuORDjWkfUq
	 3468N6sBdZ9KHFT8XvF/1zIg+Wf92d0RXqyRSy7QZg8GrONBD0up6m28DC/bvKQPl/g==
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=XTgQXl7m;
	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 2E019606A319
	for <netdev@vger.kernel.org>; Mon, 19 Oct 2026 17:58:30 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB9BE1F000C8
	for <netdev@vger.kernel.org>; Mon, 19 Oct 2026 17:58:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792432710;
	bh=EPl+s8Alb278lktSJ9Y4SjPtdKUrddbwq+zPo72cjqg=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=XTgQXl7mU0D47HGnG/yRNo8TFDoxWECV+3EwE/DUQqW+UbkvsrbJqWECoXY7KO5F+
	 IHfVflfIaRPHdiTN7Yh2bYQjUKyGwLe5kzG6STQ7eLh4p0P5PjALiccMhpGnWEm4/a
	 ZOpJwem4xJ2vB263X/pvMVhaXTmGxqRhfPC/HPTEq+VruQk2AjlqyOkRRJjDyGrxkf
	 0Y4+mKA0HB7YwrN+XqEiGpBjdJ7h8fyeNCHD2SHMUwccv68hCfvJmTjkvjuSuvZhLr
	 pA6UwYyKAqTMFAqmDZlh+o1x6GEdyHkiaefvy/X07510aZuQJlfmNhpS9s68IY5jz5
	 LbGkxL8zRd1cg==
X-Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-4949f037131so1481009fac.3
        for <netdev@vger.kernel.org>; Mon, 19 Oct 2026 10:58:30 -0700 (PDT)
X-Gm-Message-State: AFq9FYKZ9sjmfffjJ/sHQk0yMHq9r9WzSDXCaGAWYLof5Qc9xmsKSjn+
	AC+GsVd7erveYv3hYG+RiPv/h3RyIzA1EKCE4K5CI3tHmp3b7yZ6M4sH37NIZLbLFHIfVqT5Mt7
	bKRMH349M33JtMdTsI0U700WNNhVDYOM=
X-Received: by 2002:a05:6870:3d90:b0:4a7:4a8e:237 with SMTP id
 586e51a60fabf-4a7578acf6bmr6059501fac.19.1792432710042; Mon, 19 Oct 2026
 10:58:30 -0700 (PDT)
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-In-Reply-To: <20261019174258.1375583-1-jkain@nuro.ai>
X-Gmail-Original-Message-ID: <CAL4WiipkRkOnc_QJ51g6_9uB=pTeCSp6U8L-YVD2ytuZn4g5Qg@mail.gmail.com>
X-Gm-Features: AclHuK9K2lPA1ci6HB3CJlYoscojO5J-XyHjuV9QqTl7I0JMA-hlZq3voyhM-j8
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, 
	pabeni@redhat.com, horms@kernel.org, kuniyu@google.com, 
	kerneljasonxing@gmail.com, bigeasy@linutronix.de, clrkwllms@kernel.org, 
	rostedt@goodmis.org, linux-rt-devel@lists.linux.dev, 
	linux-kernel@vger.kernel.org