Re: [RFC PATCH v2 12/23] sched/cache: Introduce rq affinity gain calculation

From: Peter Zijlstra

Date: Tue Sep 01 2026 - 06:07:23 EST


On Thu, Aug 27, 2026 at 08:28:05PM +0800, Jianyong Wu wrote:

> #ifdef CONFIG_SCHED_CACHE
> +extern int max_lid;
> /*
> * Record the statistics for this scheduler group for later
> * use. These values guide load balancing on aggregating tasks
> @@ -11998,6 +11999,174 @@ static bool update_llc_busiest(struct lb_env *env,
> */
> return sgs->nr_pref_dst_llc > busiest->nr_pref_dst_llc;
> }
> +
> +/*
> + * Get all LLCs that are closer to the destination LLC than to the
> + * source LLC inside a NUMA.
> + */
> +static int get_affi_llcs(struct sched_domain *sd, int src_llc, int dst_llc,
> + int *affi_llcs, int *affi)
> +{
> + int j = 0, src_dist, dst_dist, cur_node;
> +
> + if (src_llc == dst_llc || sd->flags & (SD_NUMA | SD_SHARE_LLC))
> + return 0;
> +
> + cur_node = llc_to_node(src_llc);
> + if (cur_node != llc_to_node(dst_llc))
> + return 0;
> +
> + for (int i = 0; i <= max_lid; i++) {

This isn't safe. max_lid isn't stable, you should use sd->llc_max which
matches the actual allocation size of sd->llc_counts.