All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/numa: fix choosing isolated CPUs when task_numa_migrate()
@ 2018-10-22  3:05 Yi Wang
  2018-10-23 17:36 ` Srikar Dronamraju
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Wang @ 2018-10-22  3:05 UTC (permalink / raw)
  To: mingo; +Cc: peterz, linux-kernel, wang.yi59, zhong.weidong, liu.yi24

When trying to migrate to a CPU in task_numa_migrate(), we invoke
task_numa_find_cpu() to choose a spot, in which function we skip
the CPU which is not in cpus_allowed, but forgot to concern the
isolated CPUs, and this may cause the task would run on the isolcpus.

This patch fixes this issue by checking the load_balance_mask.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Reviewed-by: Yi Liu <liu.yi24@zte.com.cn>
---
 kernel/sched/fair.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 908c9cd..0fa0cee 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1709,6 +1709,7 @@ static void task_numa_compare(struct task_numa_env *env,
 	rcu_read_unlock();
 }
 
+static int is_cpu_load_balance(int cpu);
 static void task_numa_find_cpu(struct task_numa_env *env,
 				long taskimp, long groupimp)
 {
@@ -1731,6 +1732,9 @@ static void task_numa_find_cpu(struct task_numa_env *env,
 		if (!cpumask_test_cpu(cpu, &env->p->cpus_allowed))
 			continue;
 
+		if (!is_cpu_load_balance(cpu))
+			continue;
+
 		env->dst_cpu = cpu;
 		task_numa_compare(env, taskimp, groupimp, maymove);
 	}
@@ -8528,6 +8532,12 @@ static int should_we_balance(struct lb_env *env)
 	return balance_cpu == env->dst_cpu;
 }
 
+static int is_cpu_load_balance(int cpu)
+{
+	struct cpumask *cpus = this_cpu_cpumask_var_ptr(load_balance_mask);
+
+	return cpumask_test_cpu(cpu, cpus);
+}
+
 /*
  * Check this_cpu to ensure it is balanced within domain. Attempt to move
  * tasks if there is an imbalance.
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched/numa: fix choosing isolated CPUs when task_numa_migrate()
  2018-10-22  3:05 [PATCH] sched/numa: fix choosing isolated CPUs when task_numa_migrate() Yi Wang
@ 2018-10-23 17:36 ` Srikar Dronamraju
  0 siblings, 0 replies; 2+ messages in thread
From: Srikar Dronamraju @ 2018-10-23 17:36 UTC (permalink / raw)
  To: Yi Wang; +Cc: mingo, peterz, linux-kernel, zhong.weidong, liu.yi24


Hi Yi Wang,

> When trying to migrate to a CPU in task_numa_migrate(), we invoke
> task_numa_find_cpu() to choose a spot, in which function we skip
> the CPU which is not in cpus_allowed, but forgot to concern the
> isolated CPUs, and this may cause the task would run on the isolcpus.
>
> This patch fixes this issue by checking the load_balance_mask.
>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> Reviewed-by: Yi Liu <liu.yi24@zte.com.cn>
> ---
>  kernel/sched/fair.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>

I had proposed something similar
http://lkml.kernel.org/r/1491326848-5748-1-git-send-email-srikar@linux.vnet.ibm.com

but at that time, Peter felt we should fix it at different level.
http://lkml.kernel.org/r/20170406073659.y6ubqriyshax4v4m@hirez.programming.kicks-ass.net

and I think he is right.

I have system with 32 cpus, have passed isolcpus as a kernel parameter.

$ grep -o "isolcpus=[,,1-9]*" /proc/cmdline
isolcpus=1,5,9,13
$ grep -i cpus_allowed /proc/$$/status
Cpus_allowed:   ffffdddd
Cpus_allowed_list:      0,2-4,6-8,10-12,14-31


So for a task running on top_cpuset will not have isolcpus as part of the
cpus_allowed.

However if a said task were to call sched_setaffinity, then there is every
likely hood of the cpus being passed being a mix of isolcpus and
nonisolcpus.

For example 
perf bench numa mem --no-data_rand_walk -p 4 -t 8 -G 0 -P 3072 -T 0 -l 50 -c -s 1000

$ for i in $(pgrep -f perf); do  grep -i cpus_allowed_list  /proc/$i/task/*/status ; done | head -n 10
Cpus_allowed_list:      0,2-4,6-8,10-12,14-31
/proc/2107/task/2107/status:Cpus_allowed_list:  0-31
/proc/2107/task/2196/status:Cpus_allowed_list:  0-31
/proc/2107/task/2197/status:Cpus_allowed_list:  0-31
/proc/2107/task/2198/status:Cpus_allowed_list:  0-31
/proc/2107/task/2199/status:Cpus_allowed_list:  0-31
/proc/2107/task/2200/status:Cpus_allowed_list:  0-31
/proc/2107/task/2201/status:Cpus_allowed_list:  0-31
/proc/2107/task/2202/status:Cpus_allowed_list:  0-31
/proc/2107/task/2203/status:Cpus_allowed_list:  0-31

So the cpus_allowed has a mix of isolcpus and nonisolcpus.

While this patch fixes the problem, there is a risk of missing other places
like update_numa_stats also iterates and accounts for tasks stats running on
isolcpus.

I will send a patch with a slightly different approach.
Request you to review and verify the same.

--
Thanks and Regards
Srikar Dronamraju


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-23 17:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22  3:05 [PATCH] sched/numa: fix choosing isolated CPUs when task_numa_migrate() Yi Wang
2018-10-23 17:36 ` Srikar Dronamraju

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.