diff mbox series

[v3] sched/fair: use utilization to select misfit task

Message ID 1564750572-20251-1-git-send-email-vincent.guittot@linaro.org
State Superseded
Headers show
Series [v3] sched/fair: use utilization to select misfit task | expand

Commit Message

Vincent Guittot Aug. 2, 2019, 12:56 p.m. UTC
utilization is used to detect a misfit task but the load is then used to
select the task on the CPU which can lead to select a small task with
high weight instead of the task that triggered the misfit migration.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

---
Keep tracking load instead of utilization but check that 
task doesn't fit CPU's capacity when selecting the task to detach as
suggested by Valentin 

 kernel/sched/fair.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

-- 
2.7.4

Comments

Valentin Schneider Aug. 2, 2019, 2:27 p.m. UTC | #1
On 02/08/2019 13:56, Vincent Guittot wrote:
> utilization is used to detect a misfit task but the load is then used to

> select the task on the CPU which can lead to select a small task with

> high weight instead of the task that triggered the misfit migration.

> 

> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---

> Keep tracking load instead of utilization but check that 

> task doesn't fit CPU's capacity when selecting the task to detach as

> suggested by Valentin 

> 


I find that one much better :) The very same fix could be applied
regardless of the rework, so FWIW (providing the changelog gets a bit
clearer - maybe squash the comment in it):
Acked-by: Valentin Schneider <valentin.schneider@arm.com>



One more thing though: we actually face the same problem in active balance,
i.e. the misfit task could sleep/get preempted before the CPU stopper
actually runs, and that latter would migrate $random.

I was thinking of passing the lb_env to stop_one_cpu_nowait() - we'd have
to rebuild it in active_load_balance_cpu_stop() anyway, but we could copy
things like env.migration_type so that we remember that we should be
picking a misfit task and have a similar detach guard.

Sadly, the lb_env struct is on load_balance()'s stack, and that's a nowait
call :/

Peter/Thomas, would there be much hate in adding some sort of flags field
to struct cpu_stop_work? Or if you see a better alternative, I'm all ears.


>  kernel/sched/fair.c | 12 +++---------

>  1 file changed, 3 insertions(+), 9 deletions(-)

> 

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c

> index 53e64a7..8496118 100644

> --- a/kernel/sched/fair.c

> +++ b/kernel/sched/fair.c

> @@ -7487,15 +7487,9 @@ static int detach_tasks(struct lb_env *env)

>  			break;

>  

>  		case migrate_misfit:

> -			load = task_h_load(p);

> -

> -			/*

> -			 * utilization of misfit task might decrease a bit

> -			 * since it has been recorded. Be conservative in the

> -			 * condition.

> -			 */

> -			if (load < env->imbalance)

> -				goto next;

> +			/* This is not a misfit task */

> +                       if (task_fits_capacity(p, capacity_of(env->src_cpu)))

> +			       goto next;

>  

>  			env->imbalance = 0;

>  			break;

>
Valentin Schneider Aug. 5, 2019, 11:01 a.m. UTC | #2
On 02/08/2019 13:56, Vincent Guittot wrote:
> utilization is used to detect a misfit task but the load is then used to

> select the task on the CPU which can lead to select a small task with

> high weight instead of the task that triggered the misfit migration.

> 

> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---

> Keep tracking load instead of utilization but check that 

> task doesn't fit CPU's capacity when selecting the task to detach as

> suggested by Valentin 

> 

>  kernel/sched/fair.c | 12 +++---------

>  1 file changed, 3 insertions(+), 9 deletions(-)

> 

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c

> index 53e64a7..8496118 100644

> --- a/kernel/sched/fair.c

> +++ b/kernel/sched/fair.c

> @@ -7487,15 +7487,9 @@ static int detach_tasks(struct lb_env *env)

>  			break;

>  

>  		case migrate_misfit:

> -			load = task_h_load(p);

> -

> -			/*

> -			 * utilization of misfit task might decrease a bit

> -			 * since it has been recorded. Be conservative in the

> -			 * condition.

> -			 */

> -			if (load < env->imbalance)

> -				goto next;

> +			/* This is not a misfit task */

> +                       if (task_fits_capacity(p, capacity_of(env->src_cpu)))

   ^^^^^^^^^^^^^^^^^^^^^^^
Just noticed those are spaces for some reason (I think my original diff is
to blame)

> +			       goto next;

>  

>  			env->imbalance = 0;

>  			break;

>
diff mbox series

Patch

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 53e64a7..8496118 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7487,15 +7487,9 @@  static int detach_tasks(struct lb_env *env)
 			break;
 
 		case migrate_misfit:
-			load = task_h_load(p);
-
-			/*
-			 * utilization of misfit task might decrease a bit
-			 * since it has been recorded. Be conservative in the
-			 * condition.
-			 */
-			if (load < env->imbalance)
-				goto next;
+			/* This is not a misfit task */
+                       if (task_fits_capacity(p, capacity_of(env->src_cpu)))
+			       goto next;
 
 			env->imbalance = 0;
 			break;