Cake - FQ_codel the next generation
 help / color / mirror / Atom feed
From: Samuel Moelius <sam.moelius@trailofbits.com>
To: "Toke Høiland-Jørgensen" <toke@toke.dk>
Cc: Samuel Moelius <sam.moelius@trailofbits.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	cake@lists.bufferbloat.net (moderated list:CAKE QDISC),
	netdev@vger.kernel.org (open list:TC subsystem),
	linux-kernel@vger.kernel.org (open list)
Subject: [Cake] [PATCH] net/sched: cake: clamp active flow deficit on rate changes
Date: Tue,  9 Jun 2026 00:08:43 +0000	[thread overview]
Message-ID: <20260609000605.1234374.9ba17536ec9e.cake-rate-change-stale-flow-deficit@trailofbits.com> (raw)

Changing CAKE rate parameters updates the quantum used for future
scheduling, but active flows can retain deficit computed under the old
rate.

That stale deficit lets an already active flow receive service based on
the previous configuration after userspace changes the shaper rate.

After recomputing rate-derived scheduling parameters, clamp positive
active-flow deficits to the quantum that applies under the new
configuration.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
 net/sched/sch_cake.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index 5862933be8d7..048d313e70fe 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -2621,6 +2621,36 @@ static void cake_configure_rates(struct Qdisc *sch, u64 rate, bool rate_adjust)
 	qd->rate_shft = qd->tins[ft].tin_rate_shft;
 }
 
+static void cake_clamp_flow_deficit(struct cake_tin_data *b,
+				    struct cake_flow *flow,
+				    int flow_mode)
+{
+	s32 quantum;
+
+	if (flow->deficit <= 0)
+		return;
+
+	quantum = cake_get_flow_quantum(b, flow, flow_mode);
+	if (flow->deficit > quantum)
+		WRITE_ONCE(flow->deficit, quantum);
+}
+
+static void cake_clamp_active_deficits(struct cake_sched_data *qd)
+{
+	struct cake_sched_config *q = qd->config;
+	struct cake_flow *flow;
+	u32 tin;
+
+	for (tin = 0; tin < qd->tin_cnt; tin++) {
+		struct cake_tin_data *b = &qd->tins[tin];
+
+		list_for_each_entry(flow, &b->new_flows, flowchain)
+			cake_clamp_flow_deficit(b, flow, q->flow_mode);
+		list_for_each_entry(flow, &b->old_flows, flowchain)
+			cake_clamp_flow_deficit(b, flow, q->flow_mode);
+	}
+}
+
 static void cake_reconfigure(struct Qdisc *sch)
 {
 	struct cake_sched_data *qd = qdisc_priv(sch);
@@ -2628,6 +2658,7 @@ static void cake_reconfigure(struct Qdisc *sch)
 	u32 buffer_limit;
 
 	cake_configure_rates(sch, qd->config->rate_bps, false);
+	cake_clamp_active_deficits(qd);
 
 	if (q->buffer_config_limit) {
 		buffer_limit = q->buffer_config_limit;
-- 
2.43.0


             reply	other threads:[~2026-06-09  0:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  0:08 Samuel Moelius [this message]
2026-06-09  1:08 ` [Cake] Re: [PATCH] net/sched: cake: clamp active flow deficit on rate changes Eric Dumazet
2026-06-09 12:16   ` Samuel Moelius

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

  List information: https://lists.bufferbloat.net/postorius/lists/cake.lists.bufferbloat.net/

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

  git send-email \
    --in-reply-to=20260609000605.1234374.9ba17536ec9e.cake-rate-change-stale-flow-deficit@trailofbits.com \
    --to=sam.moelius@trailofbits.com \
    --cc=cake@lists.bufferbloat.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=toke@toke.dk \
    /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