Original bias: When the FQ Codel queue capacity is reached and we proceed in fq_codel_drop() to drop packets from the "fat flow" (the flow with the biggest size), if there are two or more equal "fat flows", we always drop from the first flow found (the flow with the lowest index). Fix: When searching for the "fat flow", keep a candidate count and, if there is more than one candidate, choose a random one to drop from. Reported-by: Thomas Begin Reported-by: Andreea-Carina Deaconu Signed-off-by: Andreea-Carina Deaconu --- net/sched/sch_fq_codel.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c index e0fcda26f..b63d3a3de 100644 --- a/net/sched/sch_fq_codel.c +++ b/net/sched/sch_fq_codel.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -139,8 +140,9 @@ static unsigned int fq_codel_drop(struct Qdisc *sch, unsigned int max_packets, { struct fq_codel_sched_data *q = qdisc_priv(sch); struct sk_buff *skb; - unsigned int maxbacklog = 0, idx = 0, i, len; struct fq_codel_flow *flow; + unsigned int maxbacklog = 0, idx = 0, ties = 0; + unsigned int target = 0, match_idx = 0, i, len; unsigned int threshold; unsigned int mem = 0; @@ -154,7 +156,26 @@ static unsigned int fq_codel_drop(struct Qdisc *sch, unsigned int max_packets, for (i = 0; i < q->flows_cnt; i++) { if (q->backlogs[i] > maxbacklog) { maxbacklog = q->backlogs[i]; - idx = i; + ties = 1; + } else if (maxbacklog > 0 && q->backlogs[i] == maxbacklog) { + ties++; + } + } + + if (maxbacklog > 0 && ties > 0) { + if (ties == 1) + target = 0; + else + target = get_random_u32() % ties; + + for (i = 0; i < q->flows_cnt; i++) { + if (q->backlogs[i] == maxbacklog) { + if (match_idx == target) { + idx = i; + break; + } + match_idx++; + } } } -- 2.53.0