Netdev List
 help / color / mirror / Atom feed
From: Andreea-Carina Deaconu <carina.deaconu@ens-lyon.fr>
To: netdev@vger.kernel.org
Cc: Thomas Begin <thomas.begin@ens-lyon.fr>
Subject: [PATCH] net/sched: fq_codel: choose random fat flow to drop from, if multiple are equal
Date: Thu, 03 Dec 2026 17:42:12 +0100	[thread overview]
Message-ID: <b080aa835ab7e3a9b715fb3ee06c447b@ens-lyon.fr> (raw)

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

             reply	other threads:[~2026-12-03 16:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:42 Andreea-Carina Deaconu [this message]
2026-12-03 16:43 ` [PATCH] net/sched: fq_codel: choose random fat flow to drop from, if multiple are equal Andreea-Carina Deaconu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b080aa835ab7e3a9b715fb3ee06c447b@ens-lyon.fr \
    --to=carina.deaconu@ens-lyon.fr \
    --cc=netdev@vger.kernel.org \
    --cc=thomas.begin@ens-lyon.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox