Skip to content

Commit d902e2c

Browse files
edumazetgregkh
authored andcommitted
pkt_sched: fq: fix pacing for small frames
[ Upstream commit f52ed89 ] For performance reasons, sch_fq tried hard to not setup timers for every sent packet, using a quantum based heuristic : A delay is setup only if the flow exhausted its credit. Problem is that application limited flows can refill their credit for every queued packet, and they can evade pacing. This problem can also be triggered when TCP flows use small MSS values, as TSO auto sizing builds packets that are smaller than the default fq quantum (3028 bytes) This patch adds a 40 ms delay to guard flow credit refill. Fixes: afe4fd0 ("pkt_sched: fq: Fair Queue packet scheduler") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Maciej Żenczykowski <maze@google.com> Cc: Willem de Bruijn <willemb@google.com> Cc: Yuchung Cheng <ycheng@google.com> Cc: Neal Cardwell <ncardwell@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8ec2182 commit d902e2c

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎include/uapi/linux/pkt_sched.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ enum {
764764
TCA_FQ_FLOW_MAX_RATE, /* per flow max rate */
765765

766766
TCA_FQ_BUCKETS_LOG, /* log2(number of buckets) */
767+
768+
TCA_FQ_FLOW_REFILL_DELAY, /* flow credit refill delay in usec */
769+
767770
__TCA_FQ_MAX
768771
};
769772

‎net/sched/sch_fq.c‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct fq_sched_data {
8888
struct fq_flow internal; /* for non classified or high prio packets */
8989
u32 quantum;
9090
u32 initial_quantum;
91+
u32 flow_refill_delay;
9192
u32 flow_max_rate; /* optional max rate per flow */
9293
u32 flow_plimit; /* max packets per flow */
9394
struct rb_root *fq_root;
@@ -114,6 +115,7 @@ static struct fq_flow detached, throttled;
114115
static void fq_flow_set_detached(struct fq_flow *f)
115116
{
116117
f->next = &detached;
118+
f->age = jiffies;
117119
}
118120

119121
static bool fq_flow_is_detached(const struct fq_flow *f)
@@ -365,17 +367,20 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
365367
}
366368

367369
f->qlen++;
368-
flow_queue_add(f, skb);
369370
if (skb_is_retransmit(skb))
370371
q->stat_tcp_retrans++;
371372
sch->qstats.backlog += qdisc_pkt_len(skb);
372373
if (fq_flow_is_detached(f)) {
373374
fq_flow_add_tail(&q->new_flows, f);
374-
if (q->quantum > f->credit)
375-
f->credit = q->quantum;
375+
if (time_after(jiffies, f->age + q->flow_refill_delay))
376+
f->credit = max_t(u32, f->credit, q->quantum);
376377
q->inactive_flows--;
377378
qdisc_unthrottled(sch);
378379
}
380+
381+
/* Note: this overwrites f->age */
382+
flow_queue_add(f, skb);
383+
379384
if (unlikely(f == &q->internal)) {
380385
q->stat_internal_packets++;
381386
qdisc_unthrottled(sch);
@@ -453,7 +458,6 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch)
453458
fq_flow_add_tail(&q->old_flows, f);
454459
} else {
455460
fq_flow_set_detached(f);
456-
f->age = jiffies;
457461
q->inactive_flows++;
458462
}
459463
goto begin;
@@ -607,6 +611,7 @@ static const struct nla_policy fq_policy[TCA_FQ_MAX + 1] = {
607611
[TCA_FQ_FLOW_DEFAULT_RATE] = { .type = NLA_U32 },
608612
[TCA_FQ_FLOW_MAX_RATE] = { .type = NLA_U32 },
609613
[TCA_FQ_BUCKETS_LOG] = { .type = NLA_U32 },
614+
[TCA_FQ_FLOW_REFILL_DELAY] = { .type = NLA_U32 },
610615
};
611616

612617
static int fq_change(struct Qdisc *sch, struct nlattr *opt)
@@ -663,6 +668,12 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
663668
err = -EINVAL;
664669
}
665670

671+
if (tb[TCA_FQ_FLOW_REFILL_DELAY]) {
672+
u32 usecs_delay = nla_get_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]) ;
673+
674+
q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
675+
}
676+
666677
if (!err)
667678
err = fq_resize(q, fq_log);
668679

@@ -698,6 +709,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt)
698709
q->flow_plimit = 100;
699710
q->quantum = 2 * psched_mtu(qdisc_dev(sch));
700711
q->initial_quantum = 10 * psched_mtu(qdisc_dev(sch));
712+
q->flow_refill_delay = msecs_to_jiffies(40);
701713
q->flow_max_rate = ~0U;
702714
q->rate_enable = 1;
703715
q->new_flows.first = NULL;
@@ -732,6 +744,8 @@ static int fq_dump(struct Qdisc *sch, struct sk_buff *skb)
732744
nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, q->initial_quantum) ||
733745
nla_put_u32(skb, TCA_FQ_RATE_ENABLE, q->rate_enable) ||
734746
nla_put_u32(skb, TCA_FQ_FLOW_MAX_RATE, q->flow_max_rate) ||
747+
nla_put_u32(skb, TCA_FQ_FLOW_REFILL_DELAY,
748+
jiffies_to_usecs(q->flow_refill_delay)) ||
735749
nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, q->fq_trees_log))
736750
goto nla_put_failure;
737751

0 commit comments

Comments
 (0)