Skip to contentSkip to conversation

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

PATCH In review Zhan Xusheng 2 participants 2 messages Nov 4 Scheduler

lore
Share & tools
lore
#0 lore raw

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

From: Zhan Xusheng <[email protected]>

invalid_llc_nr() checks that a process's running threads stay below 80% of the LLC's cores, scaled by llc_aggr_tolerance, with fits_capacity(). fits_capacity() is meant for capacity values; here it only supplies the 20% margin.

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.

---
Qais's series changes fits_capacity() to take a CPU number as its second argument [1]; this call would then pass the CPU count as a CPU number without a warning.

v2: reword the comment (Tim); move the reason above out of the
changelog; add the Reviewed-by tags.
v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/

 kernel/sched/fair.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/sched/fair.c +8 -2
index cfc982205b98..a7467fe425e6 100644
@@ -1469,6 +1469,12 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
 	return false;
 }
 
+/* Number of running threads below 80% of LLC's cores for default setting */
+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));
 }
 
 /*
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw

Hi Zhan!

Quoted 1 line · Zhan Xusheng

From: Zhan Xusheng <[email protected]>

I said myself that I'll review this someday. But forgot when to :/.

Hope I'm not too late.

Quoted 8 lines

invalid_llc_nr() checks that a process's running threads stay below 80% of the LLC's cores, scaled by llc_aggr_tolerance, with fits_capacity(). fits_capacity() is meant for capacity values; here it only supplies the 20% margin.

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.

Magic of 256.

Quoted 49 lines

---
Qais's series changes fits_capacity() to take a CPU number as its second argument [1]; this call would then pass the CPU count as a CPU number without a warning.

v2: reword the comment (Tim); move the reason above out of the
changelog; add the Reviewed-by tags.
v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/

 kernel/sched/fair.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/sched/fair.c +8 -2
index cfc982205b98..a7467fe425e6 100644
@@ -1469,6 +1469,12 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
 	return false;
 }
 
+/* Number of running threads below 80% of LLC's cores for default setting */
+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));
 }
 
 /*
Signature · 1 line
2.43.0

Yeah well they behave the same.

I'll normally say Thanks, but I'll try 'cheers' for today.

Cheers,

Kayra