Re: [PATCH v2 01/23] sched/cache: Introduce infrastructure for cache-aware load balancing
From: Tim Chen
Date: Tue Dec 09 2025 - 16:39:41 EST
On Tue, 2025-12-09 at 12:12 +0100, Peter Zijlstra wrote:
> On Wed, Dec 03, 2025 at 03:07:20PM -0800, Tim Chen wrote:
>
> > Minor fix in task_tick_cache() to use
> > if (mm->mm_sched_epoch >= rq->cpu_epoch)
> > to avoid mm_sched_epoch going backwards.
>
> > +static void task_tick_cache(struct rq *rq, struct task_struct *p)
> > +{
> > + struct callback_head *work = &p->cache_work;
> > + struct mm_struct *mm = p->mm;
> > +
> > + if (!sched_cache_enabled())
> > + return;
> > +
> > + if (!mm || !mm->pcpu_sched)
> > + return;
> > +
> > + /* avoid moving backwards */
> > + if (mm->mm_sched_epoch >= rq->cpu_epoch)
> > + return;
>
> IIRC this was supposed to be able to wrap; which then means you should
> write it like:
>
> if ((mm->mm_sched_epoch - rq->cpu_epoch) >= 0)
> return;
>
> or somesuch.
Okay. Got it.
Tim
>
> > +
> > + guard(raw_spinlock)(&mm->mm_sched_lock);
> > +
> > + if (work->next == work) {
> > + task_work_add(p, work, TWA_RESUME);
> > + WRITE_ONCE(mm->mm_sched_epoch, rq->cpu_epoch);
> > + }
> > +}