When a task exits, it notifies the parent that it has exited. This is a sync
wakup and the exiting task may pull the parent towards the wakers CPU. For
even simple workloads like using a shell, it was observed that the shell
is pulled across nodes by exiting processes. This is daft as the parent
may be long-lived and properly placed. This patch special cases a sync
wakeup on exit to avoid pulling tasks across nodes. Testing on a range
of workloads and machines showed very little differences in performance
although there was a small 3% boost on some machines running a shellscript
intensive workload (git regression test suite).

Signed-off-by: Mel Gorman <mgor...@techsingularity.net>
 kernel/sched/fair.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 28c8d9c91955..50442697b455 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5710,8 +5710,14 @@ wake_affine_idle(int this_cpu, int prev_cpu, int sync)
        if (idle_cpu(this_cpu) && cpus_share_cache(this_cpu, prev_cpu))
                return idle_cpu(prev_cpu) ? prev_cpu : this_cpu;
-       if (sync && cpu_rq(this_cpu)->nr_running == 1)
+       if (sync && cpu_rq(this_cpu)->nr_running == 1) {
+               /* Avoid tasks exiting pulling parents to new nodes */
+               if ((current->flags & PF_EXITING) &&
+                   !cpus_share_cache(this_cpu, prev_cpu))
+                       return prev_cpu;
                return this_cpu;
+       }
        return nr_cpumask_bits;

Reply via email to