From: Tim Chen <tim.c.chen@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>
Cc: Chen Yu <yu.c.chen@intel.com>, Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Kees Cook <kees@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Qais Yousef <qyousef@layalina.io>,
Aaron Lu <ziqianlu@bytedance.com>,
Srikar Dronamraju <srikar@linux.ibm.com>,
Vineeth Remanan Pillai <vineethr@linux.ibm.com>,
Ricardo Neri-Calderon <ricardo.neri-calderon@linux.intel.com>,
Lu Wang <wanglu.priv@gmail.com>, Hyunwoo Kim <imv4bel@gmail.com>,
Zhan Xusheng <zhanxusheng@xiaomi.com>,
Zhan Xusheng <zhanxusheng1024@gmail.com>,
Yi Lai <yi1.lai@intel.com>, Tim Chen <tim.c.chen@linux.intel.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Danilo Krummrich <dakr@kernel.org>,
Zenghui Yu <zenghui.yu@linux.dev>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, stable@kernel.org
Subject: [PATCH v2 5/6] sched/cache: Skip kernel thread for cache aware scheduling
Date: Mon, 21 Sep 2026 17:37:26 -0700 [thread overview]
Message-ID: <058f0c6ea7b991c177a17de347fa3157f25489a7.1790035273.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1790035273.git.tim.c.chen@linux.intel.com>
From: Chen Yu <yu.c.chen@intel.com>
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")
Cc: stable@kernel.org #7.2.x
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
kernel/sched/fair.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3e2d236be2a3..341d2f9ed72b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1805,8 +1805,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. Add the PF_KTHREAD check explicitly
+ * here for safety reasons, to guard against future
+ * modifications and to pair with task_tick_cache().
+ */
+ if (!grp || p->flags & PF_KTHREAD || !grp->pcpu_sched)
return;
pcpu_sched = per_cpu_ptr(grp->pcpu_sched, cpu_of(rq));
--
2.32.0
next prev parent reply other threads:[~2026-09-22 0:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 0:37 [PATCH v2 0/6] sched/cache: Fixes " Tim Chen
2026-09-22 0:37 ` [PATCH v2 1/6] sched/cache: Keep nr_pref_llc_running in the runnable domain Tim Chen
2026-09-22 7:22 ` Peter Zijlstra
2026-09-22 8:25 ` Chen, Yu C
2026-09-22 8:28 ` Peter Zijlstra
2026-09-22 0:37 ` [PATCH v2 2/6] sched/cache: Honor migrate_llc_task semantics in active load balance Tim Chen
2026-09-22 7:23 ` Peter Zijlstra
2026-09-22 8:30 ` Chen, Yu C
2026-09-22 0:37 ` [PATCH v2 3/6] sched/cache: Decouple sched_cache_group from mm Tim Chen
2026-09-22 0:37 ` [PATCH v2 4/6] sched/cache: Introduce task_struct->sched_cache_grp Tim Chen
2026-09-22 0:37 ` Tim Chen [this message]
2026-09-22 0:37 ` [PATCH v2 6/6] sched/cache: Refresh LLC capacity across CPU hotplug Tim Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=058f0c6ea7b991c177a17de347fa3157f25489a7.1790035273.git.tim.c.chen@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=dakr@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=imv4bel@gmail.com \
--cc=jack@suse.cz \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--cc=rafael.j.wysocki@intel.com \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
--cc=stable@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vineethr@linux.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
--cc=wanglu.priv@gmail.com \
--cc=yi1.lai@intel.com \
--cc=yu.c.chen@intel.com \
--cc=zenghui.yu@linux.dev \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.com \
--cc=ziqianlu@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®