Re: [RFC PATCH v2 1/3] sched: add helpers for numa balancing

From: Yafang Shao

Date: Tue Oct 13 2026 - 05:21:13 EST


On Tue, Oct 13, 2026 at 3:38 PM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:
>
> On 10/12/26 14:04, Yafang Shao wrote:
> > Two new helpers task_numab_enabled() and numab_mode_tiering() are
> > introduced to replace the scattered direct accesses to the
> > sched_numa_balancing static key and the sysctl_numa_balancing_mode
> > bitmask.
> >
>
> I'll only comment on the new exposed helpers. Some of these might make sense
> even without the bigger series.
>
> (obviously, minus the task change)
>
> > No functional change.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> > include/linux/sched/numa_balancing.h | 31 ++++++++++++++++++++++++++++
> > kernel/sched/fair.c | 16 +++++++-------
> > kernel/sched/sched.h | 1 -
> > mm/memory-tiers.c | 3 ++-
> > mm/migrate.c | 7 ++++---
> > mm/vmscan.c | 6 +++---
> > 6 files changed, 48 insertions(+), 16 deletions(-)
> >
> > diff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h
> > index 52b22c5c396d..353772b49c5f 100644
> > --- a/include/linux/sched/numa_balancing.h
> > +++ b/include/linux/sched/numa_balancing.h
> > @@ -8,6 +8,7 @@
> > */
> >
> > #include <linux/sched.h>
> > +#include <linux/sched/sysctl.h>
> >
> > #define TNF_MIGRATED 0x01
> > #define TNF_NO_GROUP 0x02
> > @@ -32,6 +33,28 @@ extern void set_numabalancing_state(bool enabled);
> > extern void task_numa_free(struct task_struct *p, bool final);
> > bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
> > int src_nid, int dst_cpu);
> > +
> > +extern struct static_key_false sched_numa_balancing;
> > +
> > +/*
> > + * Whether NUMA balancing applies to @p. The @p argument is unused for
> > + * now: a later patch will consult a per-cgroup BPF policy with it.
>
> Talking about later patches in a function doc is ... wrong.

Thanks for your guidance.
I will update it.

>
> > + */
> > +static inline bool task_numab_enabled(struct task_struct *p)
> > +{
> > + return static_branch_unlikely(&sched_numa_balancing);
> > +}
> > +
> > +/*
> > + * The global sysctl state, for the system-wide tiering machinery: this
> > + * reflects kernel.numa_balancing_mode only and takes no task.
>
> The latter part doesn't make a lot of sense in this documentation.

I will update it.

>
> > + */
> > +static inline bool numab_mode_tiering(void)
>
> The function name isn't really intuitive. Should this be
>
> numab_in_tiering_mode
>
>
> numab_tiering_enabled
>
> or something like this.

Agreed, thanks. I will rename it to numab_in_tiering_mode().

>
> > +{
> > + if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
> > + return true;
> > + return false;
>
>
> return sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING;
>
> ?

Agreed, will simplify as suggested.

>
> Both functions could directly have proper kerneldoc if we are already
> documenting these.

Sure. I will update it.

--
Regards
Yafang