Re: [RFC PATCH v2 02/23] sched/topology: Introduce a NUMA distance matrix with unique distance values

From: Peter Zijlstra

Date: Tue Sep 01 2026 - 04:53:20 EST


On Thu, Aug 27, 2026 at 08:27:55PM +0800, Jianyong Wu wrote:
> Builds a refined node distance matrix based on the raw NUMA distance matrix
> provided by BIOS. The refined matrix preserves the relative ordering of
> NUMA distances, while assigning distinct distance values to node pairs that
> originally shared identical distances within each matrix row. This matrix
> is exclusively used for cache-aware scheduling and has no impact on existing
> NUMA topology logic such as sched domain construction.
>
> For example, consider a system with 4 NUMA nodes. The raw BIOS-provided
> distance matrix may look like this:
>
> NODE0 NODE1 NODE2 NODE3
> NODE0 10 20 20 30
> NODE1 20 10 20 25
> NODE2 20 20 10 20
> NODE3 30 25 20 10
>
> Multiple duplicate distance values exist within each row. After the
> deduplication step, the refined distance matrix becomes:
>
> NODE0 NODE1 NODE2 NODE3
> NODE0 10 15 20 30
> NODE1 15 10 12 25
> NODE2 20 12 10 15
> NODE3 30 25 15 10
>
> All entries in each row are now unique, while adhering to two core principles:
> 1. The relative distance ordering from the original matrix is preserved.
> For instance, original distance(NODE0, NODE1) < distance(NODE0, NODE3),
> and this relative relationship is retained in the refined matrix as well.
> 2. The matrix remains symmetric across its main diagonal. Maintaining
> symmetry is critical to guarantee consistent pairwise node distances.
>
> Each row of this refined NUMA distance matrix is sorted in ascending order to
> generate a unique per-node affinity sequence. This sequence will guide
> thread migration logic introduced in subsequent patches.

Hmm, I wonder if __build_all_zonelists() wants to use this, rather than
the unmodified distance table. This would ensure the node fallback order
is distinct between nodes.