Skip to contentSkip to conversation

net_sched: codel: fix stale state for empty flows in fq_codel

PATCH Applied [email protected] 3 participants 3 messages Mar 23 – Mar 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net_sched: codel: fix stale state for empty flows in fq_codel

From: Jonas Köppeler <[email protected]>

When codel_dequeue() finds an empty queue, it resets vars->dropping but does not reset vars->first_above_time. The reference CoDel algorithm (Nichols & Jacobson, ACM Queue 2012) resets both:

  dodeque_result codel_queue_t::dodeque(time_t now) {
      ...
      if (r.p == NULL) {
          first_above_time = 0;   // <-- Linux omits this
      }
      ...
  }

Note that codel_should_drop() does reset first_above_time when called with a NULL skb, but codel_dequeue() returns early before ever calling codel_should_drop() in the empty-queue case. The post-drop code paths do reach codel_should_drop(NULL) and correctly reset the timer, so a dropped packet breaks the cycle -- but the next delivered packet re-arms first_above_time and the cycle repeats.

For sparse flows such as ICMP ping (one packet every 200ms-1s), the first packet arms first_above_time, the flow goes empty, and the second packet arrives after the interval has elapsed and gets dropped. The pattern repeats, producing sustained loss on flows that are not actually congested.

Test: veth pair, fq_codel, BQL disabled, 30000 iptables rules in the consumer namespace (NAPI-64 cycle ~14ms, well above fq_codel's 5ms target), ping at 5 pps under UDP flood:

Before fix: 26% ping packet loss
After fix: 0% ping packet loss

Fix by resetting first_above_time to zero in the empty-queue path of codel_dequeue(), matching the reference algorithm.

---
 include/net/codel_impl.h | 1 +
 1 file changed, 1 insertion(+)
include/net/codel_impl.h +1 -0
index 78a27ac73070..b2c359c6dd1b 100644
@@ -158,6 +158,7 @@ static struct sk_buff *codel_dequeue(void *ctx,
 	bool drop;
 
 	if (!skb) {
+		vars->first_above_time = 0;
 		vars->dropping = false;
 		return skb;
 	}
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · On Mon, Mar 23, 2026 at 10:49 AM <[email protected]> wrote:

From: Jonas Köppeler <[email protected]>

When codel_dequeue() finds an empty queue, it resets vars->dropping but does not reset vars->first_above_time. The reference CoDel algorithm (Nichols & Jacobson, ACM Queue 2012) resets both:

  dodeque_result codel_queue_t::dodeque(time_t now) {
      ...
      if (r.p == NULL) {
          first_above_time = 0;   // <-- Linux omits this
      }
      ...
  }

Note that codel_should_drop() does reset first_above_time when called with a NULL skb, but codel_dequeue() returns early before ever calling codel_should_drop() in the empty-queue case. The post-drop code paths do reach codel_should_drop(NULL) and correctly reset the timer, so a dropped packet breaks the cycle -- but the next delivered packet re-arms first_above_time and the cycle repeats.

For sparse flows such as ICMP ping (one packet every 200ms-1s), the first packet arms first_above_time, the flow goes empty, and the second packet arrives after the interval has elapsed and gets dropped. The pattern repeats, producing sustained loss on flows that are not actually congested.

Test: veth pair, fq_codel, BQL disabled, 30000 iptables rules in the consumer namespace (NAPI-64 cycle ~14ms, well above fq_codel's 5ms target), ping at 5 pps under UDP flood:

Before fix: 26% ping packet loss
After fix: 0% ping packet loss

Fix by resetting first_above_time to zero in the empty-queue path of codel_dequeue(), matching the reference algorithm.

---
 include/net/codel_impl.h | 1 +
 1 file changed, 1 insertion(+)
include/net/codel_impl.h +0 -0
index 78a27ac73070..b2c359c6dd1b 100644

include/net/codel_impl.h static struct sk_buff *codel_dequeue(void *ctx, · line 164

Quoted 7 lines
include/net/codel_impl.h +1 -0
@@ -158,6 +158,7 @@ static struct sk_buff *codel_dequeue(void *ctx,
        bool drop;
 
        if (!skb) {
+               vars->first_above_time = 0;
                vars->dropping = false;
                return skb;
        }

Nice catch, thanks.

I guess I wanted to avoid the ktime_get() cost as much as I could....

#2 lore raw
In reply to [email protected]
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 14 lines · On Mon, 23 Mar 2026 18:49:20 +0100 you wrote:

From: Jonas Köppeler <[email protected]>

When codel_dequeue() finds an empty queue, it resets vars->dropping but does not reset vars->first_above_time. The reference CoDel algorithm (Nichols & Jacobson, ACM Queue 2012) resets both:

  dodeque_result codel_queue_t::dodeque(time_t now) {
      ...
      if (r.p == NULL) {
          first_above_time = 0;   // <-- Linux omits this
      }
      ...
  }
Quoted 1 line

[...]

Here is the summary with links:
- net_sched: codel: fix stale state for empty flows in fq_codel

    https://git.kernel.org/netdev/net/c/815980fe6dbb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html