Netdev List
 help / color / mirror / Atom feed
* [PATCH] net/sched: fq_codel: choose random fat flow to drop from, if multiple are equal
@ 2026-12-03 16:42 Andreea-Carina Deaconu
  2026-12-03 16:43 ` Andreea-Carina Deaconu
  0 siblings, 1 reply; 2+ messages in thread
From: Andreea-Carina Deaconu @ 2026-12-03 16:42 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Begin

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 <thomas.begin@ens-lyon.fr>
Reported-by: Andreea-Carina Deaconu <carina.deaconu@ens-lyon.fr>
Signed-off-by: Andreea-Carina Deaconu <carina.deaconu@ens-lyon.fr>
---
  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 <linux/in.h>
  #include <linux/errno.h>
  #include <linux/init.h>
+#include <linux/random.h>
  #include <linux/skbuff.h>
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
@@ -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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:42 [PATCH] net/sched: fq_codel: choose random fat flow to drop from, if multiple are equal Andreea-Carina Deaconu
2026-12-03 16:43 ` Andreea-Carina Deaconu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox