Skip to contentSkip to conversation

net/sched: sch_cake: skip clearing unused tins during rate adjustment

PATCH Applied Jonas Köppeler 3 participants 3 messages Jul 20 – Jul 24

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

PATCH v2 1/1 net/sched: sch_cake: skip clearing unused tins during rate adjustment

When cake_configure_rates() is called from the dequeue path with rate_adjust=true, it only needs to update the rate parameters. The loop that clears the unused tins is both unnecessary and harmful in this path:

- cake_clear_tin() overwrites q->cur_tin and q->cur_flow, which are actively used by cake_dequeue(), corrupting the dequeue state.
- iterating over the unused tins and their internal queues to purge packets adds needless overhead to the hot path.

Skip the entire loop when rate_adjust is set, as neither cake_clear_tin() nor the mtu_time update are needed when only the rate changes.

The clearing loop runs on every rate adjustment from the dequeue path, clearing (max_tins - cur_tins) tins each time, so the cost grows the fewer tins the configured mode actually uses. Testing cake_mq over veth (8 rx/tx queues, 2 Gbit limit) with flent's [1] rrul and tcp_nup tests and 32 TCP upstreams shows a large drop in loaded latency and a throughput gain, restoring behaviour to pre-15c2715a5264 levels:

  +------------+------+------+-------+-------+---------+
  | kernel     | mode | test |  base |  load |    tput |
  |            |      |      |  (ms) |  (ms) |  (Mbit) |
  +------------+------+------+-------+-------+---------+
  | net-next   | be   | rrul | 0.810 | 11.78 | 1469.67 |
  | net-next   | be   | nup  | 0.637 | 85.71 | 1243.15 |
  | net-next   | ds3  | rrul | 0.397 | 15.28 | 1770.06 |
  | net-next   | ds3  | nup  | 0.351 | 15.98 | 1799.39 |
  +------------+------+------+-------+-------+---------+
  | patched    | be   | rrul | 0.092 |  0.56 | 1873.40 |
  | patched    | be   | nup  | 0.109 |  1.82 | 1869.12 |
  | patched    | ds3  | rrul | 0.097 |  0.98 | 1866.10 |
  | patched    | ds3  | nup  | 0.101 |  0.51 | 1861.79 |
  +------------+------+------+-------+-------+---------+

The same trend holds on real hardware (IPQ8074A, 4 rx/tx queues, OpenWrt): in besteffort mode the tcp_nup loaded latency drops from ~470 ms to ~4 ms.

[1] https://flent.org

Fixes 15c2715a5264 ("net/sched: sch_cake: fixup cake_mq rate adjustment for diffserv config")

---
Changes in v2:
- added performance data to commit message, no code changes
- Link to v1: https://patch.msgid.link/20260716-sch_cake-skip-clearing-tins-v1-1-d9787df20c28@tu-berlin.de

---
 net/sched/sch_cake.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/sched/sch_cake.c +5 -3
index f78f8e950776..845e1c017714 100644
@@ -2609,9 +2609,11 @@ static void cake_configure_rates(struct Qdisc *sch, u64 rate, bool rate_adjust)
 		break;
 	}
 
-	for (c = qd->tin_cnt; c < CAKE_MAX_TINS; c++) {
-		cake_clear_tin(sch, c);
-		qd->tins[c].cparams.mtu_time = qd->tins[ft].cparams.mtu_time;
+	if (!rate_adjust) {
+		for (c = qd->tin_cnt; c < CAKE_MAX_TINS; c++) {
+			cake_clear_tin(sch, c);
+			qd->tins[c].cparams.mtu_time = qd->tins[ft].cparams.mtu_time;
+		}
 	}
 
 	qd->rate_ns   = qd->tins[ft].tin_rate_ns;

---
base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e
change-id: 20260716-sch_cake-skip-clearing-tins-856812586cde

Best regards,

Signature · 1 line
Jonas Köppeler <[email protected]>
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 40 lines · Jonas Köppeler

When cake_configure_rates() is called from the dequeue path with rate_adjust=true, it only needs to update the rate parameters. The loop that clears the unused tins is both unnecessary and harmful in this path:

- cake_clear_tin() overwrites q->cur_tin and q->cur_flow, which are actively used by cake_dequeue(), corrupting the dequeue state.
- iterating over the unused tins and their internal queues to purge packets adds needless overhead to the hot path.

Skip the entire loop when rate_adjust is set, as neither cake_clear_tin() nor the mtu_time update are needed when only the rate changes.

The clearing loop runs on every rate adjustment from the dequeue path, clearing (max_tins - cur_tins) tins each time, so the cost grows the fewer tins the configured mode actually uses. Testing cake_mq over veth (8 rx/tx queues, 2 Gbit limit) with flent's [1] rrul and tcp_nup tests and 32 TCP upstreams shows a large drop in loaded latency and a throughput gain, restoring behaviour to pre-15c2715a5264 levels:

 +------------+------+------+-------+-------+---------+
 | kernel     | mode | test |  base |  load |    tput |
 |            |      |      |  (ms) |  (ms) |  (Mbit) |
 +------------+------+------+-------+-------+---------+
 | net-next   | be   | rrul | 0.810 | 11.78 | 1469.67 |
 | net-next   | be   | nup  | 0.637 | 85.71 | 1243.15 |
 | net-next   | ds3  | rrul | 0.397 | 15.28 | 1770.06 |
 | net-next   | ds3  | nup  | 0.351 | 15.98 | 1799.39 |
 +------------+------+------+-------+-------+---------+
 | patched    | be   | rrul | 0.092 |  0.56 | 1873.40 |
 | patched    | be   | nup  | 0.109 |  1.82 | 1869.12 |
 | patched    | ds3  | rrul | 0.097 |  0.98 | 1866.10 |
 | patched    | ds3  | nup  | 0.101 |  0.51 | 1861.79 |
 +------------+------+------+-------+-------+---------+

The same trend holds on real hardware (IPQ8074A, 4 rx/tx queues, OpenWrt): in besteffort mode the tcp_nup loaded latency drops from ~470 ms to ~4 ms.

Quoted 5 lines

[1] https://flent.org

Fixes 15c2715a5264 ("net/sched: sch_cake: fixup cake_mq rate adjustment for diffserv config")
#2 lore raw
In reply to Jonas Köppeler
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 11 lines · On Mon, 20 Jul 2026 23:14:52 +0200 you wrote:

When cake_configure_rates() is called from the dequeue path with rate_adjust=true, it only needs to update the rate parameters. The loop that clears the unused tins is both unnecessary and harmful in this path:

- cake_clear_tin() overwrites q->cur_tin and q->cur_flow, which are actively used by cake_dequeue(), corrupting the dequeue state.
- iterating over the unused tins and their internal queues to purge packets adds needless overhead to the hot path.

[...]

Here is the summary with links:
- [net-next,v2] net/sched: sch_cake: skip clearing unused tins during rate adjustment

    https://git.kernel.org/netdev/net/c/a3729e0df005

You are awesome, thank you!

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