1 From: Eric Dumazet <edumazet@google.com>
2 Date: Tue, 21 Jun 2016 23:16:52 -0700
3 Subject: [PATCH] net_sched: generalize bulk dequeue
5 When qdisc bulk dequeue was added in linux-3.18 (commit
6 5772e9a3463b "qdisc: bulk dequeue support for qdiscs
7 with TCQ_F_ONETXQUEUE"), it was constrained to some
10 With some extra care, we can extend this to all qdiscs,
11 so that typical traffic shaping solutions can benefit from
12 small batches (8 packets in this patch).
14 For example, HTB is often used on some multi queue device.
15 And bonding/team are multi queue devices...
17 Idea is to bulk-dequeue packets mapping to the same transmit queue.
19 This brings between 35 and 80 % performance increase in HTB setup
20 under pressure on a bonding setup :
22 1) NUMA node contention : 610,000 pps -> 1,110,000 pps
23 2) No node contention : 1,380,000 pps -> 1,930,000 pps
25 Now we should work to add batches on the enqueue() side ;)
27 Signed-off-by: Eric Dumazet <edumazet@google.com>
28 Cc: John Fastabend <john.r.fastabend@intel.com>
29 Cc: Jesper Dangaard Brouer <brouer@redhat.com>
30 Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
31 Cc: Florian Westphal <fw@strlen.de>
32 Cc: Daniel Borkmann <daniel@iogearbox.net>
33 Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
34 Signed-off-by: David S. Miller <davem@davemloft.net>
37 --- a/include/net/sch_generic.h
38 +++ b/include/net/sch_generic.h
39 @@ -88,13 +88,14 @@ struct Qdisc {
41 * For performance sake on SMP, we put highly modified fields at the end
43 - struct Qdisc *next_sched ____cacheline_aligned_in_smp;
44 - struct sk_buff *gso_skb;
45 - unsigned long state;
46 + struct sk_buff *gso_skb ____cacheline_aligned_in_smp;
47 struct sk_buff_head q;
48 struct gnet_stats_basic_packed bstats;
50 struct gnet_stats_queue qstats;
51 + unsigned long state;
52 + struct Qdisc *next_sched;
53 + struct sk_buff *skb_bad_txq;
54 struct rcu_head rcu_head;
57 --- a/net/sched/sch_generic.c
58 +++ b/net/sched/sch_generic.c
59 @@ -76,6 +76,34 @@ static void try_bulk_dequeue_skb(struct
63 +/* This variant of try_bulk_dequeue_skb() makes sure
64 + * all skbs in the chain are for the same txq
66 +static void try_bulk_dequeue_skb_slow(struct Qdisc *q,
67 + struct sk_buff *skb,
70 + int mapping = skb_get_queue_mapping(skb);
71 + struct sk_buff *nskb;
75 + nskb = q->dequeue(q);
78 + if (unlikely(skb_get_queue_mapping(nskb) != mapping)) {
79 + q->skb_bad_txq = nskb;
80 + qdisc_qstats_backlog_inc(q, nskb);
86 + } while (++cnt < 8);
91 /* Note that dequeue_skb can possibly return a SKB list (via skb->next).
92 * A requeued skb (via q->gso_skb) can also be a SKB list.
94 @@ -86,8 +114,9 @@ static struct sk_buff *dequeue_skb(struc
95 const struct netdev_queue *txq = q->dev_queue;
100 + /* skb in gso_skb were already validated */
102 /* check the reason of requeuing without tx lock first */
103 txq = skb_get_tx_queue(txq->dev, skb);
104 if (!netif_xmit_frozen_or_stopped(txq)) {
105 @@ -95,15 +124,30 @@ static struct sk_buff *dequeue_skb(struc
109 - /* skb in gso_skb were already validated */
112 - if (!(q->flags & TCQ_F_ONETXQUEUE) ||
113 - !netif_xmit_frozen_or_stopped(txq)) {
114 - skb = q->dequeue(q);
115 - if (skb && qdisc_may_bulk(q))
116 - try_bulk_dequeue_skb(q, skb, txq, packets);
120 + skb = q->skb_bad_txq;
121 + if (unlikely(skb)) {
122 + /* check the reason of requeuing without tx lock first */
123 + txq = skb_get_tx_queue(txq->dev, skb);
124 + if (!netif_xmit_frozen_or_stopped(txq)) {
125 + q->skb_bad_txq = NULL;
126 + qdisc_qstats_backlog_dec(q, skb);
132 + if (!(q->flags & TCQ_F_ONETXQUEUE) ||
133 + !netif_xmit_frozen_or_stopped(txq))
134 + skb = q->dequeue(q);
137 + if (qdisc_may_bulk(q))
138 + try_bulk_dequeue_skb(q, skb, txq, packets);
140 + try_bulk_dequeue_skb_slow(q, skb, packets);
144 @@ -649,11 +693,14 @@ void qdisc_reset(struct Qdisc *qdisc)
148 + kfree_skb(qdisc->skb_bad_txq);
149 + qdisc->skb_bad_txq = NULL;
151 if (qdisc->gso_skb) {
152 kfree_skb_list(qdisc->gso_skb);
153 qdisc->gso_skb = NULL;
158 EXPORT_SYMBOL(qdisc_reset);
160 @@ -692,6 +739,7 @@ void qdisc_destroy(struct Qdisc *qdisc)
161 dev_put(qdisc_dev(qdisc));
163 kfree_skb_list(qdisc->gso_skb);
164 + kfree_skb(qdisc->skb_bad_txq);
166 * gen_estimator est_timer() might access qdisc->q.lock,
167 * wait a RCU grace period before freeing qdisc.