[RFC PATCH v5 7/9] sched/fair: Provide can_migrate_task_llc

From: Chen Jinghuang

Date: Fri Mar 20 2026 - 02:20:42 EST


From: Steve Sistare <steven.sistare@xxxxxxxxxx>

Define a simpler version of can_migrate_task called can_migrate_task_llc
which does not require a struct lb_env argument, and judges whether a
migration from one CPU to another within the same LLC should be allowed.

Signed-off-by: Steve Sistare <steven.sistare@xxxxxxxxxx>
Signed-off-by: Chen Jinghuang <chenjinghuang2@xxxxxxxxxx>
---
changes from v4 to v5:
Skip tasks with the sched_delayed flag during overload detection.
---
kernel/sched/fair.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ebb13108dabe..0bf6d18dac05 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9582,6 +9582,34 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
return 0;
}

+/*
+ * Return true if task @p can migrate from @rq to @dst_rq in the same LLC.
+ * No need to test for co-locality, and no need to test task_hot(), as sharing
+ * LLC provides cache warmth at that level.
+ */
+static bool
+can_migrate_task_llc(struct task_struct *p, struct rq *rq, struct rq *dst_rq)
+{
+ int dst_cpu = dst_rq->cpu;
+
+ lockdep_assert_rq_held(rq);
+
+ if (!cpumask_test_cpu(dst_cpu, p->cpus_ptr)) {
+ schedstat_inc(p->stats.nr_failed_migrations_affine);
+ return false;
+ }
+
+ if (task_on_cpu(rq, p)) {
+ schedstat_inc(p->stats.nr_failed_migrations_running);
+ return false;
+ }
+
+ if (p->se.sched_delayed)
+ return false;
+
+ return true;
+}
+
/*
* detach_task() -- detach the task for the migration specified in env
*/
--
2.34.1