Re: [PATCH 2/2] sched: use static_branch_likely() for the NUMA balancing tick check

From: Gregory Price (Meta)

Date: Sat Oct 24 2026 - 02:28:40 EST


On 2026-10-23 17:49 +0200, Vincent Guittot wrote:
> On Fri, 23 Oct 2026 at 17:21, Gregory Price (Meta) <gourry@xxxxxxxxxx> wrote:
> >
> > On 2026-10-23 14:23 +0200, Vincent Guittot wrote:
> > > On Fri, 23 Oct 2026 at 04:31, Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
> > > >
> > > > task_tick_fair() checks sched_numa_balancing on every tick. The
> > > > static_branch_unlikely() annotation reserves the nop for the disabled case,
> > > > so the default configuration (NUMA_BALANCING_DEFAULT_ENABLED=y) pays a
> > > > taken jump per tick. Flip the polarity to static_branch_likely() so that
> > > > the fast path matches the default.
> > > >
> > > > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > > > Acked-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> > > > ---
> > > > kernel/sched/fair.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > > > index 973647ad6c2d..71dc47d6114d 100644
> > > > --- a/kernel/sched/fair.c
> > > > +++ b/kernel/sched/fair.c
> > > > @@ -15351,7 +15351,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
> > > > if (queued)
> > > > return;
> > > >
> > > > - if (static_branch_unlikely(&sched_numa_balancing))
> > > > + if (static_branch_likely(&sched_numa_balancing))
> > >
> > > static_branch_unlikely is used by default for other static keys too
> > > like sched_cluster_active, sched_cache_active, __sched_core_enabled
> > > sched_asym_cpucapacity and others ...
> >
> > every other instance checking sched_numa_balancing checks likely(), this
> > is the odd one out.
>
> Some other places might be behind another key but otherwise it should
> be unlikely()
>

On second look, I made a poor assumption on it being enabled by default.

On single-node systems, the key is off by default, even if numa
balancing is built in. I don't think this change makes a huge
difference either way - but probably just drop this patch.

~Gregory

--
~Gregory