From: Chen Yu <yu.c.chen@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
"Gautham R . Shenoy" <gautham.shenoy@amd.com>
Cc: Juri Lelli <juri.lelli@redhat.com>,
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>,
Tim Chen <tim.c.chen@intel.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Libo Chen <libo.chen@oracle.com>,
Abel Wu <wuyun.abel@bytedance.com>,
Madadi Vineeth Reddy <vineethr@linux.ibm.com>,
Hillf Danton <hdanton@sina.com>,
linux-kernel@vger.kernel.org, Chen Yu <yu.c.chen@intel.com>
Subject: [RFC PATCH 3/5] sched: Avoid task migration within its preferred LLC
Date: Mon, 21 Apr 2025 11:25:04 +0800 [thread overview]
Message-ID: <01a54d63193fab5c819aab75321f6aa492491997.1745199017.git.yu.c.chen@intel.com> (raw)
In-Reply-To: <cover.1745199017.git.yu.c.chen@intel.com>
It was found that when running schbench, there is a
significant amount of in-LLC task migration, even if
the wakee is woken up on its preferred LLC. This
leads to core-to-core latency and impairs performance.
Inhibit task migration if the wakee is already in its
preferred LLC. Meanwhile, prevent the load balancer
from treating the task as cache-hot if this task is
being migrated out of its preferred LLC, rather than
comparing the occupancy between CPUs.
With this enhancement applied, the in-LLC task migration
has been reduced a lot(use PATCH 5/5 to verify).
It was found that when schbench is running, there is a
significant amount of in-LLC task migration, even if the
wakee is woken up on its preferred LLC. This leads to
core-to-core latency and impairs performance.
Inhibit task migration if the wakee is already in its
preferred LLC. Meanwhile, prevent the load balancer from
treating the task as cache-hot if this task is being migrated
out of its preferred LLC, instead of comparing occupancy
between CPUs directly.
With this enhancement applied, the in-LLC task migration has
been reduced significantly, (use PATCH 5/5 to verify).
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
kernel/sched/fair.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 22b5830e7e4e..1733eb83042c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8806,6 +8806,12 @@ static int select_cache_cpu(struct task_struct *p, int prev_cpu)
if (cpu < 0)
return prev_cpu;
+ /*
+ * No need to migrate the task if previous and preferred CPU
+ * are in the same LLC.
+ */
+ if (cpus_share_cache(prev_cpu, cpu))
+ return prev_cpu;
if (static_branch_likely(&sched_numa_balancing) &&
__migrate_degrades_locality(p, prev_cpu, cpu, false) > 0) {
@@ -9553,14 +9559,13 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
return 0;
#ifdef CONFIG_SCHED_CACHE
- if (sched_feat(SCHED_CACHE) && p->mm && p->mm->pcpu_sched) {
- /*
- * XXX things like Skylake have non-inclusive L3 and might not
- * like this L3 centric view. What to do about L2 stickyness ?
- */
- return per_cpu_ptr(p->mm->pcpu_sched, env->src_cpu)->occ >
- per_cpu_ptr(p->mm->pcpu_sched, env->dst_cpu)->occ;
- }
+ /*
+ * Don't migrate task out of its preferred LLC.
+ */
+ if (sched_feat(SCHED_CACHE) && p->mm && p->mm->mm_sched_cpu >= 0 &&
+ cpus_share_cache(env->src_cpu, p->mm->mm_sched_cpu) &&
+ !cpus_share_cache(env->src_cpu, env->dst_cpu))
+ return 1;
#endif
delta = rq_clock_task(env->src_rq) - p->se.exec_start;
--
2.25.1
next prev parent reply other threads:[~2025-04-21 3:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 3:23 [RFC PATCH 0/5] sched: Introduce Cache aware scheduling Chen Yu
2025-04-21 3:24 ` [RFC PATCH 1/5] sched: Cache aware load-balancing Chen Yu
2025-04-21 3:24 ` [RFC PATCH 2/5] sched: Several fixes for cache aware scheduling Chen Yu
2025-04-21 3:25 ` Chen Yu [this message]
2025-04-21 3:25 ` [RFC PATCH 4/5] sched: Inhibit cache aware scheduling if the preferred LLC is over aggregated Chen Yu
2025-04-24 9:22 ` Madadi Vineeth Reddy
2025-04-24 14:11 ` Chen, Yu C
2025-04-24 15:51 ` Tim Chen
2025-04-25 9:13 ` Madadi Vineeth Reddy
2025-04-25 17:29 ` Tim Chen
2025-04-25 8:58 ` Madadi Vineeth Reddy
2025-04-21 3:25 ` [RFC PATCH 5/5] sched: Add ftrace to track task migration and load balance within and across LLC Chen Yu
2025-04-29 3:47 ` [RFC PATCH 0/5] sched: Introduce Cache aware scheduling K Prateek Nayak
2025-04-29 12:57 ` Chen, Yu C
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=01a54d63193fab5c819aab75321f6aa492491997.1745199017.git.yu.c.chen@intel.com \
--to=yu.c.chen@intel.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.com \
--cc=hdanton@sina.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=libo.chen@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vineethr@linux.ibm.com \
--cc=vschneid@redhat.com \
--cc=wuyun.abel@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®