Skip to content

Commit c3856c9

Browse files
author
Peter Zijlstra
committed
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) <[email protected]> Not-yet-signed-off-by: Peter Zijlstra <[email protected]> Signed-off-by: Swapnil Sapkal <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a430d99 commit c3856c9

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
@@ -9329,43 +9329,43 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
93299329

93309330
#ifdef CONFIG_NUMA_BALANCING
93319331
/*
9332-
* Returns 1, if task migration degrades locality
9333-
* Returns 0, if task migration improves locality i.e migration preferred.
9334-
* Returns -1, if task migration is not affected by locality.
9332+
* Returns a positive value, if task migration degrades locality.
9333+
* Returns 0, if task migration is not affected by locality.
9334+
* Returns a negative value, if task migration improves locality i.e migration preferred.
93359335
*/
9336-
static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
9336+
static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
93379337
{
93389338
struct numa_group *numa_group = rcu_dereference(p->numa_group);
93399339
unsigned long src_weight, dst_weight;
93409340
int src_nid, dst_nid, dist;
93419341

93429342
if (!static_branch_likely(&sched_numa_balancing))
9343-
return -1;
9343+
return 0;
93449344

93459345
if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
9346-
return -1;
9346+
return 0;
93479347

93489348
src_nid = cpu_to_node(env->src_cpu);
93499349
dst_nid = cpu_to_node(env->dst_cpu);
93509350

93519351
if (src_nid == dst_nid)
9352-
return -1;
9352+
return 0;
93539353

93549354
/* Migrating away from the preferred node is always bad. */
93559355
if (src_nid == p->numa_preferred_nid) {
93569356
if (env->src_rq->nr_running > env->src_rq->nr_preferred_running)
93579357
return 1;
93589358
else
9359-
return -1;
9359+
return 0;
93609360
}
93619361

93629362
/* Encourage migration to the preferred node. */
93639363
if (dst_nid == p->numa_preferred_nid)
9364-
return 0;
9364+
return -1;
93659365

93669366
/* Leaving a core idle is often worse than degrading locality. */
93679367
if (env->idle == CPU_IDLE)
9368-
return -1;
9368+
return 0;
93699369

93709370
dist = node_distance(src_nid, dst_nid);
93719371
if (numa_group) {
@@ -9376,14 +9376,14 @@ static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
93769376
dst_weight = task_weight(p, dst_nid, dist);
93779377
}
93789378

9379-
return dst_weight < src_weight;
9379+
return src_weight - dst_weight;
93809380
}
93819381

93829382
#else
9383-
static inline int migrate_degrades_locality(struct task_struct *p,
9383+
static inline long migrate_degrades_locality(struct task_struct *p,
93849384
struct lb_env *env)
93859385
{
9386-
return -1;
9386+
return 0;
93879387
}
93889388
#endif
93899389

@@ -9393,7 +9393,7 @@ static inline int migrate_degrades_locality(struct task_struct *p,
93939393
static
93949394
int can_migrate_task(struct task_struct *p, struct lb_env *env)
93959395
{
9396-
int tsk_cache_hot;
9396+
long degrades, hot;
93979397

93989398
lockdep_assert_rq_held(env->src_rq);
93999399
if (p->sched_task_hot)
@@ -9468,13 +9468,14 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
94689468
if (env->flags & LBF_ACTIVE_LB)
94699469
return 1;
94709470

9471-
tsk_cache_hot = migrate_degrades_locality(p, env);
9472-
if (tsk_cache_hot == -1)
9473-
tsk_cache_hot = task_hot(p, env);
9471+
degrades = migrate_degrades_locality(p, env);
9472+
if (!degrades)
9473+
hot = task_hot(p, env);
9474+
else
9475+
hot = degrades > 0;
94749476

9475-
if (tsk_cache_hot <= 0 ||
9476-
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
9477-
if (tsk_cache_hot == 1)
9477+
if (!hot || env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
9478+
if (hot)
94789479
p->sched_task_hot = 1;
94799480
return 1;
94809481
}

0 commit comments

Comments
 (0)