From nobody Wed Nov 25 17:40:04 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=129.217.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795620228; b=ljEQKhdi14c/xsWSPoUZq43qiDZduTP7OPUig3YpgipUSJx6mTuZlsG64VHpl2K5Kka1 NmvagpiDNGoS+X58X/91XPfCRpxyvTuBrAhvng4hdxKQgVb5KyCvRiUVNIvtgxTLnm/Kr g2xzbFSaSgiQhVicS6wXCKVor0hH6YVKEd/0Km3NI1gD/AjF1x1c+PqtOQXwAtrevP2YB sNEauj6/k/ZGuy/DFmzVFI38LEcAyvxhlXVXlvZnrX5Th1tle4tCiw98EwT4frHph+qWK aW/zEsrFfFK7yI5rFquBsFANopna4YxOXzGBXkc6VB+DjixhUmHAHjjf/8ZWKm1jTqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795620228; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=SC6SmwcOlRX4TMShN4/z5oFu7ovHE/zxGHPprunnak4=; b=b07eff3y7sgKZ1HeqhacBMzcPvIZV/ex6V5na9VcIFX06BoJyg3z0bDFqlyPF/FdwMjv SOotbwBbhREzN2Lx/10CaguZ2DVe+tRlbD2bQ/TWsnK0/mqAOvG2JB0cTZi49H5jvh0hb utAXqxfkCc03M2AQk7+30wmvEka50b4DojrmkPL0CVLsti/HoMxE1j6+wojqbi8PEJsLV AdaAZ3uhRq+9XYr/s1USC4jasog0m+vBdWUQ0DVvd6ZVdp3m9gSC/hpw3SVjhlLFZu6EU IrG1lsBvZSCbVLrlquZ/JYbfmB6F0cJk2fqwyBYUw5syMqWklFLqSr16kPlGufbhtuw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=tu-dortmund.de; spf=pass smtp.mailfrom=tu-dortmund.de; dkim=pass header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=V+LxSgX+; arc=none smtp.remote-ip=129.217.128.51 Received: from unimail.uni-dortmund.de (mx1.hrz.uni-dortmund.de [129.217.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AA28606A323; Wed, 25 Nov 2026 15:23:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8AA28606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=V+LxSgX+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tu-dortmund.de; s=unimail; t=1795620198; bh=SC6SmwcOlRX4TMShN4/z5oFu7ovHE/zxGHPprunnak4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V+LxSgX+xOIGZKNib5pjO6K9VDNuowVOl3A9tvaUAg8D4bIdEXr4w9BVkbNfpKzK+ e9D8yq/Sx9zz8wwRgyZtt8F8WJ+bT6MpXvptSn1HIYJCBMbp/koMDX2bg8NQaUaEHb PQv1QiViB8LXTIvM0WkHfWq+4KVqoPUSFtG9aGbc= Received: from simon-Latitude-5450.cni.e-technik.tu-dortmund.de ([129.217.186.207]) (authenticated bits=0) by unimail.uni-dortmund.de (8.19.0.2/8.19.0.2) with ESMTPSA id 6APFNERM004665 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 25 Nov 2026 16:23:17 +0100 (CET) From: Simon Schippers To: netdev@vger.kernel.org Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Tim Gebauer , =?UTF-8?q?Jonas=20K=C3=B6ppeler?= , "Michael S. Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Stanislav Fomichev , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Schippers Subject: [PATCH net-next 1/3] ptr_ring: add PTR_RING_BATCH Date: Wed, 25 Nov 2026 16:23:09 +0100 Message-ID: <20261125152311.805325-2-simon.schippers@tu-dortmund.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> References: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> X-Mailing-List: linux-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: quoted-printable Content-Type: text/plain; charset="utf-8" Name the batch size in which the consumer frees entries, so that users of a ring can size their own work to it. The next patch uses it in veth. No functional change. Signed-off-by: Simon Schippers --- include/linux/ptr_ring.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h index 631c43fde4407..b851a9c170bf6 100644 --- a/include/linux/ptr_ring.h +++ b/include/linux/ptr_ring.h @@ -27,6 +27,11 @@ #include #endif =20 +/* Consumed entries are freed in batches of this size, unless the ring is + * smaller than two batches + */ +#define PTR_RING_BATCH (SMP_CACHE_BYTES * 2 / (int)sizeof(void *)) + struct ptr_ring { int producer ____cacheline_aligned_in_smp; spinlock_t producer_lock; @@ -506,7 +511,7 @@ static inline void **__ptr_ring_init_queue_alloc_noprof= (unsigned int size, gfp_t static inline void __ptr_ring_set_size(struct ptr_ring *r, int size) { r->size =3D size; - r->batch =3D SMP_CACHE_BYTES * 2 / sizeof(*(r->queue)); + r->batch =3D PTR_RING_BATCH; /* We need to set batch at least to 1 to make logic * in __ptr_ring_discard_one work correctly. * Batching too much (because ring is small) would cause a lot of --=20 2.43.0 From nobody Wed Nov 25 17:40:04 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=129.217.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795620227; b=3OF9W/YxNj4oMWu67bRfpD68sLNJtW/hRU2/VZiUv7vtlDhi1czIcLmTTEcnEveGMUwX O40yGdVI7LlX6Mps8PJDzAvC1LHz0e/Ig6Qzh2/jVJtjIlJDug9JGMU1uOFmZrf1Mh0pP jIxO21OQmIAXxJjZvSTAuZqHJ5IRnVcZMxx5V8am+Th+nMadwx9n807ecINX578Gw+8vC 2G19QU5XMzlgMl5kbIxIUYDJuXye9+wIJYcZIjys6LbdBNtJS2lOO3rq4Ff42JpeRUvaR bTIV40sOYBnPUewjBozkJD3aXrcjdQEPLT62phWk2DhDfBkgCBp9KwPf4VpekKA7FsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795620227; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=7lqxMl9LQqYx+IM7aMsw8LkEd2OcKYcJGIX+toZz4gI=; b=op5NpzzqFCKumc9maH+E4j1z/MdraJWug5LNr5p9y5+0SHPJ0qeU7/Sp/GKWw3G8rCqU vaIs9NH5DKSGrdNURbq9IQmYAB523zGzkR/nuiPatzGU2x8xfqdyZdQMM/laVNPuXXlz9 MuYPpyQ1REncsgDfNrnluXYrwSAkkI8QC/hxbiKLtNij0TAgawLuyYVVon0HKi0z4v6gE aut46r3FKjn4iJMm7oKhJjKBwkGlfeYy1arg7c+8418hF2A1pik7vZ8iELnzNt1RyVhI/ aAf0n+tst44uOs1JkaKaMqR5ZBgQnEGWwzahSVfAGZJIHShf7TqxIXtUZxzlQX/p1VQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=tu-dortmund.de; spf=pass smtp.mailfrom=tu-dortmund.de; dkim=pass header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=oMXXhGa6; arc=none smtp.remote-ip=129.217.128.51 Received: from unimail.uni-dortmund.de (mx1.hrz.uni-dortmund.de [129.217.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A87F606A31E; Wed, 25 Nov 2026 15:23:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A87F606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=oMXXhGa6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tu-dortmund.de; s=unimail; t=1795620200; bh=7lqxMl9LQqYx+IM7aMsw8LkEd2OcKYcJGIX+toZz4gI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oMXXhGa6Pz9YwLcLMEvsUzRfNd0vuSx8r6LH1gd0iYeAIV/qUnfZuC93MhGTMATu6 j+hSIpontklgWBjGbD4qdumPffr1vHuSv71LBY8dwyzWxOijFFrShIUizV0LT/JwMM KJ/ArCASgkDC83da9jbglh3nbXCIOnJ0aTKIJ0qs= Received: from simon-Latitude-5450.cni.e-technik.tu-dortmund.de ([129.217.186.207]) (authenticated bits=0) by unimail.uni-dortmund.de (8.19.0.2/8.19.0.2) with ESMTPSA id 6APFNERO004665 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 25 Nov 2026 16:23:18 +0100 (CET) From: Simon Schippers To: netdev@vger.kernel.org Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Tim Gebauer , =?UTF-8?q?Jonas=20K=C3=B6ppeler?= , "Michael S. Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Stanislav Fomichev , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Schippers Subject: [PATCH net-next 2/3] veth: wake the peer txq in the middle of the NAPI poll Date: Wed, 25 Nov 2026 16:23:10 +0100 Message-ID: <20261125152311.805325-3-simon.schippers@tu-dortmund.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> References: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> X-Mailing-List: linux-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: quoted-printable Content-Type: text/plain; charset="utf-8" Since commit dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to reduce TX drops") veth_poll() wakes a stopped peer txq at the end of every poll. netif_tx_wake_queue() raises NET_TX_SOFTIRQ on the local CPU, and it runs right after the poll when BHs are enabled again. The consumer CPU then dequeues from the qdisc and refills the ring itself, while the producer finds the qdisc running or the txq stopped again. Under a flood the consumer spends that time on the refill instead of on consuming. Wake the txq after PTR_RING_BATCH entries of the poll instead, if it was stopped when the poll started. That is 16 on 64-bit architectures with 64 byte cache lines. The softirq then stays pending until the poll ends, and the producer refills the ring on its own CPU while the consumer goes on. All entries consumed by then were consumed after the stop, so the ptr_ring has freed at least one batch of slots and the producer does not find it full again right away. At the end of the poll the txq is woken only when the ring has run dry, so that NAPI does not go idle with the txq stopped. A stop during a poll is picked up by the next one. Budgets up to PTR_RING_BATCH, as with busy polling, cannot consume a batch before the wake and keep the wake at the end of every poll. The position of the wake is what matters. Waking only at the end of a poll, once 128 entries had been consumed with the txq stopped, gave about 3% in a short pktgen test, against about 25% for the wake in the middle of the poll. pktgen (64 byte UDP, queue_xmit) and iperf3 into fq_codel on a veth pair with GRO on and TSO off, so that all traffic takes the NAPI ptr_ring path, as with an XDP program on the peer. In a virtme-ng VM with 4 vCPUs pinned to isolated cores of an AMD Ryzen 9 9950X, all on the same CCX, at a fixed 4.3 GHz. 50 boots per kernel, 95% confidence intervals, with the qdisc requeues per 10 s run: threaded NAPI before after requeues pktgen 1078122 pps +24.6 +-0.5% 169038 -> 210594 iperf3 TCP 32682 Mbit/s +1.3 +-0.7% 579184 -> 4587 iperf3 UDP 362 Mbit/s +0.2 +-0.5% 14 -> 14 pktgen requeues one skb per 64 packets, before and after. The next patch removes these requeues. With softirq NAPI and a single sender the consumer runs on the sender's CPU and the ring does not fill. The changes of pktgen and iperf3 there range from -0.7% to +0.4%, with confidence intervals of 0.4% to 0.9%. With two iperf3 senders on one queue, each on its own CPU, the ring fills with softirq NAPI too. 40 boots per kernel, 6 vCPUs: two senders before after requeues TCP, softirq 25798 Mbit/s +52.1 +-0.9% 6024998 -> 799805 TCP, threaded 22480 Mbit/s +16.4 +-1.8% 6741008 -> 5910785 UDP, threaded 701 Mbit/s +14.4 +-0.5% 152298 -> 81520 With softirq NAPI, TCP through fq_codel was 36% slower than with noqueue before and is 2% slower after. A wake after 32 entries instead of 16 gave the same throughput, except for TCP with two senders and threaded NAPI, which gained only 8.3%. Signed-off-by: Simon Schippers --- drivers/net/veth.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 2051f6e044327..02ffc7ba59ab2 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -912,11 +912,19 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_r= q *rq, =20 static int veth_xdp_rcv(struct veth_rq *rq, int budget, struct veth_xdp_tx_bq *bq, - struct veth_stats *stats) + struct veth_stats *stats, + struct netdev_queue *peer_txq) { - int i, done =3D 0, n_xdpf =3D 0; + int i, done =3D 0, n_xdpf =3D 0, wake_at =3D 0; void *xdpf[VETH_XDP_BATCH]; =20 + /* Wake a stopped peer txq in the middle of the poll, so that the + * producer refills the ring while this poll goes on. + */ + if (budget > PTR_RING_BATCH && peer_txq && + netif_tx_queue_stopped(peer_txq)) + wake_at =3D PTR_RING_BATCH; + for (i =3D 0; i < budget; i++) { void *ptr =3D __ptr_ring_consume(&rq->xdp_ring); =20 @@ -952,6 +960,11 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget, } } done++; + + if (done =3D=3D wake_at) { + txq_trans_cond_update(peer_txq); + netif_tx_wake_queue(peer_txq); + } } =20 if (n_xdpf) @@ -988,7 +1001,7 @@ static int veth_poll(struct napi_struct *napi, int bud= get) netdev_get_tx_queue(peer_dev, queue_idx) : NULL; =20 xdp_set_return_frame_no_direct(); - done =3D veth_xdp_rcv(rq, budget, &bq, &stats); + done =3D veth_xdp_rcv(rq, budget, &bq, &stats, peer_txq); =20 if (stats.xdp_redirect > 0) xdp_do_flush(); @@ -1007,9 +1020,13 @@ static int veth_poll(struct napi_struct *napi, int b= udget) } } =20 - /* Release backpressure per NAPI poll */ + /* Release backpressure before NAPI may go idle, and after every poll + * that veth_xdp_rcv() cannot wake in the middle of + */ smp_rmb(); /* Paired with netif_tx_stop_queue set_bit */ - if (peer_txq && netif_tx_queue_stopped(peer_txq)) { + if (peer_txq && netif_tx_queue_stopped(peer_txq) && + (budget <=3D PTR_RING_BATCH || done < budget || + __ptr_ring_empty(&rq->xdp_ring))) { txq_trans_cond_update(peer_txq); netif_tx_wake_queue(peer_txq); } --=20 2.43.0 From nobody Wed Nov 25 17:40:04 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=129.217.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795620227; b=b+FI0rIelTaiD0bNpAri6NLsQ7bVVL9rfCLeJJRpNy5t1hD+yEH/Zs8yHrMKmYkvC0dc dyZWuWvsYNKymfiPLLupJky1nbLVmE+JQM/5aY9n49H/syFg8ilj9828kAYafO00m/Gwr p0KbH1rQJOH15uIFn9oCFaBao4F/m4ZpGaNJRk+IESLfvDOzVoq5CEgFx7bup/MM1JulW 7MzBsUdP1OFDcddZPpqVl7nAlH4FRwTLyf08spcZvn2v8uSPWXubLemOmsBjd0LgMqr3m nqVEFxxA3eZ3SE0L+zBBYLBe1nm9jeRnLcUnuR/FCkG0a/PEEqzZaAy2SesozBI2+Ag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795620227; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=i8WL8KVOFFwJaUNqpb8Y5QPC+4OxinZ301w/l2clA6k=; b=L1PS9jrKZ094piofFM+kGtnLuRp2dLiRxLx76/E/+Kw9XzgBTEW1fr6lH4UjQRy6wmL2 bsWHMb9nIYj1X190LrwETlCL4s8eN2eU8AnGa1+WGlo3gx+6JS2GikNNENnTcmMR0a/V0 r65dQjDWcIpeElbK9HoKsEEZpJD5wjEBEdiGNNvSenLOjmTdjiCxc7T9JKN2lLS53gRkS gStFYY2gvlC8Hkbqwf7Jien3U/Lksb5okJy+cXJyPVH35yP4nBU1tvp+ePO8IihGyxgcJ EhEmMFHQ5Cgg8yD/z2Dp2nF6A7LPD0EMQ3qDncY9W6PlTvvuGlkO/4NeSz9IYXfVioA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=tu-dortmund.de; spf=pass smtp.mailfrom=tu-dortmund.de; dkim=pass header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=FPnoMXV9; arc=none smtp.remote-ip=129.217.128.51 Received: from unimail.uni-dortmund.de (mx1.hrz.uni-dortmund.de [129.217.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DE76606A321; Wed, 25 Nov 2026 15:23:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DE76606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=tu-dortmund.de header.i=@tu-dortmund.de header.a=rsa-sha256 header.s=unimail header.b=FPnoMXV9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tu-dortmund.de; s=unimail; t=1795620201; bh=i8WL8KVOFFwJaUNqpb8Y5QPC+4OxinZ301w/l2clA6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FPnoMXV90YdHIuiVRrB5NvAJOaRLZrtwR3WQMGS2T3cQOtnSZylxpMIlYxfEgn/n0 6OFqx1iZxrs3t5pR7BUwjALRyKcnefWnuteKLxqBhsnmB9aFDb0FYAyKW0LHVFC/0O UuH/DzJw/CniCOyfQXFNriMS+yuspOB97sh8+b+g= Received: from simon-Latitude-5450.cni.e-technik.tu-dortmund.de ([129.217.186.207]) (authenticated bits=0) by unimail.uni-dortmund.de (8.19.0.2/8.19.0.2) with ESMTPSA id 6APFNERQ004665 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 25 Nov 2026 16:23:20 +0100 (CET) From: Simon Schippers To: netdev@vger.kernel.org Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Tim Gebauer , =?UTF-8?q?Jonas=20K=C3=B6ppeler?= , "Michael S. Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Stanislav Fomichev , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Schippers Subject: [PATCH net-next 3/3] veth: stop the txq as soon as the ptr_ring is full Date: Wed, 25 Nov 2026 16:23:11 +0100 Message-ID: <20261125152311.805325-4-simon.schippers@tu-dortmund.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> References: <20261125152311.805325-1-simon.schippers@tu-dortmund.de> X-Mailing-List: linux-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: quoted-printable Content-Type: text/plain; charset="utf-8" veth_xmit() stops the txq only once a produce has failed. The skb is then returned with NETDEV_TX_BUSY and requeued by the qdisc. Under a flood every refill of the ring after a wake ends this way, with a failed produce and a requeue. Check under the producer lock whether the produce has filled the ring, and stop the txq then, as for NETDEV_TX_BUSY but with the skb sent. The next skb waits in the qdisc and is not requeued. NETDEV_TX_BUSY stays for a ring that another producer, like XDP redirect, has filled. The stop is ordered as in the NETDEV_TX_BUSY path. The stop bit is set before the smp_mb() in __veth_xdp_flush(), which pairs with the smp_store_mb() in veth_poll(). Either the producer finds NAPI idle and schedules it, or the poll sees the stopped txq and wakes it. Same setup as in the previous patch, an AMD Ryzen 9 9950X with all cores on the same CCX at a fixed 4.3 GHz, compared to it: threaded NAPI before after requeues pktgen 1343008 pps +0.2 +-0.4% 210594 -> 0 iperf3 TCP 33113 Mbit/s +0.1 +-0.4% 4587 -> 3213 iperf3 UDP 363 Mbit/s +1.2 +-0.6% 14 -> 14 iperf3 TCP keeps its requeues, the change is within noise. When the txq stops in the middle of a GSO segment list, the rest of the list goes back to the qdisc, and each segment counts as a requeue. The few UDP requeues show up with every kernel, also without this series. With softirq NAPI and a single sender the ring does not fill, and the only change on that path is the __ptr_ring_check_produce() check. iperf3 changes by -0.1% to +0.4% there, with confidence intervals of 0.4% to 0.9%. pktgen is 1.4 +-0.5% slower. The patch also moves the code of net/ by 16 bytes, as veth is linked before it, and I could not separate the two. With the two iperf3 senders on one queue from the previous patch, throughput stays within 1.2% of it. The UDP requeues with threaded NAPI drop from 81520 to 48929 per run. Signed-off-by: Simon Schippers --- drivers/net/veth.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 02ffc7ba59ab2..911da9893e82d 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -40,6 +40,11 @@ #define VETH_XDP_TX_BULK_SIZE 16 #define VETH_XDP_BATCH 16 =20 +/* Returned by veth_xdp_rx() when the skb filled the ring. Internal to + * veth, veth_xmit() returns NETDEV_TX_OK for it. + */ +#define VETH_RING_FULL 0x20 + struct veth_stats { u64 rx_drops; /* xdp */ @@ -312,10 +317,17 @@ static void __veth_xdp_flush(struct veth_rq *rq) =20 static int veth_xdp_rx(struct veth_rq *rq, struct sk_buff *skb) { - if (unlikely(ptr_ring_produce(&rq->xdp_ring, skb))) - return NETDEV_TX_BUSY; /* signal qdisc layer */ + struct ptr_ring *ring =3D &rq->xdp_ring; + int ret =3D NET_RX_SUCCESS; /* same as NETDEV_TX_OK */ =20 - return NET_RX_SUCCESS; /* same as NETDEV_TX_OK */ + spin_lock(&ring->producer_lock); + if (__ptr_ring_produce(ring, skb)) + ret =3D NETDEV_TX_BUSY; /* signal qdisc layer */ + else if (__ptr_ring_check_produce(ring) =3D=3D -ENOSPC) + ret =3D VETH_RING_FULL; + spin_unlock(&ring->producer_lock); + + return ret; } =20 static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, @@ -388,6 +400,13 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, stru= ct net_device *dev) else __veth_xdp_flush(rq); break; + case VETH_RING_FULL: + txq =3D netdev_get_tx_queue(dev, rxq); + if (!qdisc_txq_has_no_queue(txq)) + netif_tx_stop_queue(txq); + __veth_xdp_flush(rq); + ret =3D NETDEV_TX_OK; + break; case NETDEV_TX_BUSY: /* If a qdisc is attached to our virtual device, returning * NETDEV_TX_BUSY is allowed. --=20 2.43.0