Re: [RFC PATCH v2 10/23] sched/topology: Add per-sd scratch for the load balance affinity score
From: Peter Zijlstra
Date: Tue Sep 01 2026 - 04:02:59 EST
On Thu, Aug 27, 2026 at 08:28:03PM +0800, Jianyong Wu wrote:
> The affinity score computed during load balancing needs two small arrays,
> one entry per LLC: the LLCs that sit closer to the balance destination than
> to the source, and the weight of each. Their size is only known once the
> sched domains have been built, which is why the load balancer currently has
> to allocate them on every call.
>
> Signed-off-by: Jianyong Wu <wujianyong@xxxxxxxx>
> ---
> include/linux/sched/topology.h | 6 ++++++
> kernel/sched/topology.c | 28 +++++++++++++++++++++++++++-
> 2 files changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
> index b31d2cf16592..569ff562dbdb 100644
> --- a/include/linux/sched/topology.h
> +++ b/include/linux/sched/topology.h
> @@ -122,6 +122,12 @@ struct sched_domain {
> unsigned int *llc_counts __counted_by_ptr(llc_max);
> unsigned long llc_bytes;
> unsigned int *numa_counts;
> + /*
> + * Scratch for the load balance affinity score, llc_max entries each.
> + * Only the bottom sd owns them, like llc_counts above.
> + */
> + int *affi_ids;
> + int *affi_weights;
Per the below, these should also have: __counted_by_ptr(llc_max), right?
> #endif
> + p_ids = kcalloc_node(max_lid + 1, sizeof(int),
> + GFP_KERNEL, cpu_to_node(i));
> + p_w = kcalloc_node(max_lid + 1, sizeof(int),
> + GFP_KERNEL, cpu_to_node(i));