Re: [PATCH v3 07/21] sched/cache: Introduce per CPU's tasks LLC preference counter
From: Chen, Yu C
Date: Fri Feb 20 2026 - 11:58:08 EST
On 2/20/2026 6:45 PM, Peter Zijlstra wrote:
On Tue, Feb 10, 2026 at 02:18:47PM -0800, Tim Chen wrote:
diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
index a4e2fb31f2fd..3aa6c101b2e4 100644
--- a/include/linux/sched/topology.h
+++ b/include/linux/sched/topology.h
@@ -102,6 +102,10 @@ struct sched_domain {
u64 max_newidle_lb_cost;
unsigned long last_decay_max_lb_cost;
+#ifdef CONFIG_SCHED_CACHE
+ unsigned int *pf;
So I'm all for short names; but perhaps this could be better. When
reading this my brain went page-fault, and then WTF :-)
OK, I assume you are suggesting renaming it to llc_counts.
+#endif
+
#ifdef CONFIG_SCHEDSTATS
/* sched_balance_rq() stats */
unsigned int lb_count[CPU_MAX_IDLE_TYPES];
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index ca46b5cf7f78..dae78b5915a7 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2723,6 +2778,13 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att
}
rcu_read_unlock();
+ /*
+ * Ensure we see enlarged sd->pf when we use new llc_ids and
+ * bigger max_llcs.
+ */
+ smp_mb();
+ max_llcs = tl_max_llcs;
This seems wrong. This is *after* cpu_attach_domain() which publishes
@sd. How about you do something like:
struct sched_domain {
...
unsigned int llc_max;
unsigned int *llc_counts __counted_by(llc_max);
}
Then you always carry matching information that is published together.
OK, we will change it accordingly.
Additionally, with this change we should be able to safely read
the data in the sched_domain by verifying whether the target llc_id
falls within the valid range(to avoid a race condition):
CPU0 CPU1
:
...
build_sched_domains update_sg_lb_stats
for_each_cpu_and(i, sg)
sd=rq[i]->sd
per_cpu(sd_llc_id,i)=new_llc
llc=llc_id(i)
if(llc<sd->llc_max)
safe read sd->pf[llc]
alloc_sd_pref(cpu_map)
sd->llc_counts=kzalloc()
sd->llc_max=max_llc
Thanks,
Chenyu