[tip: sched/core] sched/fair: Add cgroup_mode: tasks
From: tip-bot2 for Peter Zijlstra
Date: Tue Jun 30 2026 - 05:05:46 EST
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 507f910a4e1f140a245b693441b42bcbc8128938
Gitweb: https://git.kernel.org/tip/507f910a4e1f140a245b693441b42bcbc8128938
Author: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
AuthorDate: Fri, 05 Jun 2026 10:35:01 +02:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Tue, 30 Jun 2026 10:56:53 +02:00
sched/fair: Add cgroup_mode: tasks
Since we are exploring this space; include a scheme that scales by total number
of runnable tasks. This results in:
F_g_n' = M * F_g_n
This will obviously have: avg(F_g_n') > 1, (it will be ~M/N in fact).
And while that sounds odd, it actually has a fairly straight foward meaning for
"cpu.weight": average weight per member task.
This is an entirely valid and workable option, it is however wildly different
from the traditional meaning.
Included for completeness (and curiosity).
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260605124051.921991975%40infradead.org
---
kernel/sched/debug.c | 1 +
kernel/sched/fair.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index a5e3f8a..464d0e4 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -642,6 +642,7 @@ static const char *cgroup_mode_str[] = {
"smp",
"concur",
"max",
+ "tasks",
};
static int sched_cgroup_mode(const char *str)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 64181e4..4a204eb 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4852,6 +4852,19 @@ static inline int tg_tasks(struct task_group *tg)
}
/*
+ * Func: fraction(nr_tasks * tg->shares)
+ *
+ * Scale tg->shares by the number of tasks.
+ */
+static long calc_tasks_shares(struct cfs_rq *cfs_rq)
+{
+ struct task_group *tg = cfs_rq->tg;
+ int nr = tg_tasks(tg);
+ long tg_shares = READ_ONCE(tg->shares);
+ return __calc_smp_shares(cfs_rq, nr * tg_shares, nr * tg_shares);
+}
+
+/*
* Func: min(fraction(nr_cpus * tg->shares), nice -20)
*
* Scale tg->shares by the maximal number of CPUs; but clip the max shares at
@@ -4921,6 +4934,9 @@ void __sched_cgroup_mode_update(int mode)
case 3:
func = &calc_max_shares;
break;
+ case 4:
+ func = &calc_tasks_shares;
+ break;
}
static_call_update(calc_group_shares, func);
}