RE: [RFC PATCH v2 12/23] sched/cache: Introduce rq affinity gain calculation

From: Jianyong Wu

Date: Tue Sep 01 2026 - 08:25:36 EST




> -----Original Message-----
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Sent: Tuesday, September 1, 2026 5:59 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 12/23] sched/cache: Introduce rq affinity gain
> calculation
>
> On Thu, Aug 27, 2026 at 08:28:05PM +0800, Jianyong Wu wrote:
>
> > #ifdef CONFIG_SCHED_CACHE
> > +extern int max_lid;
> > /*
> > * Record the statistics for this scheduler group for later
> > * use. These values guide load balancing on aggregating tasks
> > @@ -11998,6 +11999,174 @@ static bool update_llc_busiest(struct
> lb_env *env,
> > */
> > return sgs->nr_pref_dst_llc > busiest->nr_pref_dst_llc;
> > }
> > +
> > +/*
> > + * Get all LLCs that are closer to the destination LLC than to the
> > + * source LLC inside a NUMA.
> > + */
> > +static int get_affi_llcs(struct sched_domain *sd, int src_llc, int dst_llc,
> > + int *affi_llcs, int *affi)
> > +{
> > + int j = 0, src_dist, dst_dist, cur_node;
> > +
> > + if (src_llc == dst_llc || sd->flags & (SD_NUMA | SD_SHARE_LLC))
> > + return 0;
> > +
> > + cur_node = llc_to_node(src_llc);
> > + if (cur_node != llc_to_node(dst_llc))
> > + return 0;
> > +
> > + for (int i = 0; i <= max_lid; i++) {
>
> This isn't safe. max_lid isn't stable, you should use sd->llc_max which
> matches the actual allocation size of sd->llc_counts.

Yes, max_lid isn't stable. But get_affi_llcs() receives env->sd, whose
llc_max is 0 - llc_max is only set on the base sched domain (rq->sd).
Since calc_affinity_llc_score() already holds that base sd, I'll pass its
llc_max down to get_affi_llcs() as a parameter.

Thanks
Jianyong