RE: [RFC PATCH v2 01/23] sched/topology: Add llc_to_node() to translate LLC id to NUMA node

From: Jianyong Wu

Date: Mon Aug 31 2026 - 05:47:54 EST


Hi Peter,

> -----Original Message-----
> From: owner-linux-mm@xxxxxxxxx <owner-linux-mm@xxxxxxxxx> On
> Behalf Of Peter Zijlstra
> Sent: Saturday, August 29, 2026 6:31 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 01/23] sched/topology: Add llc_to_node() to
> translate LLC id to NUMA node
>
> On Thu, Aug 27, 2026 at 08:27:54PM +0800, Jianyong Wu wrote:
> > +static void rebuild_llc_node_map(int size)
> > +{
> > + int *new_map, *old_map;
> > + u8 *seen_llc;
> > + int cpu, llc;
> > +
> > + new_map = kcalloc(size, sizeof(int), GFP_KERNEL);
> > + if (!new_map)
> > + return;
> > + seen_llc = kcalloc(size, sizeof(*seen_llc), GFP_KERNEL);
> > + if (!seen_llc) {
> > + kfree(new_map);
> > + return;
> > + }
> > +
> > + /*
> > + * for_each_possible_cpu() revisits the same LLC non-consecutively
> > + * under SMT (each node's LLCs are walked once per thread), so
> > + * dedup by llc id via seen_llc[], not by comparing against the
> > + * immediately preceding CPU's llc.
> > + */
> > + for_each_possible_cpu(cpu) {
> > + llc = per_cpu(sd_llc_id, cpu);
> > + if (llc < 0 || llc >= size || seen_llc[llc])
> > + continue;
> > + seen_llc[llc] = 1;
> > + new_map[llc] = cpu_to_node(cpu);
> > + }
> > + kfree(seen_llc);
> > +
> > + old_map = rcu_dereference_protected(llc_to_node_map, true);
> > + rcu_assign_pointer(llc_to_node_map, new_map);
> > + synchronize_rcu();
> > + kfree(old_map);
>
> Could that not be: kfree_rcu_mightsleep(old_map); ?
>
Yes, that would avoid synchronously waiting for the grace period here.
I'll replace synchronize_rcu() + kfree() with kfree_rcu_mightsleep() in the next version.

Thanks
Jianyong