Skip to contentSkip to conversation

Avoid enqueuing skb for default qdiscs

PATCH In review Krishna Kumar 4 participants 9 messages Aug 6, 2009 – Feb 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid enqueuing skb for default qdiscs

From: Krishna Kumar <[email protected]>

dev_queue_xmit enqueue's a skb and calls qdisc_run which dequeue's the skb and xmits it. In most cases, the skb that is enqueue'd is the same one that is dequeue'd (unless the queue gets stopped or multiple cpu's write to the same queue and ends in a race with qdisc_run). For default qdiscs, we can remove the redundant enqueue/dequeue and simply xmit the skb since the default qdisc is work-conserving.

The patch uses a new flag - TCQ_F_CAN_BYPASS to identify the default fast queue. The controversial part of the patch is incrementing qlen when a skb is requeued - this is to avoid checks like the second line below:

+ } else if ((q->flags & TCQ_F_CAN_BYPASS) && !qdisc_qlen(q) &&

Quoted 1 line
Quoted 1 line
        !q->gso_skb &&

+ !test_and_set_bit(__QDISC_STATE_RUNNING, &q->state)) {

Results of a 2 hour testing for multiple netperf sessions (1, 2, 4, 8, 12 sessions on a 4 cpu system-X). The BW numbers are aggregate Mb/s across iterations tested with this version on System-X boxes with Chelsio 10gbps cards:

----------------------------------
Size | ORG BW NEW BW |
----------------------------------

128K |  156964          159381   |
256K |  158650          162042   |

----------------------------------

Changes from ver1:

1. Move sch_direct_xmit declaration from sch_generic.h to pkt_sched.h
2. Update qdisc basic statistics for direct xmit path.
3. Set qlen to zero in qdisc_reset.
4. Changed some function names to more meaningful ones.

Thanks,

- KK

---
 include/net/pkt_sched.h   |    3 +
 include/net/sch_generic.h |   15 +++++
 net/core/dev.c            |   48 +++++++++++++-----
 net/sched/sch_generic.c   |   93 ++++++++++++++++++++++--------------
 4 files changed, 108 insertions(+), 51 deletions(-)
include/net/pkt_sched.h +3 -0
diff -ruNp org2/include/net/pkt_sched.h new6/include/net/pkt_sched.h
@@ -87,6 +87,9 @@ extern struct qdisc_rate_table *qdisc_ge
 extern void qdisc_put_rtab(struct qdisc_rate_table *tab);
 extern void qdisc_put_stab(struct qdisc_size_table *tab);
 extern void qdisc_warn_nonwc(char *txt, struct Qdisc *qdisc);
+extern int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
+			   struct net_device *dev, struct netdev_queue *txq,
+			   spinlock_t *root_lock);
 
 extern void __qdisc_run(struct Qdisc *q);
 
include/net/sch_generic.h +13 -2
diff -ruNp org2/include/net/sch_generic.h new6/include/net/sch_generic.h
@@ -45,6 +45,7 @@ struct Qdisc
 #define TCQ_F_BUILTIN		1
 #define TCQ_F_THROTTLED		2
 #define TCQ_F_INGRESS		4
+#define TCQ_F_CAN_BYPASS	8
 #define TCQ_F_WARN_NONWC	(1 << 16)
 	int			padded;
 	struct Qdisc_ops	*ops;
@@ -182,6 +183,11 @@ struct qdisc_skb_cb {
 	char			data[];
 };
 
+static inline int qdisc_qlen(struct Qdisc *q)
+{
+	return q->q.qlen;
+}
+
 static inline struct qdisc_skb_cb *qdisc_skb_cb(struct sk_buff *skb)
 {
 	return (struct qdisc_skb_cb *)skb->cb;
@@ -387,13 +393,18 @@ static inline int qdisc_enqueue_root(str
 	return qdisc_enqueue(skb, sch) & NET_XMIT_MASK;
 }
 
+static inline void __qdisc_update_bstats(struct Qdisc *sch, unsigned int len)
+{
+	sch->bstats.bytes += len;
+	sch->bstats.packets++;
+}
+
 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
 				       struct sk_buff_head *list)
 {
 	__skb_queue_tail(list, skb);
 	sch->qstats.backlog += qdisc_pkt_len(skb);
-	sch->bstats.bytes += qdisc_pkt_len(skb);
-	sch->bstats.packets++;
+	__qdisc_update_bstats(sch, qdisc_pkt_len(skb));
 
 	return NET_XMIT_SUCCESS;
 }
net/core/dev.c +35 -13

60 lines not on this page · raw message

net/sched/sch_generic.c +57 -36

145 lines not on this page · raw message

maintainer
#1 lore raw

From: Krishna Kumar <[email protected]>
Date: Thu, 06 Aug 2009 17:14:21 +0530

net/sched/sch_generic.c line 47

Quoted 9 lines
net/sched/sch_generic.c +1 -1
-
 static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q)
 {
 	q->gso_skb = skb;
 	q->qstats.requeues++;
+	q->q.qlen++;	/* it's still part of the queue */
 	__netif_schedule(q);
 
 	return 0;

I'm dubious about this new qlen accounting scheme, does it handle the non-bypass case properly? Can you explain how it works exactly?

#4 lore raw
In reply to Krishna Kumar

include/net/sch_generic.h struct qdisc_skb_cb { · line 190

Quoted 5 lines · On Thu, 06 Aug 2009 17:14:21 +0530 Krishna Kumar <[email protected]> wrote:
include/net/sch_generic.h +5 -0
+static inline int qdisc_qlen(struct Qdisc *q)
+{
+	return q->q.qlen;
+}
+

Why?
This kind of oneline accessor decreases the code clarity.

#2 lore raw
In reply to David Miller

Hi Dave,

David Miller <[email protected]> wrote on 08/07/2009 02:11:26 AM:

Quoted 1 line
Quoted 1 line

static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc

*q)

Quoted 11 lines
Quoted 7 lines
 {
    q->gso_skb = skb;
    q->qstats.requeues++;
+   q->q.qlen++;   /* it's still part of the queue */
    __netif_schedule(q);

    return 0;

I'm dubious about this new qlen accounting scheme, does it handle the non-bypass case properly? Can you explain how it works exactly?

Adding one to qlen will handle non-bypass correctly. On the next non-bypass (or a bypass) xmit, dequeue_skb will remove gso_skb and decrement the counter. If no more xmits are done, qdisc_reset will also fix it. I got this idea by extending one of Jarek's patches:

commit 61c9eaf90081cbe6dc4f389e0056bff76eca19ec

Author: Jarek Poplawski <[email protected]>
Date:   Wed Nov 5 16:02:34 2008 -0800

pkt_sched: Fix qdisc len in qdisc_peek_dequeued()

Thanks,

- KK

#5 lore raw
In reply to Stephen Hemminger

Hi Stephen,

Stephen Hemminger <[email protected]> wrote on 08/07/2009 02:19:46 AM:

Quoted 8 lines

include/net/sch_generic.h struct qdisc_skb_cb { · line 190

Quoted 5 lines
include/net/sch_generic.h +5 -0
+static inline int qdisc_qlen(struct Qdisc *q)
+{
+   return q->q.qlen;
+}
+

Why?
This kind of oneline accessor decreases the code clarity.

qdisc_qlen() was previously defined in sch_generic.c. I moved it to the header file so that it could be accessed in dev.c (where there is no code using q.qlen), so it is not new code.

Thanks,

- KK

maintainer
#3 lore raw
In reply to Krishna Kumar2

From: Krishna Kumar2 <[email protected]>
Date: Fri, 7 Aug 2009 08:26:04 +0530

Quoted 10 lines

David Miller <[email protected]> wrote on 08/07/2009 02:11:26 AM:

Quoted 3 lines

I'm dubious about this new qlen accounting scheme, does it handle the non-bypass case properly? Can you explain how it works exactly?

Adding one to qlen will handle non-bypass correctly. On the next non-bypass (or a bypass) xmit, dequeue_skb will remove gso_skb and decrement the counter. If no more xmits are done, qdisc_reset will also fix it. I got this idea by extending one of Jarek's patches:

Aha, I see. Thanks for the explanation.

Ok, I'll let this rip... let's see what falls out of it :-) Will apply this to net-next-2.6 right now.

#6 lore raw
In reply to Krishna Kumar

On Thu, 2009-08-06 at 17:14 +0530, Krishna Kumar wrote:

Hello,

Quoted 9 lines

From: Krishna Kumar <[email protected]>

dev_queue_xmit enqueue's a skb and calls qdisc_run which dequeue's the skb and xmits it. In most cases, the skb that is enqueue'd is the same one that is dequeue'd (unless the queue gets stopped or multiple cpu's write to the same queue and ends in a race with qdisc_run). For default qdiscs, we can remove the redundant enqueue/dequeue and simply xmit the skb since the default qdisc is work-conserving.

Sorry old stuff, but I just noticed this.

One side effect of this patch is that tc now shows a lot of requeue for slow interfaces (slow dsl link in my case), because sch_direct_xmit is called even if device stopped its queue.

My first reflex was too investigate for a misbehaving driver (returning TX_BUSY), but start_xmit is not even called, sch_direct_xmit notices that queue is stopped, and just does a dequeue/requeue.

Since we're talking about slow interfaces, this has no impact on performance, the requeue counter incrementing is just a bit scary.

Shouldn't we check for stopped queue earlier to avoid this ?

Regards,

Signature · 1 line
Maxime
#7 lore raw

Hi Maxime,

Maxime Bizon <[email protected]> wrote on 02/01/2010 03:22:20 PM:

Quoted 5 lines

Sorry old stuff, but I just noticed this.

One side effect of this patch is that tc now shows a lot of requeue for slow interfaces (slow dsl link in my case), because sch_direct_xmit is called even if device stopped its queue.

sch_direct_xmit can be called from dev_queue_xmit for a stopped device only if the device had xmit the previous skb, stopped the device and returned OK. Then the next sch_d_x will dequeue and requeue the new skb. But from now on, sch_d_x is never called from dev_queue_xmit since qdisc_qlen(q) > 0. Instead dev_queue_xmit enqueue's the skb and calls qdisc_restart, which calls dequeue_skb. dequeue_skb finds there is an earlier gso_skb but since the device is stopped, it returns NULL. Hence there should be only one requeue (and dequeue) for every stop.

BTW, I don't think this patch would change the earlier behavior. The old code would have done the same thing.

Quoted 3 lines

My first reflex was too investigate for a misbehaving driver (returning TX_BUSY), but start_xmit is not even called, sch_direct_xmit notices that queue is stopped, and just does a dequeue/requeue.

As I explained, this should happen only once per stop event. Could you tell which driver is having this problem? Is it waking up too early, eg, it might be stopping when the hw tx descriptor is full but waking up when a few slots open up, and those will get filled up immediately on fast systems. Then you will see a lot of requeue's.

Quoted 4 lines

Since we're talking about slow interfaces, this has no impact on performance, the requeue counter incrementing is just a bit scary.

Shouldn't we check for stopped queue earlier to avoid this ?

dev_queue_xmit is checking for qdisc_qlen == 0 before calling sch_direct_xmit, which is enough for all stopped queue except the first time. Also, it's not possible to check for stopped Q earlier in qdisc_restart() due to multiqueue implementation.

Please let me know if you find something different from what I have described.

thanks,

- KK

#8 lore raw

On Mon, 2010-02-01 at 19:12 +0530, Krishna Kumar2 wrote:

Hi,

Quoted 3 lines

sch_direct_xmit can be called from dev_queue_xmit for a stopped device only if the device had xmit the previous skb, stopped the device and returned OK. Then the next

Yes, that's what happen in my case.

Quoted 2 lines

BTW, I don't think this patch would change the earlier behavior. The old code would have done the same thing.

Oh, my mistake then. I always thought the requeue counter was indicating the driver returned TX_BUSY (and failed to stop the queue before), which is not polite.

If the current behavior is the expected one, then there is no problem here.

Quoted 6 lines

As I explained, this should happen only once per stop event. Could you tell which driver is having this problem? Is it waking up too early, eg, it might be stopping when the hw tx descriptor is full but waking up when a few slots open up, and those will get filled up immediately on fast systems. Then you will see a lot of requeue's.

This is an atm driver which is not mainlined. The system is not that fast, but the link is (very) slow (< 1 Mbit/s).

The driver is waking up the queue once the hardware queue is not full anymore (at least one free tx desc), and the free slot gets filled immediately since the link is slow.

Thanks for explaining !

Signature · 1 line
Maxime