Skip to contentSkip to conversation

sched: small changes

PATCH Applied Yafang Shao 4 participants 9 messages Oct 23 – Oct 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover sched: small changes

These improments are found in the implementation of BPF-NUMAB series[0]. They can be applied seperately.

[0]. https://lwn.net/Articles/1101442/

Yafang Shao (2):
sched: fix stale get_pref_llc() stub for !CONFIG_SCHED_CACHE
sched: use static_branch_likely() for the NUMA balancing tick check

 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 sched: fix stale get_pref_llc() stub for !CONFIG_SCHED_CACHE

Commit b636fef85bda ("sched/cache: Introduce task_struct->sched_cache_grp to fix UAF") switched get_pref_llc() from taking a struct mm_struct * to taking the task's struct sched_cache_group *, but only updated the CONFIG_SCHED_CACHE definition and its caller: the stub in the !CONFIG_SCHED_CACHE branch kept the old mm_struct parameter.

Fixes b636fef85bda ("sched/cache: Introduce task_struct->sched_cache_grp to fix UAF")
Cc <[email protected]> #v7.2.x
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 57360f5cdde4..973647ad6c2d 100644
@@ -2194,7 +2194,7 @@ void init_sched_mm(struct task_struct *p) { }
 static void task_tick_cache(struct rq *rq, struct task_struct *p) { }
 
 static inline int get_pref_llc(struct task_struct *p,
-			       struct mm_struct *mm)
+			       struct sched_cache_group *grp)
 {
 	return -1;
 }
Signature · 1 line
2.52.0
merge bot Applied
#2 lore raw

[tip: sched/urgent] sched: fix stale get_pref_llc() stub for !CONFIG_SCHED_CACHE

The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     cac037a85c1971ec75c4d3edf5a28af9ec2a089c
Gitweb:        https://git.kernel.org/tip/cac037a85c1971ec75c4d3edf5a28af9ec2a089c
Author:        Yafang Shao <[email protected]>
AuthorDate:    Fri, 23 Oct 2026 10:31:04 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 23 Oct 2026 19:09:54 +02:00

sched: fix stale get_pref_llc() stub for !CONFIG_SCHED_CACHE

Commit b636fef85bda ("sched/cache: Introduce task_struct->sched_cache_grp to fix UAF") switched get_pref_llc() from taking a struct mm_struct * to taking the task's struct sched_cache_group *, but only updated the CONFIG_SCHED_CACHE definition and its caller: the stub in the !CONFIG_SCHED_CACHE branch kept the old mm_struct parameter.

Fixes b636fef85bda ("sched/cache: Introduce task_struct->sched_cache_grp to fix UAF")
Cc <[email protected]> #v7.2.x
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index d750f2f..6057bb5 100644
@@ -2194,7 +2194,7 @@ void init_sched_mm(struct task_struct *p) { }
 static void task_tick_cache(struct rq *rq, struct task_struct *p) { }
 
 static inline int get_pref_llc(struct task_struct *p,
-			       struct mm_struct *mm)
+			       struct sched_cache_group *grp)
 {
 	return -1;
 }
#3 lore raw

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

In reply to Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 973647ad6c2d..71dc47d6114d 100644
@@ -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))
 		task_tick_numa(rq, curr);
 
 	task_tick_cache(rq, curr);
Signature · 1 line
2.52.0
maintainer
#4 lore raw

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

Quoted 18 lines · Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 973647ad6c2d..71dc47d6114d 100644

kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) · line 15354

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -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 ...
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

Quoted 6 lines
kernel/sched/fair.c +0 -1
                task_tick_numa(rq, curr);
 
        task_tick_cache(rq, curr);
--

2.52.0

#5 lore raw

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

Quoted 22 lines · Vincent Guittot
Quoted 21 lines · Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 973647ad6c2d..71dc47d6114d 100644
@@ -15351,7 +15351,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
        if (queued)
                return;
 
Quoted 6 lines

kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) · line 15354

Quoted 2 lines
kernel/sched/fair.c +1 -1
-       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.

Quoted 3 lines

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.

This just looks like cleanup to me.

Signature · 1 line
~Gregory
maintainer
#6 lore raw

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

Quoted 31 lines · Gregory Price (Meta)
Quoted 22 lines · Vincent Guittot
Quoted 21 lines · Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 973647ad6c2d..71dc47d6114d 100644
@@ -15351,7 +15351,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
        if (queued)
                return;
 
Quoted 6 lines

kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) · line 15354

Quoted 2 lines
kernel/sched/fair.c +1 -1
-       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 ...

Quoted 2 lines

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()

Quoted 6 lines
Quoted 4 lines

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

Quoted 6 lines

This just looks like cleanup to me.

--
~Gregory

#7 lore raw

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

Quoted 32 lines · Vincent Guittot
Quoted 31 lines · Gregory Price (Meta)
Quoted 28 lines · Vincent Guittot
Quoted 18 lines · Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 973647ad6c2d..71dc47d6114d 100644

kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) · line 15354

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -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 ...

Quoted 6 lines
Quoted 2 lines

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

Signature · 1 line
~Gregory
#8 lore raw

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

In reply to Vincent Guittot
Quoted 33 lines · Vincent Guittot
Quoted 31 lines · Gregory Price (Meta)
Quoted 28 lines · Vincent Guittot
Quoted 18 lines · Yafang Shao

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.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 973647ad6c2d..71dc47d6114d 100644

kernel/sched/fair.c static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) · line 15354

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -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 ...

Quoted 5 lines
Quoted 2 lines

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.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

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