Re: [RFC PATCH v2 01/23] sched/topology: Add llc_to_node() to translate LLC id to NUMA node
From: Peter Zijlstra
Date: Sat Aug 29 2026 - 06:31:32 EST
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); ?