* [Cake] [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config
@ 2026-01-13 14:31 Toke Høiland-Jørgensen
2026-01-14 7:58 ` [Cake] " Eric Dumazet
2026-01-19 14:19 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-01-13 14:31 UTC (permalink / raw)
To: Toke Høiland-Jørgensen, Jamal Hadi Salim, Cong Wang,
Jiri Pirko
Cc: Toke Høiland-Jørgensen, Paolo Abeni, David S. Miller,
Eric Dumazet, Jakub Kicinski, Simon Horman, cake, netdev
Paolo pointed out that we can avoid separately allocating struct
cake_sched_config even in the non-mq case, by embedding it into struct
cake_sched_data. This reduces the complexity of the logic that swaps the
pointers and frees the old value, at the cost of adding 56 bytes to the
latter. Since cake_sched_data is already almost 17k bytes, this seems
like a reasonable tradeoff.
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
net/sched/sch_cake.c | 29 ++++++-----------------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index e30ef7f8ee68..fd56b7d88301 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -221,6 +221,7 @@ struct cake_sched_data {
struct tcf_block *block;
struct cake_tin_data *tins;
struct cake_sched_config *config;
+ struct cake_sched_config initial_config;
struct cake_heap_entry overflow_heap[CAKE_QUEUES * CAKE_MAX_TINS];
@@ -2798,8 +2799,6 @@ static void cake_destroy(struct Qdisc *sch)
qdisc_watchdog_cancel(&q->watchdog);
tcf_block_put(q->block);
kvfree(q->tins);
- if (q->config && !q->config->is_shared)
- kvfree(q->config);
}
static void cake_config_init(struct cake_sched_config *q, bool is_shared)
@@ -2822,13 +2821,9 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt,
struct netlink_ext_ack *extack)
{
struct cake_sched_data *qd = qdisc_priv(sch);
- struct cake_sched_config *q;
+ struct cake_sched_config *q = &qd->initial_config;
int i, j, err;
- q = kzalloc(sizeof(*q), GFP_KERNEL);
- if (!q)
- return -ENOMEM;
-
cake_config_init(q, false);
sch->limit = 10240;
@@ -2842,14 +2837,13 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt,
if (opt) {
err = cake_change(sch, opt, extack);
-
if (err)
- goto err;
+ return err;
}
err = tcf_block_get(&qd->block, &qd->filter_list, sch, extack);
if (err)
- goto err;
+ return err;
quantum_div[0] = ~0;
for (i = 1; i <= CAKE_QUEUES; i++)
@@ -2857,10 +2851,8 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt,
qd->tins = kvcalloc(CAKE_MAX_TINS, sizeof(struct cake_tin_data),
GFP_KERNEL);
- if (!qd->tins) {
- err = -ENOMEM;
- goto err;
- }
+ if (!qd->tins)
+ return -ENOMEM;
for (i = 0; i < CAKE_MAX_TINS; i++) {
struct cake_tin_data *b = qd->tins + i;
@@ -2893,22 +2885,13 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt,
qd->last_checked_active = 0;
return 0;
-err:
- kvfree(qd->config);
- qd->config = NULL;
- return err;
}
static void cake_config_replace(struct Qdisc *sch, struct cake_sched_config *cfg)
{
struct cake_sched_data *qd = qdisc_priv(sch);
- struct cake_sched_config *q = qd->config;
qd->config = cfg;
-
- if (!q->is_shared)
- kvfree(q);
-
cake_reconfigure(sch);
}
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [Cake] Re: [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config
2026-01-13 14:31 [Cake] [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config Toke Høiland-Jørgensen
@ 2026-01-14 7:58 ` Eric Dumazet
2026-01-14 10:54 ` Toke Høiland-Jørgensen
2026-01-19 14:19 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2026-01-14 7:58 UTC (permalink / raw)
To: Toke Høiland-Jørgensen
Cc: Toke Høiland-Jørgensen, Jamal Hadi Salim, Cong Wang,
Jiri Pirko, Paolo Abeni, David S. Miller, Jakub Kicinski,
Simon Horman, cake, netdev
On Tue, Jan 13, 2026 at 3:32 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> Paolo pointed out that we can avoid separately allocating struct
> cake_sched_config even in the non-mq case, by embedding it into struct
> cake_sched_data. This reduces the complexity of the logic that swaps the
> pointers and frees the old value, at the cost of adding 56 bytes to the
> latter. Since cake_sched_data is already almost 17k bytes, this seems
> like a reasonable tradeoff.
>
> Suggested-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
This is also fixing a panic, so :
Fixes: bc0ce2bad36c ("net/sched: sch_cake: Factor out config variables
into separate struct")
For the record, a fix for the panic would be :
diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index e30ef7f8ee6862a916acc06e568e37f35fd675b1..742fb850e2afb159f215b263bc36c372552911bc
100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -2825,6 +2825,8 @@ static int cake_init(struct Qdisc *sch, struct
nlattr *opt,
struct cake_sched_config *q;
int i, j, err;
+ qdisc_watchdog_init(&qd->watchdog, sch);
+
q = kzalloc(sizeof(*q), GFP_KERNEL);
if (!q)
return -ENOMEM;
@@ -2838,7 +2840,6 @@ static int cake_init(struct Qdisc *sch, struct
nlattr *opt,
qd->cur_flow = 0;
qd->config = q;
- qdisc_watchdog_init(&qd->watchdog, sch);
if (opt) {
err = cake_change(sch, opt, extack);
^ permalink raw reply [flat|nested] 4+ messages in thread* [Cake] Re: [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config
2026-01-14 7:58 ` [Cake] " Eric Dumazet
@ 2026-01-14 10:54 ` Toke Høiland-Jørgensen
0 siblings, 0 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-01-14 10:54 UTC (permalink / raw)
To: Eric Dumazet
Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, Paolo Abeni,
David S. Miller, Jakub Kicinski, Simon Horman, cake, netdev
Eric Dumazet <edumazet@google.com> writes:
> On Tue, Jan 13, 2026 at 3:32 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>> Paolo pointed out that we can avoid separately allocating struct
>> cake_sched_config even in the non-mq case, by embedding it into struct
>> cake_sched_data. This reduces the complexity of the logic that swaps the
>> pointers and frees the old value, at the cost of adding 56 bytes to the
>> latter. Since cake_sched_data is already almost 17k bytes, this seems
>> like a reasonable tradeoff.
>>
>> Suggested-by: Paolo Abeni <pabeni@redhat.com>
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> ---
>
> This is also fixing a panic, so :
>
> Fixes: bc0ce2bad36c ("net/sched: sch_cake: Factor out config variables
> into separate struct")
>
> For the record, a fix for the panic would be :
Ah yes, of course; thanks for noticing (and for the tag)!
-Toke
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cake] Re: [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config
2026-01-13 14:31 [Cake] [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config Toke Høiland-Jørgensen
2026-01-14 7:58 ` [Cake] " Eric Dumazet
@ 2026-01-19 14:19 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-19 14:19 UTC (permalink / raw)
To: =?utf-8?b?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2VuIDx0b2tlQHJlZGhhdC5jb20+?=
Cc: toke, jhs, xiyou.wangcong, jiri, pabeni, davem, edumazet, kuba,
horms, cake, netdev
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 13 Jan 2026 15:31:56 +0100 you wrote:
> Paolo pointed out that we can avoid separately allocating struct
> cake_sched_config even in the non-mq case, by embedding it into struct
> cake_sched_data. This reduces the complexity of the logic that swaps the
> pointers and frees the old value, at the cost of adding 56 bytes to the
> latter. Since cake_sched_data is already almost 17k bytes, this seems
> like a reasonable tradeoff.
>
> [...]
Here is the summary with links:
- [net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config
https://git.kernel.org/netdev/net-next/c/2a85541d95f7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-19 14:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-13 14:31 [Cake] [PATCH net-next] net/sched: cake: avoid separate allocation of struct cake_sched_config Toke Høiland-Jørgensen
2026-01-14 7:58 ` [Cake] " Eric Dumazet
2026-01-14 10:54 ` Toke Høiland-Jørgensen
2026-01-19 14:19 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox