RE: [RFC PATCH v2 10/23] sched/topology: Add per-sd scratch for the load balance affinity score

From: Jianyong Wu

Date: Tue Sep 01 2026 - 07:55:52 EST




> -----Original Message-----
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Sent: Tuesday, September 1, 2026 4:02 PM
> To: Jianyong Wu <wujianyong@xxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>; Juri Lelli <juri.lelli@xxxxxxxxxx>;
> Vincent Guittot <vincent.guittot@xxxxxxxxxx>; Chen Yu
> <yu.c.chen@xxxxxxxxx>; Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>; Dietmar
> Eggemann <dietmar.eggemann@xxxxxxx>; Steven Rostedt
> <rostedt@xxxxxxxxxxx>; Ben Segall <bsegall@xxxxxxxxxx>; Mel Gorman
> <mgorman@xxxxxxx>; Valentin Schneider <vschneid@xxxxxxxxxx>; K
> Prateek Nayak <kprateek.nayak@xxxxxxx>; Shrikanth Hegde
> <sshegde@xxxxxxxxxxxxx>; Phil Auld <pauld@xxxxxxxxxx>; Andrew
> Morton <akpm@xxxxxxxxxxxxxxxxxxxx>; David Hildenbrand
> <david@xxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx; linux-mm@xxxxxxxxx;
> jianyong.wu@xxxxxxxxxxx; Yuan Zhong <zhongyuan@xxxxxxxx>; Huangsj
> <huangsj@xxxxxxxx>; Fengyu Wang <wangfengyu@xxxxxxxx>; Zhiwei Ying
> <yingzhiwei@xxxxxxxx>; justin.he@xxxxxxx
> Subject: Re: [RFC PATCH v2 10/23] sched/topology: Add per-sd scratch for
> the load balance affinity score
>
> 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?

Right. These arrays contain llc_max entries and are only used when llc_max is non-zero. I will add the missing __counted_by_ptr(llc_max) annotation.

Thanks
Jianyong
>
> > #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));