[tip: sched/urgent] sched/cache: Don't use fits_capacity() to compare thread and CPU counts

From: tip-bot2 for Zhan Xusheng

Date: Mon Nov 09 2026 - 03:52:56 EST


The following commit has been merged into the sched/urgent branch of tip:

Commit-ID: 63e5dcd44ded2c83b468417381c3a5987a8f66d1
Gitweb: https://git.kernel.org/tip/63e5dcd44ded2c83b468417381c3a5987a8f66d1
Author: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
AuthorDate: Mon, 02 Nov 2026 10:15:36 +08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Fri, 06 Nov 2026 11:45:18 +01:00

sched/cache: Don't use fits_capacity() to compare thread and CPU counts

invalid_llc_nr() uses fits_capacity() to compare a thread count with a
CPU count, only for its 20% margin. Qais's series changes
fits_capacity() to take a CPU number as its second argument, and this
call would then pass the CPU count as a CPU number without a warning.

Give the check its own helper. x * 5 < y * 4 is the same comparison as
x * 1280 < y * 1024, so there is no functional change.

Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Qais Yousef <qyousef@xxxxxxxxxxx>
Reviewed-by: Chen Yu <yu.c.chen@xxxxxxxxx>
Reviewed-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/all/20260504020003.71306-5-qyousef@xxxxxxxxxxx/
Link: https://patch.msgid.link/20261102021536.1026143-1-zhanxusheng1024@xxxxxxxxx
---
kernel/sched/fair.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 79f6b3a..0c8af1c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1469,6 +1469,12 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
return false;
}

+/* Are the running threads (in SMT siblings) below ~80% of the LLC's CPUs? */
+static inline bool fits_llc_nr(u64 nr_threads, unsigned int nr_cpus)
+{
+ return nr_threads * 5 < (u64)nr_cpus * 4;
+}
+
static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,
int cpu)
{
@@ -1485,8 +1491,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,
if (scale == INT_MAX)
return false;

- return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads),
- (scale * per_cpu(sd_llc_size, cpu)));
+ return !fits_llc_nr(READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads,
+ scale * per_cpu(sd_llc_size, cpu));
}

/*