Skip to content

Commit 2a1ed24

Browse files
srikardingomolnar
authored andcommitted
sched/numa: Prefer NUMA hotness over cache hotness
The current load balancer may not try to prevent a task from moving out of a preferred node to a less preferred node. The reason for this being: - Since sched features NUMA and NUMA_RESIST_LOWER are disabled by default, migrate_degrades_locality() always returns false. - Even if NUMA_RESIST_LOWER were to be enabled, if its cache hot, migrate_degrades_locality() never gets called. The above behaviour can mean that tasks can move out of their preferred node but they may be eventually be brought back to their preferred node by numa balancer (due to higher numa faults). To avoid the above, this commit merges migrate_degrades_locality() and migrate_improves_locality(). It also replaces 3 sched features NUMA, NUMA_FAVOUR_HIGHER and NUMA_RESIST_LOWER by a single sched feature NUMA. Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Rik van Riel <riel@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Mike Galbraith <efault@gmx.de> Link: http://lkml.kernel.org/r/1434455762-30857-2-git-send-email-srikar@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 6dfec8d commit 2a1ed24

2 files changed

Lines changed: 30 additions & 77 deletions

File tree

‎kernel/sched/fair.c‎

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,72 +5670,39 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
56705670

56715671
#ifdef CONFIG_NUMA_BALANCING
56725672
/*
5673-
* Returns true if the destination node is the preferred node.
5674-
* Needs to match fbq_classify_rq(): if there is a runnable task
5675-
* that is not on its preferred node, we should identify it.
5673+
* Returns 1, if task migration degrades locality
5674+
* Returns 0, if task migration improves locality i.e migration preferred.
5675+
* Returns -1, if task migration is not affected by locality.
56765676
*/
5677-
static bool migrate_improves_locality(struct task_struct *p, struct lb_env *env)
5677+
static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
56785678
{
56795679
struct numa_group *numa_group = rcu_dereference(p->numa_group);
56805680
unsigned long src_faults, dst_faults;
56815681
int src_nid, dst_nid;
56825682

5683-
if (!sched_feat(NUMA) || !sched_feat(NUMA_FAVOUR_HIGHER) ||
5684-
!p->numa_faults || !(env->sd->flags & SD_NUMA)) {
5685-
return false;
5686-
}
5687-
5688-
src_nid = cpu_to_node(env->src_cpu);
5689-
dst_nid = cpu_to_node(env->dst_cpu);
5690-
5691-
if (src_nid == dst_nid)
5692-
return false;
5693-
5694-
/* Encourage migration to the preferred node. */
5695-
if (dst_nid == p->numa_preferred_nid)
5696-
return true;
5697-
5698-
/* Migrating away from the preferred node is bad. */
5699-
if (src_nid == p->numa_preferred_nid)
5700-
return false;
5701-
5702-
if (numa_group) {
5703-
src_faults = group_faults(p, src_nid);
5704-
dst_faults = group_faults(p, dst_nid);
5705-
} else {
5706-
src_faults = task_faults(p, src_nid);
5707-
dst_faults = task_faults(p, dst_nid);
5708-
}
5709-
5710-
return dst_faults > src_faults;
5711-
}
5712-
5713-
5714-
static bool migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
5715-
{
5716-
struct numa_group *numa_group = rcu_dereference(p->numa_group);
5717-
unsigned long src_faults, dst_faults;
5718-
int src_nid, dst_nid;
5719-
5720-
if (!sched_feat(NUMA) || !sched_feat(NUMA_RESIST_LOWER))
5721-
return false;
5722-
57235683
if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
5724-
return false;
5684+
return -1;
5685+
5686+
if (!sched_feat(NUMA))
5687+
return -1;
57255688

57265689
src_nid = cpu_to_node(env->src_cpu);
57275690
dst_nid = cpu_to_node(env->dst_cpu);
57285691

57295692
if (src_nid == dst_nid)
5730-
return false;
5693+
return -1;
57315694

5732-
/* Migrating away from the preferred node is bad. */
5733-
if (src_nid == p->numa_preferred_nid)
5734-
return true;
5695+
/* Migrating away from the preferred node is always bad. */
5696+
if (src_nid == p->numa_preferred_nid) {
5697+
if (env->src_rq->nr_running > env->src_rq->nr_preferred_running)
5698+
return 1;
5699+
else
5700+
return -1;
5701+
}
57355702

57365703
/* Encourage migration to the preferred node. */
57375704
if (dst_nid == p->numa_preferred_nid)
5738-
return false;
5705+
return 0;
57395706

57405707
if (numa_group) {
57415708
src_faults = group_faults(p, src_nid);
@@ -5749,16 +5716,10 @@ static bool migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
57495716
}
57505717

57515718
#else
5752-
static inline bool migrate_improves_locality(struct task_struct *p,
5719+
static inline int migrate_degrades_locality(struct task_struct *p,
57535720
struct lb_env *env)
57545721
{
5755-
return false;
5756-
}
5757-
5758-
static inline bool migrate_degrades_locality(struct task_struct *p,
5759-
struct lb_env *env)
5760-
{
5761-
return false;
5722+
return -1;
57625723
}
57635724
#endif
57645725

@@ -5768,7 +5729,7 @@ static inline bool migrate_degrades_locality(struct task_struct *p,
57685729
static
57695730
int can_migrate_task(struct task_struct *p, struct lb_env *env)
57705731
{
5771-
int tsk_cache_hot = 0;
5732+
int tsk_cache_hot;
57725733

57735734
lockdep_assert_held(&env->src_rq->lock);
57745735

@@ -5826,13 +5787,13 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
58265787
* 2) task is cache cold, or
58275788
* 3) too many balance attempts have failed.
58285789
*/
5829-
tsk_cache_hot = task_hot(p, env);
5830-
if (!tsk_cache_hot)
5831-
tsk_cache_hot = migrate_degrades_locality(p, env);
5790+
tsk_cache_hot = migrate_degrades_locality(p, env);
5791+
if (tsk_cache_hot == -1)
5792+
tsk_cache_hot = task_hot(p, env);
58325793

5833-
if (migrate_improves_locality(p, env) || !tsk_cache_hot ||
5794+
if (tsk_cache_hot <= 0 ||
58345795
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
5835-
if (tsk_cache_hot) {
5796+
if (tsk_cache_hot == 1) {
58365797
schedstat_inc(env->sd, lb_hot_gained[env->idle]);
58375798
schedstat_inc(p, se.statistics.nr_forced_migrations);
58385799
}

‎kernel/sched/features.h‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,12 @@ SCHED_FEAT(LB_MIN, false)
7979
* numa_balancing=
8080
*/
8181
#ifdef CONFIG_NUMA_BALANCING
82-
SCHED_FEAT(NUMA, false)
8382

8483
/*
85-
* NUMA_FAVOUR_HIGHER will favor moving tasks towards nodes where a
86-
* higher number of hinting faults are recorded during active load
87-
* balancing.
84+
* NUMA will favor moving tasks towards nodes where a higher number of
85+
* hinting faults are recorded during active load balancing. It will
86+
* resist moving tasks towards nodes where a lower number of hinting
87+
* faults have been recorded.
8888
*/
89-
SCHED_FEAT(NUMA_FAVOUR_HIGHER, true)
90-
91-
/*
92-
* NUMA_RESIST_LOWER will resist moving tasks towards nodes where a
93-
* lower number of hinting faults have been recorded. As this has
94-
* the potential to prevent a task ever migrating to a new node
95-
* due to CPU overload it is disabled by default.
96-
*/
97-
SCHED_FEAT(NUMA_RESIST_LOWER, false)
89+
SCHED_FEAT(NUMA, true)
9890
#endif

0 commit comments

Comments
 (0)