From: Peter Zijlstra <peterz@infradead.org>
Date: Mon, 10 Nov 2014 09:54:35 +0000 (+0100)
Subject: sched/numa: Avoid selecting oneself as swap target
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7af683350cb0ddd0e9d3819b4eb7abe9e2d3e709;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git

sched/numa: Avoid selecting oneself as swap target

Because the whole numa task selection stuff runs with preemption
enabled (its long and expensive) we can end up migrating and selecting
oneself as a swap target. This doesn't really work out well -- we end
up trying to acquire the same lock twice for the swap migrate -- so
avoid this.

Reported-and-Tested-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20141110100328.GF29390@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 34baa60f8a7b..3af3d1e7df9b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1179,6 +1179,13 @@ static void task_numa_compare(struct task_numa_env *env,
 		cur = NULL;
 	raw_spin_unlock_irq(&dst_rq->lock);
 
+	/*
+	 * Because we have preemption enabled we can get migrated around and
+	 * end try selecting ourselves (current == env->p) as a swap candidate.
+	 */
+	if (cur == env->p)
+		goto unlock;
+
 	/*
 	 * "imp" is the fault differential for the source task between the
 	 * source and destination node. Calculate the total differential for