Skip to content

Commit 0c8bb49

Browse files
committed
sched/fair: Cleanup in migrate_degrades_locality() to improve readability
JIRA: https://issues.redhat.com/browse/RHEL-23495 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 10dafae commit 0c8bb49

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

88388838
#ifdef CONFIG_NUMA_BALANCING
88398839
/*
8840-
* Returns 1, if task migration degrades locality
8841-
* Returns 0, if task migration improves locality i.e migration preferred.
8842-
* Returns -1, if task migration is not affected by locality.
8840+
* Returns a positive value, if task migration degrades locality.
8841+
* Returns 0, if task migration is not affected by locality.
8842+
* Returns a negative value, if task migration improves locality i.e migration preferred.
88438843
*/
8844-
static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
8844+
static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
88458845
{
88468846
struct numa_group *numa_group = rcu_dereference(p->numa_group);
88478847
unsigned long src_weight, dst_weight;
88488848
int src_nid, dst_nid, dist;
88498849

88508850
if (!static_branch_likely(&sched_numa_balancing))
8851-
return -1;
8851+
return 0;
88528852

88538853
if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
8854-
return -1;
8854+
return 0;
88558855

88568856
src_nid = cpu_to_node(env->src_cpu);
88578857
dst_nid = cpu_to_node(env->dst_cpu);
88588858

88598859
if (src_nid == dst_nid)
8860-
return -1;
8860+
return 0;
88618861

88628862
/* Migrating away from the preferred node is always bad. */
88638863
if (src_nid == p->numa_preferred_nid) {
88648864
if (env->src_rq->nr_running > env->src_rq->nr_preferred_running)
88658865
return 1;
88668866
else
8867-
return -1;
8867+
return 0;
88688868
}
88698869

88708870
/* Encourage migration to the preferred node. */
88718871
if (dst_nid == p->numa_preferred_nid)
8872-
return 0;
8872+
return -1;
88738873

88748874
/* Leaving a core idle is often worse than degrading locality. */
88758875
if (env->idle == CPU_IDLE)
8876-
return -1;
8876+
return 0;
88778877

88788878
dist = node_distance(src_nid, dst_nid);
88798879
if (numa_group) {
@@ -8884,14 +8884,14 @@ static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
88848884
dst_weight = task_weight(p, dst_nid, dist);
88858885
}
88868886

8887-
return dst_weight < src_weight;
8887+
return src_weight - dst_weight;
88888888
}
88898889

88908890
#else
8891-
static inline int migrate_degrades_locality(struct task_struct *p,
8891+
static inline long migrate_degrades_locality(struct task_struct *p,
88928892
struct lb_env *env)
88938893
{
8894-
return -1;
8894+
return 0;
88958895
}
88968896
#endif
88978897

@@ -8901,7 +8901,7 @@ static inline int migrate_degrades_locality(struct task_struct *p,
89018901
static
89028902
int can_migrate_task(struct task_struct *p, struct lb_env *env)
89038903
{
8904-
int tsk_cache_hot;
8904+
long degrades, hot;
89058905

89068906
lockdep_assert_rq_held(env->src_rq);
89078907
if (p->sched_task_hot)
@@ -8972,13 +8972,14 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
89728972
if (env->flags & LBF_ACTIVE_LB)
89738973
return 1;
89748974

8975-
tsk_cache_hot = migrate_degrades_locality(p, env);
8976-
if (tsk_cache_hot == -1)
8977-
tsk_cache_hot = task_hot(p, env);
8975+
degrades = migrate_degrades_locality(p, env);
8976+
if (!degrades)
8977+
hot = task_hot(p, env);
8978+
else
8979+
hot = degrades > 0;
89788980

8979-
if (tsk_cache_hot <= 0 ||
8980-
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
8981-
if (tsk_cache_hot == 1)
8981+
if (!hot || env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
8982+
if (hot)
89828983
p->sched_task_hot = 1;
89838984
return 1;
89848985
}

0 commit comments

Comments
 (0)