mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jianyong Wu <wujianyong@hygon.cn>
To: Tim Chen <tim.c.chen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Chen Yu <yu.c.chen@intel.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Phil Auld <pauld@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"David Hildenbrand" <david@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"jianyong.wu@outlook.com" <jianyong.wu@outlook.com>,
	Yuan Zhong <zhongyuan@hygon.cn>, Huangsj <huangsj@hygon.cn>,
	Fengyu Wang <wangfengyu@hygon.cn>,
	Zhiwei Ying <yingzhiwei@hygon.cn>,
	"justin.he@arm.com" <justin.he@arm.com>
Subject: RE: [RFC PATCH v2 02/23] sched/topology: Introduce a NUMA distance matrix with unique distance values
Date: Wed, 23 Sep 2026 03:14:47 +0000	[thread overview]
Message-ID: <09261c8222994a41a04ace5f342475df@hygon.cn> (raw)
In-Reply-To: <da32ba66d95fd88869ba052f97698b9a4d6c3dc6.camel@linux.intel.com>

Hi Tim,

Thanks for your suggestion.

> -----Original Message-----
> From: Tim Chen <tim.c.chen@linux.intel.com>
> Sent: Wednesday, September 23, 2026 2:39 AM
> To: Peter Zijlstra <peterz@infradead.org>; Jianyong Wu
> <wujianyong@hygon.cn>
> Cc: Ingo Molnar <mingo@redhat.com>; Juri Lelli <juri.lelli@redhat.com>;
> Vincent Guittot <vincent.guittot@linaro.org>; Chen Yu
> <yu.c.chen@intel.com>; Dietmar Eggemann
> <dietmar.eggemann@arm.com>; Steven Rostedt <rostedt@goodmis.org>;
> Ben Segall <bsegall@google.com>; Mel Gorman <mgorman@suse.de>;
> Valentin Schneider <vschneid@redhat.com>; K Prateek Nayak
> <kprateek.nayak@amd.com>; Shrikanth Hegde <sshegde@linux.ibm.com>;
> Phil Auld <pauld@redhat.com>; Andrew Morton
> <akpm@linux-foundation.org>; David Hildenbrand <david@kernel.org>;
> linux-kernel@vger.kernel.org; linux-mm@kvack.org;
> jianyong.wu@outlook.com; Yuan Zhong <zhongyuan@hygon.cn>; Huangsj
> <huangsj@hygon.cn>; Fengyu Wang <wangfengyu@hygon.cn>; Zhiwei Ying
> <yingzhiwei@hygon.cn>; justin.he@arm.com
> Subject: Re: [RFC PATCH v2 02/23] sched/topology: Introduce a NUMA
> distance matrix with unique distance values
> 
> On Mon, 2026-08-31 at 13:50 +0200, Peter Zijlstra wrote:
> > 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.
> >
> > This example uses Node only, but the code in question is specifically
> > aimed at Cache granularity; might it be better to use a cache example?
> >
> > A little something like so (I got tired of prompting Gemini to generate
> > more complicates / less broken examples)...
> >
> > Pre:
> >
> > Cache |  C0   C1 |  C2   C3 |  C4   C5 |  C6   C7
> > ------+----------+----------+----------+---------
> >   C0  |  10   10 |  20   20 |  20   20 |  20   20
> >   C1  |  10   10 |  20   20 |  20   20 |  20   20
> > ------+----------+----------+----------+---------
> >   C2  |  20   20 |  10   10 |  20   20 |  20   20
> >   C3  |  20   20 |  10   10 |  20   20 |  20   20
> > ------+----------+----------+----------+---------
> >   C4  |  20   20 |  20   20 |  10   10 |  20   20
> >   C5  |  20   20 |  20   20 |  10   10 |  20   20
> > ------+----------+----------+----------+---------
> >   C6  |  20   20 |  20   20 |  20   20 |  10   10
> >   C7  |  20   20 |  20   20 |  20   20 |  10   10
> 
> I think what we really want is an ordering of caches within
> the same NUMA node.  So when one cache is full, we can
> pick the next one down the list.  That is essentially the
> net effect of the distance de-duplication.

The goal of this series is to provide a system-wide LLC affinity
ordering, rather than only an ordering of the LLCs within one NUMA node.

Maintaining one large system-wide LLC ordering would be expensive, so
the ordering is represented hierarchically: a NUMA-node-level affinity
ordering, followed by an LLC-level ordering within each node.  This
patch only deals with the NUMA-node-level part.

> 
> So how about introduce a llc_next array.  We will initialize
> the array such that it will return the next LLC in
> the NUMA node.  So for the example that Peter has above,
> assuming C0 maps to LLC id 0, C1 maps to 1, etc.
> then llc_next is
> 
> 	    c0 c1 c2 c3 c4 c5 c6 c7
> llc_next = [1  0  3  2  5  4  7  6]
> 
> When we come back to the orginal LLC we start off with,
> we know that it is time to move on to a LLC in next closest
> NUMA node.
>
How should the next closest NUMA node be selected when multiple nodes
have the same distance from the current node?

That is the ambiguity this patch is intended to resolve. For each
source node, it disambiguates equal NUMA distances and produces a
unique node-level affinity ordering. An llc_next array can describe
the traversal of LLCs within a node, but it does not determine which
equidistant NUMA node should be visited next.

> This will be storage efficient and more straight forward
> to use than maintaining an artificial cache distance matrix.
> 
> I dislike the artificial distance matrix also for the
> reason that there is no guarantee that there are enough
> available distance slots between two nodes.  Say if I
> start with
> 
>         NODE0  NODE1  NODE2  NODE3
> NODE0   10     20     20     30
> NODE1   20     10     20     25
> NODE2   20     20     10     20
> NODE3   30     25     20     10
> 
> and there are 16 LLCs in NODE 1, I will run
> out of slots when I try to deduplicate as
> only 10 slots are available to fit 16 LLCs.
>

There is no system-wide LLC distance matrix in this series. The
de-duplication is applied only to the NUMA-node distance matrix.
Consequently, the number of LLCs in NODE1 does not affect the number
of distance values required by this patch.

The algorithm also takes the available distance space into account
when assigning the refined node distances. It does not simply insert
one value for each duplicate into the existing gap between two
original distance levels. The distance values are adjusted as
necessary to reserve enough space before the duplicates are assigned.
Therefore, the algorithm cannot run out of available distance values,
regardless of the number of nodes sharing the same original distance.

In addition to providing the node-level component of the LLC affinity
ordering, the refined node distances are used to calculate the
affinity improvement score when selecting a source scheduling group
or runqueue during load balancing. Please see patch 12 for that usage.

Thanks
Jianyong

> Tim
> 
> >
> > Post:
> >
> > Cache |  C0   C1 |  C2   C3 |  C4   C5 |  C6   C7
> > ------+----------+----------+----------+---------
> >   C0  |  10   11 |  20   21 |  22   23 |  24   25
> >   C1  |  11   10 |  21   20 |  23   22 |  25   24
> > ------+----------+----------+----------+---------
> >   C2  |  20   21 |  10   11 |  24   25 |  22   23
> >   C3  |  21   20 |  11   10 |  25   24 |  23   22
> > ------+----------+----------+----------+---------
> >   C4  |  22   23 |  24   25 |  10   11 |  20   21
> >   C5  |  23   22 |  25   24 |  11   10 |  21   20
> > ------+----------+----------+----------+---------
> >   C6  |  24   25 |  22   23 |  20   21 |  10   11
> >   C7  |  25   24 |  23   22 |  21   20 |  11   10
> >
> >
> > > 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.
> >
> > IIRC greedy has significant worse bounds than many other schemes. This
> > would result in more unique distances than strictly needed here, right?
> >
> > Since this is all on slow paths anyway, does it make sense to pick a
> > slightly better algorithm in order to reduce this bound and get better
> > results?
> >
> > Anyway, let me continue trying to dig through all this.


  reply	other threads:[~2026-09-23  3:14 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 12:27 [RFC PATCH v2 00/23] sched: Scale cache-aware aggregation at LLC granularity Jianyong Wu
2026-08-27 12:27 ` [RFC PATCH v2 01/23] sched/topology: Add llc_to_node() to translate LLC id to NUMA node Jianyong Wu
2026-08-29 10:31   ` Peter Zijlstra
2026-08-31  9:43     ` Jianyong Wu
2026-08-27 12:27 ` [RFC PATCH v2 02/23] sched/topology: Introduce a NUMA distance matrix with unique distance values Jianyong Wu
2026-08-31 11:50   ` Peter Zijlstra
2026-09-01  6:57     ` Jianyong Wu
2026-09-01  7:13       ` Peter Zijlstra
2026-09-01  7:37         ` Jianyong Wu
2026-09-22 18:38     ` Tim Chen
2026-09-23  3:14       ` Jianyong Wu [this message]
2026-09-23 18:29         ` Tim Chen
2026-09-24  5:41           ` Jianyong Wu
2026-09-24 15:46             ` Tim Chen
2026-09-01  8:48   ` Peter Zijlstra
2026-09-02  7:11     ` Jianyong Wu
2026-08-27 12:27 ` [RFC PATCH v2 03/23] sched/topology: Introduce a macro to traverse node Jianyong Wu
2026-08-27 12:27 ` [RFC PATCH v2 04/23] sched/topology: Introduce a method to calculate the llc distance Jianyong Wu
2026-08-31 13:12   ` Peter Zijlstra
2026-08-27 12:27 ` [RFC PATCH v2 05/23] sched/topology: Introduce a macro to traverse LLC inside node Jianyong Wu
2026-08-27 12:27 ` [RFC PATCH v2 06/23] sched/topology: Add sd_node for the NODE sched domain Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 07/23] sched/cache: Prioritize preferred NUMA node selection over LLC selection Jianyong Wu
2026-08-31 13:16   ` Peter Zijlstra
2026-09-01  7:44     ` Jianyong Wu
2026-08-31 13:22   ` Peter Zijlstra
2026-09-01  8:05     ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 08/23] sched/topology: Introduce a per-CPU tasks NUMA preferred counter Jianyong Wu
2026-08-31 13:23   ` Peter Zijlstra
2026-09-01  8:14     ` Jianyong Wu
2026-08-31 13:24   ` Peter Zijlstra
2026-09-01  8:31     ` Jianyong Wu
2026-09-01 10:21       ` Peter Zijlstra
2026-09-01 13:02         ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 09/23] sched/cache: Account percpu sd task NUMA preference Jianyong Wu
2026-09-01  7:54   ` Peter Zijlstra
2026-09-01  8:41     ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 10/23] sched/topology: Add per-sd scratch for the load balance affinity score Jianyong Wu
2026-09-01  8:02   ` Peter Zijlstra
2026-09-01 11:55     ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 11/23] sched/cache: Introduce helpers for task migration decisions Jianyong Wu
2026-09-01  9:08   ` Peter Zijlstra
2026-09-02  5:08     ` Jianyong Wu
2026-09-01 11:32   ` Peter Zijlstra
2026-09-02  5:46     ` Jianyong Wu
2026-09-02 21:11   ` Tim Chen
2026-09-03  2:04     ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 12/23] sched/cache: Introduce rq affinity gain calculation Jianyong Wu
2026-09-01  9:58   ` Peter Zijlstra
2026-09-01 12:23     ` Jianyong Wu
2026-09-01 10:16   ` Peter Zijlstra
2026-09-01 12:34     ` Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 13/23] sched/cache: Pick optimal src rq/group using affinity promotion metric Jianyong Wu
2026-08-27 12:28 ` [RFC PATCH v2 14/23] sched/cache: Drop prefer_sibling restriction for llc_balance Jianyong Wu
2026-09-01 10:29   ` Peter Zijlstra
2026-09-01 13:25     ` Jianyong Wu
2026-08-28  1:58 ` [RFC PATCH v2 15/23] sched/cache: Judge migration eligibility in LLC granularity Jianyong Wu
2026-08-28  2:04 ` [RFC PATCH v2 16/23] sched/cache: Allow un-throttled active balance to spread out of a full LLC Jianyong Wu
2026-08-28  2:07 ` [RFC PATCH v2 17/23] sched/fair: Fine-granularity NUMA balancing Jianyong Wu
2026-09-01 12:47   ` Peter Zijlstra
2026-09-02  6:43     ` Jianyong Wu
2026-08-28  2:09 ` [RFC PATCH v2 18/23] sched/cache: Scan all prefer nodes in thread group Jianyong Wu
2026-08-28  2:10 ` [RFC PATCH v2 19/23] sched/cache: Remove preferred LLC/node check no longer needed Jianyong Wu
2026-08-28  2:11 ` [RFC PATCH v2 20/23] sched/cache: Estimate utilization of the whole thread group Jianyong Wu
2026-09-01 14:44   ` Peter Zijlstra
2026-09-08  7:43     ` Jianyong Wu
2026-08-28  2:13 ` [RFC PATCH v2 21/23] sched/cache: Spread workloads within an estimated LLC range Jianyong Wu
2026-08-28  2:14 ` [RFC PATCH v2 22/23] sched/cache: Walk the preferred node from the preferred LLC Jianyong Wu
2026-08-28  2:15 ` [RFC PATCH v2 23/23] sched/debug: Print task preferred LLC for scheduler debugging Jianyong Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09261c8222994a41a04ace5f342475df@hygon.cn \
    --to=wujianyong@hygon.cn \
    --cc=akpm@linux-foundation.org \
    --cc=bsegall@google.com \
    --cc=david@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=huangsj@hygon.cn \
    --cc=jianyong.wu@outlook.com \
    --cc=juri.lelli@redhat.com \
    --cc=justin.he@arm.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=pauld@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wangfengyu@hygon.cn \
    --cc=yingzhiwei@hygon.cn \
    --cc=yu.c.chen@intel.com \
    --cc=zhongyuan@hygon.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®