[PATCH] sched/numa: fix stale dst_nid used in distance calculation for candidate nodes

lirongqing posted 1 patch 1 week, 4 days ago
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] sched/numa: fix stale dst_nid used in distance calculation for candidate nodes
Posted by lirongqing 1 week, 4 days ago
From: Li RongQing <lirongqing@baidu.com>

In task_numa_migrate(), when iterating over candidate NUMA nodes to
find a migration target beyond the preferred node, the distance is
computed as:

  dist = node_distance(env.src_nid, env.dst_nid);

However, env.dst_nid still holds the value from the previous iteration
(or the preferred node on the first pass), not the current candidate
node 'nid'. The corrected distance is only assigned to env.dst_nid,
after it has already been used for scoring.

Fix it by computing the distance against the current candidate node:

  dist = node_distance(env.src_nid, nid);

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d78467e..a58c15a 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3319,7 +3319,7 @@ static int task_numa_migrate(struct task_struct *p)
 			if (nid == env.src_nid || nid == p->numa_preferred_nid)
 				continue;
 
-			dist = node_distance(env.src_nid, env.dst_nid);
+			dist = node_distance(env.src_nid, nid);
 			if (sched_numa_topology_type == NUMA_BACKPLANE &&
 						dist != env.dist) {
 				taskweight = task_weight(p, env.src_nid, dist);
-- 
2.9.4