Re: [PATCH v3 04/21] sched/cache: Make LLC id continuous
From: Peter Zijlstra
Date: Fri Feb 20 2026 - 11:03:59 EST
On Fri, Feb 20, 2026 at 11:53:31PM +0800, Chen, Yu C wrote:
> Hi Peter,
>
> On 2/19/2026 11:40 PM, Peter Zijlstra wrote:
> > On Mon, Feb 16, 2026 at 01:14:20PM +0530, K Prateek Nayak wrote:
>
> [ ... ]
>
> > > +static int __sched_domains_alloc_llc_id(void)
> > > +{
> > > + int lid;
> > > +
> > > + lockdep_assert_held(&sched_domains_mutex);
> > > +
> > > + lid = cpumask_first_zero(sched_domains_llc_id_allocmask);
> > > + if (lid >= tl_max_llcs)
> > > + tl_max_llcs++;
> >
> > Urgh,. should we not rather track the max lid?
> >
>
> Do you mean we should not always increment the max lid,
> but instead decrease it when an llc_id is released?
> I think Tim has adjusted the code to shrink tl_max_llcs
> when an llc_id is released:
> https://lore.kernel.org/all/acc7a5c96e8235bf11af640798ce1b60bcaa8196.camel@xxxxxxxxxxxxxxx/
You can only shrink when the max lid is released. Since lid is an array
index, something like max_lid = weight(mask) would be terribly broken.
But what I was getting at is that the code as presented there is rather
non-obvious. Yes, if the lid is higher, it cannot be more than one
higher than the previous value, but something like:
lid = cpumask_first_zero();
BUG_ON(lid >= nr_cpu_ids);
max_lid = max(max_lid, lid);
Is way simpler to follow since it doesn't have that hidden assumption.
Then, if you want to allow shrinking, then the clear side could do
something like:
__cpumask_clear(lid, mask);
if (lid == max_lid)
max_lid = cpumask_last(mask);
or something like that.
> > Also, we allocate max_llc sized data structures, if this thing is
> > 'variable' we must also always store a copy of the 'lid' size of the
> > time of allocation.
> >
>
> Do you mean we should save the latest llc_max in the sched_domain
> and publish it during sd attachment, as suggested at:
>
> https://lore.kernel.org/all/20260220104533.GO1395266@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Yeah, having it separated like it is now feels super fragile.