mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Simon Schippers <simon.schippers@tu-dortmund.de>
To: netdev@vger.kernel.org
Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Tim Gebauer" <tim.gebauer@tu-dortmund.de>,
	"Jonas Köppeler" <j.koeppeler@tu-berlin.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Simon Schippers" <simon.schippers@tu-dortmund.de>
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	[thread overview]
Message-ID: <20261125152311.805325-4-simon.schippers@tu-dortmund.de> (raw)
In-Reply-To: <20261125152311.805325-1-simon.schippers@tu-dortmund.de>

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 <simon.schippers@tu-dortmund.de>
---
 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
 
+/* 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)
 
 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 = &rq->xdp_ring;
+	int ret = NET_RX_SUCCESS; /* same as NETDEV_TX_OK */
 
-	return NET_RX_SUCCESS; /* same as NETDEV_TX_OK */
+	spin_lock(&ring->producer_lock);
+	if (__ptr_ring_produce(ring, skb))
+		ret = NETDEV_TX_BUSY; /* signal qdisc layer */
+	else if (__ptr_ring_check_produce(ring) == -ENOSPC)
+		ret = VETH_RING_FULL;
+	spin_unlock(&ring->producer_lock);
+
+	return ret;
 }
 
 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, struct net_device *dev)
 		else
 			__veth_xdp_flush(rq);
 		break;
+	case VETH_RING_FULL:
+		txq = netdev_get_tx_queue(dev, rxq);
+		if (!qdisc_txq_has_no_queue(txq))
+			netif_tx_stop_queue(txq);
+		__veth_xdp_flush(rq);
+		ret = NETDEV_TX_OK;
+		break;
 	case NETDEV_TX_BUSY:
 		/* If a qdisc is attached to our virtual device, returning
 		 * NETDEV_TX_BUSY is allowed.
-- 
2.43.0


  parent reply	other threads:[~2026-11-25 15:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:23 [PATCH net-next 0/3] veth: earlier txq wake and stop under backpressure Simon Schippers
2026-11-25 15:23 ` [PATCH net-next 1/3] ptr_ring: add PTR_RING_BATCH Simon Schippers
2026-11-25 15:23 ` [PATCH net-next 2/3] veth: wake the peer txq in the middle of the NAPI poll Simon Schippers
2026-11-25 15:23 ` Simon Schippers [this message]
2026-11-26 18:06 ` [PATCH net-next 0/3] veth: earlier txq wake and stop under backpressure Simon Schippers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125152311.805325-4-simon.schippers@tu-dortmund.de \
    --to=simon.schippers@tu-dortmund.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=j.koeppeler@tu-berlin.de \
    --cc=jasowangio@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=tim.gebauer@tu-dortmund.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®