Re: [PATCH v3 04/21] sched/cache: Make LLC id continuous
From: Peter Zijlstra
Date: Fri Feb 20 2026 - 14:31:16 EST
On Fri, Feb 20, 2026 at 11:24:11AM -0800, Tim Chen wrote:
> +static int __sched_domains_alloc_llc_id(void)
> +{
> + int lid, max_lid;
> +
> + lockdep_assert_held(&sched_domains_mutex);
> +
> + lid = cpumask_first_zero(sched_domains_llc_id_allocmask);
> + /*
> + * llc_id space should never grow larger than the
> + * possible number of CPUs in the system.
> + */
> + BUG_ON(lid >= nr_cpu_ids);
__cpumask_set_cpu(lid, sched_domains_llc_is_allocmask);
> + max_lid = cpumask_last(sched_domains_llc_id_allocmask);
> + /* size is one more than max index */
> + tl_max_llcs = max(lid, max_lid) + 1;
> +
> + return lid;
> +}
> +
> +static void __sched_domains_free_llc_id(int cpu)
> +{
> + int i, lid, last_lid;
> +
> + lockdep_assert_held(&sched_domains_mutex);
> +
> + lid = per_cpu(sd_llc_id, cpu);
> + if (lid == -1)
> + return;
> +
> + BUG_ON(lid >= nr_cpu_ids);
> + per_cpu(sd_llc_id, cpu) = -1;
> +
> + for_each_cpu(i, cpu_coregroup_mask(cpu)) {
> + /* An online CPU owns the llc_id. */
> + if (per_cpu(sd_llc_id, i) == lid)
> + return;
> + }
> +
__cpumask_clear_cpu(lid, sched_domains_llc_id_allocmask);
> +
> + last_lid = cpumask_last(sched_domains_llc_id_allocmask);
> + /* shrink max LLC size to save memory */
> + if (last_lid < tl_max_llcs - 1)
> + tl_max_llcs = last_lid + 1;
> +}
Might be simpler to just track max_lid, and do the +1 at the alloc site?