summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorChen Yu <yu.c.chen@intel.com>2026-09-21 17:37:26 -0700
committerIngo Molnar <mingo@kernel.org>2026-09-22 10:50:49 +0200
commit65efcccddc83d6a19e8a2e2a6117811e39e589bf (patch)
tree867e324274da27e5b86c55f87eb16a2cdba6dd15 /kernel
parentb636fef85bda7d1bab9c0a45067ab1508d79d946 (diff)
downloadlinux-next-65efcccddc83d6a19e8a2e2a6117811e39e589bf.tar.gz
linux-next-65efcccddc83d6a19e8a2e2a6117811e39e589bf.zip
sched/cache: Skip kernel threads for cache aware scheduling to rubustify the code
Kernel thread should not be covered by cache aware scheduling as it borrows the statistics from the user space thread. Filter the kernel thread in account_mm_sched(). In theory a kernel thread does not have any valid cache group, so !grp should gate the kernel thread. Add the PF_KTHREAD check explicitly here for safety reasons, to guard against future modifications and to pair with task_tick_cache(). Fixes: df0d98475954 ("sched/cache: Introduce infrastructure for cache-aware load balancing") Signed-off-by: Chen Yu <yu.c.chen@intel.com> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: <stable@kernel.org> # 7.2.x Link: https://patch.msgid.link/058f0c6ea7b991c177a17de347fa3157f25489a7.1790035273.git.tim.c.chen@linux.intel.com
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/fair.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 974a7dfe3215..57360f5cdde4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1907,8 +1907,14 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
/*
* init_task, kthreads and user thread created
* by user_mode_thread() don't have a cache group.
- */
- if (!grp || !grp->pcpu_sched)
+ * In theory a kernel thread does not have any valid
+ * cache group, because sched_cache_fork() is not
+ * invoked for a kernel thread - !grp should gate the
+ * kernel thread. Use the PF_KTHREAD check explicitly
+ * here for safety reasons, to guard against future
+ * modifications and to pair with task_tick_cache().
+ */
+ if (p->flags & PF_KTHREAD || !grp || !grp->pcpu_sched)
return;
pcpu_sched = per_cpu_ptr(grp->pcpu_sched, cpu_of(rq));