Re: [RFC] net: release dst entry in dev_queue_xmit()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Wednesday, March 25, 2009 - 11:41 am

Jarek Poplawski a écrit :

Yes indeed, this is what I thought too, thanks Jarek.

I tested following patch today on my machine, but obviously could not try 
all possible quirks :)

[PATCH] net: release dst entry in dev_hard_start_xmit()

One point of contention in high network loads is the dst_release() performed
when a transmited skb is freed. This is because NIC tx completion calls skb free
long after original call to dev_queue_xmit(skb).

CPU cache is cold and the atomic op in dst_release() stalls. On SMP, this is
quite visible if one CPU is 100% handling softirqs for a network device,
since dst_clone() is done by other cpus, involving cache line ping pongs.

I believe we can release dst in dev_hard_start_xmit(), while cpu cache is hot, since
caller of dev_queue_xmit() had to hold a reference on dst right before. This reduce
work to be done by softirq handler, and decrease cache misses.

I also believe only pktgen can call dev_queue_xmit() with skb which have
a skb->users != 1. But pkthen skbs have a NULL dst entry.

I added a WARN_ON_ONCE() to catch other cases, and not release skb->dst
if skb->users != 1

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>

diff --git a/net/core/dev.c b/net/core/dev.c
index e3fe5c7..a622db6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1664,6 +1664,26 @@ static int dev_gso_segment(struct sk_buff *skb)
 	return 0;
 }
 
+
+/*
+ * Release dst while its refcnt is likely hot in CPU cache, instead
+ * of waiting NIC tx completion.
+ * We inline dst_release() code for performance reason
+ */
+static void release_skb_dst(struct sk_buff *skb)
+{
+	if (likely(skb->dst)) {
+		if (!WARN_ON_ONCE(atomic_read(&skb->users) != 1)) {
+			int newrefcnt;
+
+			smp_mb__before_atomic_dec();
+			newrefcnt = atomic_dec_return(&skb->dst->__refcnt);
+			WARN_ON(newrefcnt < 0);
+			skb->dst = NULL;
+		}
+	}
+}
+
 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
 			struct netdev_queue *txq)
 {
@@ -1681,6 +1701,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
 				goto gso;
 		}
 
+		release_skb_dst(skb);
 		return ops->ndo_start_xmit(skb, dev);
 	}
 
@@ -1691,6 +1712,7 @@ gso:
 
 		skb->next = nskb->next;
 		nskb->next = NULL;
+		release_skb_dst(nskb);
 		rc = ops->ndo_start_xmit(nskb, dev);
 		if (unlikely(rc)) {
 			nskb->next = skb->next;

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] net: release dst entry in dev_queue_xmit(), Eric Dumazet, (Fri Mar 20, 4:40 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Neil Horman, (Fri Mar 20, 7:10 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), David Miller, (Tue Mar 24, 11:43 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Eric Dumazet, (Wed Mar 25, 12:13 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), David Miller, (Wed Mar 25, 12:17 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Jarek Poplawski, (Wed Mar 25, 11:22 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Eric Dumazet, (Wed Mar 25, 11:41 am)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Jarek Poplawski, (Wed Mar 25, 12:18 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Eric Dumazet, (Wed Mar 25, 12:40 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Jarek Poplawski, (Wed Mar 25, 12:54 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Eric Dumazet, (Wed Mar 25, 1:28 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Jarek Poplawski, (Wed Mar 25, 2:12 pm)
Re: [RFC] net: release dst entry in dev_queue_xmit(), Patrick McHardy, (Wed Mar 25, 2:20 pm)
[PATCH] net: release dst entry in dev_hard_start_xmit(), Eric Dumazet, (Tue May 12, 1:12 am)
Re: [PATCH] net: release dst entry in dev_hard_start_xmit(), Jarek Poplawski, (Tue May 12, 12:27 pm)
Re: [PATCH] net: release dst entry in dev_hard_start_xmit(), Jarek Poplawski, (Tue May 12, 1:05 pm)
Re: [PATCH] net: release dst entry in dev_hard_start_xmit(), Jarek Poplawski, (Tue May 12, 1:24 pm)
Re: [PATCH] net: release dst entry in dev_hard_start_xmit(), Jarek Poplawski, (Tue May 12, 1:59 pm)