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

From: Yafang Shao

Date: Sun Oct 25 2026 - 02:59:10 EST


On Fri, Oct 23, 2026 at 11:49 PM Vincent Guittot
<vincent.guittot@xxxxxxxxxx> 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()

Hello Vincent,

I checked the other places that use the sched_numa_balancing static
key. None of them is behind another key, and all but one also run
while the key is disabled:

fair.c: exceed_llc_capacity()
fair.c: get_pref_llc()
fair.c: get_scan_cpumasks()
fair.c: update_scan_period()
fair.c: migrate_degrades_locality()

The only exception is task_numa_fault(), which does not run when
NUMA balancing is disabled.

Please correct me if I'm wrong.

>
> >
> > > So systems which don't enable them don't pay a jump when not using it.
> > > I don't see why numa should be different
> > >
> >
> > numa balancing ships enabled by default.
>
> Others are also shipped enabled by default

sched_cluster_active, sched_cache_active, __sched_core_enabled and
sched_asym_cpucapacity are all DEFINE_STATIC_KEY_FALSE() as well,
but none of them has a config that enables it by default.
sched_numa_balancing is the only one with an explicit default policy:
NUMA_BALANCING_DEFAULT_ENABLED=y enables it on every
multi-node system.

That said, Gregory is right in the other thread that I overlooked
the single-node case: with this change, a single-node system pays
one predicted jump per tick at this site, where it previously paid
none.


--
Regards
Yafang