Re: [RFC PATCH v2 04/23] sched/topology: Introduce a method to calculate the llc distance
From: Peter Zijlstra
Date: Mon Aug 31 2026 - 09:18:55 EST
On Thu, Aug 27, 2026 at 08:27:57PM +0800, Jianyong Wu wrote:
> The previous patch addresses NUMA inter-node distance handling. This
> patch shifts focus to the LLC layer and introduces a scheme to compute
> pairwise distances between sibling LLCs inside one NUMA node.
> The calculation only guarantees distinct distance values for all peers
> when viewed from a single reference LLC; it does not enforce globally
> unique distances for every arbitrary LLC pair on the node.
>
> One valid calculation scheme is defined by the formula below:
>
> dist(LLC1, LLC2) = (rank1 + rank2) % k + 1
>
> Constraints: LLC1 and LLC2 must reside on the identical NUMA node.
> rank1 = local index of LLC1 within its node; rank2 follows the same rule.
> k = total count of LLCs available on the node.
>
> The formula never yields zero, so diagonal self-distance entries are
> explicitly hardcoded to 0.
>
> For demonstration, consider a NUMA node with four LLCs (local ranks 0~3):
> LLC0 LLC1 LLC2 LLC3
> LLC0 0 2 3 4
> LLC1 2 0 4 1
> LLC2 3 4 0 2
> LLC3 4 1 2 0
>
> Sorting each matrix row in ascending order generates a unique LLC affinity
> sequence, which drives thread migration policies implemented in follow-up
> patches.
Aah, now I see. I got confused by your sched_cache_node_distance naming,
and thought it was cache-to-cache distance.