All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/cache: Don't use fits_capacity() to compare thread and CPU counts
@ 2026-11-02  2:15 Zhan Xusheng
  2026-11-03  1:31 ` Qais Yousef
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Zhan Xusheng @ 2026-11-02  2:15 UTC (permalink / raw)
  To: peterz, mingo
  Cc: qyousef, tim.c.chen, yu.c.chen, vincent.guittot, juri.lelli,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	linux-kernel, zhanxusheng

From: Zhan Xusheng <zhanxusheng@xiaomi.com>

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.

Link: https://lore.kernel.org/all/20260504020003.71306-5-qyousef@layalina.io/
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
This keeps the 20% margin.  Qais would rather not add hardcoded
margins, and llc_aggr_tolerance already scales the LLC size here, so
the margin could go, but that changes when a process stops being
aggregated.  Tim, Chen Yu, would you drop it?

 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 cfc982205b98..dfd6528d18ee 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));
 }
 
 /*

base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-09  9:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02  2:15 [PATCH] sched/cache: Don't use fits_capacity() to compare thread and CPU counts Zhan Xusheng
2026-11-03  1:31 ` Qais Yousef
2026-11-03  2:24   ` Chen Yu
2026-11-03 21:07   ` Tim Chen
2026-11-03  2:27 ` Chen Yu
2026-11-03 18:30 ` Tim Chen
2026-11-03 18:34 ` Tim Chen
2026-11-09  8:38 ` [tip: sched/urgent] " tip-bot2 for Zhan Xusheng
2026-11-09  9:28 ` [tip: sched/core] " tip-bot2 for Zhan Xusheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.