Re: [Patch v4 02/22] sched/cache: Limit the scan number of CPUs when calculating task occupancy

Tim Chen
2026-04-10T17:12:08Z

On Fri, 2026-04-10 at 15:29 +0800, Chen, Yu C wrote:
> Hi Gengkun,
>
> On 4/9/2026 9:17 PM, Luo Gengkun wrote:
> >
> >
> > On 2026/4/2 5:52, Tim Chen wrote:
> > > From: Chen Yu <yu.c.chen@intel.com>
>
> [ ... ]
>
> >
> > To address the issue of scanning overhead, there is a more targeted
> > approach: only scanning the CPUs actually accessed by the process, and
> > evicting these CPUs when they remain unaccessed for a specific period of
> > time.
> >
>
> Thanks for the patch. This approach looks quite sensible to me, and
>
> [ ... ]
>
> >
> >         /*
> >          * The update to mm->sc_stat should not be reordered
> > @@ -1582,6 +1584,7 @@ void account_mm_sched(struct rq *rq, struct
> > task_struct *p, s64 delta_exec)
> >                 pcpu_sched->runtime += delta_exec;
> >                 rq->cpu_runtime += delta_exec;
> >                 epoch = rq->cpu_epoch;
> > +               cpumask_set_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
>
> I would refer a check before writing to avoid c2c overhead:
> if (!cpumask_test_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus))
> cpumask_set_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);

I think a similar check is also needed for clearing of visited CPU. It is possible that
the visited_cpus mask has already been cleared long time back. Change

+ if (llc_epoch_visited_timeout && (rq->cpu_epoch - pcpu_sched->epoch) >
+ llc_epoch_visited_timeout) {
+ cpumask_clear_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
+ continue;
+ }

to

+ if (llc_epoch_visited_timeout &&
+ cpumask_test_cpu(cpu_of(rq), &mm->sc_stat.visitied_cpus) &&
+ (rq->cpu_epoch - pcpu_sched->epoch) > llc_epoch_visited_timeout) {
+ cpumask_clear_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
+ continue;
+ }

Thanks.

Tim