Skip to content

Commit 7d25c44

Browse files
committed
sched/fair: Cleanup in migrate_degrades_locality() to improve readability
JIRA: https://issues.redhat.com/browse/RHEL-24185 commit c3856c9 Author: Peter Zijlstra <peterz@infradead.org> Date: Fri Dec 20 06:32:20 2024 +0000 sched/fair: Cleanup in migrate_degrades_locality() to improve readability migrate_degrade_locality() would return {1, 0, -1} respectively to indicate that migration would degrade-locality, would improve locality, would be ambivalent to locality improvements. This patch improves readability by changing the return value to mean: * Any positive value degrades locality * 0 migration doesn't affect locality * Any negative value improves locality [Swapnil: Fixed comments around code and wrote commit log] Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Not-yet-signed-off-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20241220063224.17767-3-swapnil.sapkal@amd.com Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 3905cb6 commit 7d25c44

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

kernel/sched/fair.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9347,43 +9347,43 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
93479347

93489348
#ifdef CONFIG_NUMA_BALANCING
93499349
/*
9350-
* Returns 1, if task migration degrades locality
9351-
* Returns 0, if task migration improves locality i.e migration preferred.
9352-
* Returns -1, if task migration is not affected by locality.
9350+
* Returns a positive value, if task migration degrades locality.
9351+
* Returns 0, if task migration is not affected by locality.
9352+
* Returns a negative value, if task migration improves locality i.e migration preferred.
93539353
*/
9354-
static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
9354+
static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
93559355
{
93569356
struct numa_group *numa_group = rcu_dereference(p->numa_group);
93579357
unsigned long src_weight, dst_weight;
93589358
int src_nid, dst_nid, dist;
93599359

93609360
if (!static_branch_likely(&sched_numa_balancing))
9361-
return -1;
9361+
return 0;
93629362

93639363
if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
9364-
return -1;
9364+
return 0;
93659365

93669366
src_nid = cpu_to_node(env->src_cpu);
93679367
dst_nid = cpu_to_node(env->dst_cpu);
93689368

93699369
if (src_nid == dst_nid)
9370-
return -1;
9370+
return 0;
93719371

93729372
/* Migrating away from the preferred node is always bad. */
93739373
if (src_nid == p->numa_preferred_nid) {
93749374
if (env->src_rq->nr_running > env->src_rq->nr_preferred_running)
93759375
return 1;
93769376
else
9377-
return -1;
9377+
return 0;
93789378
}
93799379

93809380
/* Encourage migration to the preferred node. */
93819381
if (dst_nid == p->numa_preferred_nid)
9382-
return 0;
9382+
return -1;
93839383

93849384
/* Leaving a core idle is often worse than degrading locality. */
93859385
if (env->idle == CPU_IDLE)
9386-
return -1;
9386+
return 0;
93879387

93889388
dist = node_distance(src_nid, dst_nid);
93899389
if (numa_group) {
@@ -9394,14 +9394,14 @@ static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
93949394
dst_weight = task_weight(p, dst_nid, dist);
93959395
}
93969396

9397-
return dst_weight < src_weight;
9397+
return src_weight - dst_weight;
93989398
}
93999399

94009400
#else
9401-
static inline int migrate_degrades_locality(struct task_struct *p,
9401+
static inline long migrate_degrades_locality(struct task_struct *p,
94029402
struct lb_env *env)
94039403
{
9404-
return -1;
9404+
return 0;
94059405
}
94069406
#endif
94079407

@@ -9411,7 +9411,7 @@ static inline int migrate_degrades_locality(struct task_struct *p,
94119411
static
94129412
int can_migrate_task(struct task_struct *p, struct lb_env *env)
94139413
{
9414-
int tsk_cache_hot;
9414+
long degrades, hot;
94159415

94169416
lockdep_assert_rq_held(env->src_rq);
94179417
if (p->sched_task_hot)
@@ -9482,13 +9482,14 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
94829482
if (env->flags & LBF_ACTIVE_LB)
94839483
return 1;
94849484

9485-
tsk_cache_hot = migrate_degrades_locality(p, env);
9486-
if (tsk_cache_hot == -1)
9487-
tsk_cache_hot = task_hot(p, env);
9485+
degrades = migrate_degrades_locality(p, env);
9486+
if (!degrades)
9487+
hot = task_hot(p, env);
9488+
else
9489+
hot = degrades > 0;
94889490

9489-
if (tsk_cache_hot <= 0 ||
9490-
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
9491-
if (tsk_cache_hot == 1)
9491+
if (!hot || env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
9492+
if (hot)
94929493
p->sched_task_hot = 1;
94939494
return 1;
94949495
}

0 commit comments

Comments
 (0)