Re: [PATCH] sched/pelt: Skip redundant decay and divisions when sched_avg is zero

From: Chris Wiseman

Date: Mon Nov 16 2026 - 07:15:52 EST


On Mon, 16 Nov 2026 at 12:29, Vincent Guittot <vincent.guittot@xxxxxxxxxx> wrote:
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index f77e722..83d3928 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -11538,6 +11538,8 @@ static bool __update_blocked_fair(struct rq *rq, bool *done)
> >
> > if (cfs_rq == &rq->cfs)
> > decayed = true;
> > + } else if (cfs_rq->tg_load_avg_contrib) {
> > + update_tg_load_avg(cfs_rq);
>
> Normally the cfs_rq is removed once it has been decayed which
> includes tg_load_avg_contrib so they should not be updated
>
> This is because of your change which prevents updating update_tg_load_avg

Good point. We only needed that fair.c check because returning 0 from
___update_load_sum() stopped the next pass from clearing
tg_load_avg_contrib. Still returning periods from accumulate_sum() lets
us drop the fair.c change completely.

> > + if (unlikely(!(sa->load_sum | sa->runnable_sum | sa->util_sum |
> > + sa->load_avg))) {
>
> why load_avg ? when load_sum == 0, load_avg must be 0
>
> > + sa->period_contrib = (delta + sa->period_contrib) % 1024;
> > + return 0;
>
> I would prefer that this to be included in accumulate_sum before step 1
>
> Wouldn't it be enough to skip the decay_load and
> __accumulate_pelt_segments in accumulate_sum but still return the
> decay. And in ___update_load_avg() set the *_avg to 0 instead of doing
> the div when the *_sum is 0

Makes sense - if accumulate_sum() still returns periods and
___update_load_avg() sets *_avg to 0 when *_sum is 0, we don't need
load_avg in the check either. I'll send v2 with this.