linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition
@ 2018-09-26 15:12 Valentin Schneider
  2018-09-26 15:12 ` [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance Valentin Schneider
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Valentin Schneider @ 2018-09-26 15:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, peterz, vincent.guittot, Dietmar.Eggemann, patrick.bellasi

The alignment of the condition is off, clean that up.

Also, logical operators have lower precedence than bitwise/relational
operators, so remove one layer of parentheses to make the condition a
bit simpler to follow.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
---
 kernel/sched/fair.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6bd142d..9cf93ba 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8783,9 +8783,9 @@ static int load_balance(int this_cpu, struct rq *this_rq,
 
 out_one_pinned:
 	/* tune up the balancing interval */
-	if (((env.flags & LBF_ALL_PINNED) &&
-			sd->balance_interval < MAX_PINNED_INTERVAL) ||
-			(sd->balance_interval < sd->max_interval))
+	if ((env.flags & LBF_ALL_PINNED &&
+	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
+	    sd->balance_interval < sd->max_interval)
 		sd->balance_interval *= 2;
 
 	ld_moved = 0;
-- 
2.7.4


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

* [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance
  2018-09-26 15:12 [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
@ 2018-09-26 15:12 ` Valentin Schneider
  2018-11-04  0:13   ` [tip:sched/core] " tip-bot for Valentin Schneider
  2018-10-30 10:27 ` [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
  2018-11-04  0:13 ` [tip:sched/core] sched/fair: Clean up " tip-bot for Valentin Schneider
  2 siblings, 1 reply; 6+ messages in thread
From: Valentin Schneider @ 2018-09-26 15:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, peterz, vincent.guittot, Dietmar.Eggemann, patrick.bellasi

When load_balance() fails to move some load because of task affinity,
we end up increasing sd->balance_interval to delay the next periodic
balance in the hopes that next time we look, that annoying pinned
task(s) will be gone.

However, idle_balance() pays no attention to sd->balance_interval, yet
it will still lead to an increase in balance_interval in case of
pinned tasks.

If we're going through several newidle balances (e.g. we have a
periodic task), this can lead to a huge increase of the
balance_interval in a very small amount of time.

To prevent that, don't increase the balance interval when going
through a newidle balance.

This is a similar approach to what is done in commit 58b26c4c0257
("sched: Increment cache_nice_tries only on periodic lb"), where we
disregard newidle balance and rely on periodic balance for more stable
results.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
---
 kernel/sched/fair.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 9cf93ba..4c33283 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8782,13 +8782,22 @@ static int load_balance(int this_cpu, struct rq *this_rq,
 	sd->nr_balance_failed = 0;
 
 out_one_pinned:
+	ld_moved = 0;
+
+	/*
+	 * idle_balance() disregards balance intervals, so we could repeatedly
+	 * reach this code, which would lead to balance_interval skyrocketting
+	 * in a short amount of time. Skip the balance_interval increase logic
+	 * to avoid that.
+	 */
+	if (env.idle == CPU_NEWLY_IDLE)
+		goto out;
+
 	/* tune up the balancing interval */
 	if ((env.flags & LBF_ALL_PINNED &&
 	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
 	    sd->balance_interval < sd->max_interval)
 		sd->balance_interval *= 2;
-
-	ld_moved = 0;
 out:
 	return ld_moved;
 }
-- 
2.7.4


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

* Re: [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition
  2018-09-26 15:12 [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
  2018-09-26 15:12 ` [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance Valentin Schneider
@ 2018-10-30 10:27 ` Valentin Schneider
  2018-10-30 12:41   ` Peter Zijlstra
  2018-11-04  0:13 ` [tip:sched/core] sched/fair: Clean up " tip-bot for Valentin Schneider
  2 siblings, 1 reply; 6+ messages in thread
From: Valentin Schneider @ 2018-10-30 10:27 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, peterz, vincent.guittot, Dietmar.Eggemann, patrick.bellasi

Hi,

On 26/09/2018 16:12, Valentin Schneider wrote:
> The alignment of the condition is off, clean that up.
> 
> Also, logical operators have lower precedence than bitwise/relational
> operators, so remove one layer of parentheses to make the condition a
> bit simpler to follow.
> 
> Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> ---
>  kernel/sched/fair.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 6bd142d..9cf93ba 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8783,9 +8783,9 @@ static int load_balance(int this_cpu, struct rq *this_rq,
>  
>  out_one_pinned:
>  	/* tune up the balancing interval */
> -	if (((env.flags & LBF_ALL_PINNED) &&
> -			sd->balance_interval < MAX_PINNED_INTERVAL) ||
> -			(sd->balance_interval < sd->max_interval))
> +	if ((env.flags & LBF_ALL_PINNED &&
> +	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
> +	    sd->balance_interval < sd->max_interval)
>  		sd->balance_interval *= 2;
>  
>  	ld_moved = 0;
> 

Is there anything else that should be done for these two patches?

Thanks,
Valentin

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

* Re: [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition
  2018-10-30 10:27 ` [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
@ 2018-10-30 12:41   ` Peter Zijlstra
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2018-10-30 12:41 UTC (permalink / raw)
  To: Valentin Schneider
  Cc: linux-kernel, mingo, vincent.guittot, Dietmar.Eggemann, patrick.bellasi

On Tue, Oct 30, 2018 at 10:27:59AM +0000, Valentin Schneider wrote:
> Hi,
> 
> On 26/09/2018 16:12, Valentin Schneider wrote:
> > The alignment of the condition is off, clean that up.
> > 
> > Also, logical operators have lower precedence than bitwise/relational
> > operators, so remove one layer of parentheses to make the condition a
> > bit simpler to follow.
> > 
> > Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> > ---
> >  kernel/sched/fair.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 6bd142d..9cf93ba 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -8783,9 +8783,9 @@ static int load_balance(int this_cpu, struct rq *this_rq,
> >  
> >  out_one_pinned:
> >  	/* tune up the balancing interval */
> > -	if (((env.flags & LBF_ALL_PINNED) &&
> > -			sd->balance_interval < MAX_PINNED_INTERVAL) ||
> > -			(sd->balance_interval < sd->max_interval))
> > +	if ((env.flags & LBF_ALL_PINNED &&
> > +	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
> > +	    sd->balance_interval < sd->max_interval)
> >  		sd->balance_interval *= 2;
> >  
> >  	ld_moved = 0;
> > 
> 
> Is there anything else that should be done for these two patches?

Have them now, Thanks!

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

* [tip:sched/core] sched/fair: Clean up load_balance() condition
  2018-09-26 15:12 [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
  2018-09-26 15:12 ` [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance Valentin Schneider
  2018-10-30 10:27 ` [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
@ 2018-11-04  0:13 ` tip-bot for Valentin Schneider
  2 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Valentin Schneider @ 2018-11-04  0:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, torvalds, peterz, tglx, hpa, valentin.schneider, mingo

Commit-ID:  47b7aee14fd7e453370a5d15dfb11c958ca360f2
Gitweb:     https://git.kernel.org/tip/47b7aee14fd7e453370a5d15dfb11c958ca360f2
Author:     Valentin Schneider <valentin.schneider@arm.com>
AuthorDate: Wed, 26 Sep 2018 16:12:06 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 4 Nov 2018 00:59:22 +0100

sched/fair: Clean up load_balance() condition

The alignment of the condition is off, clean that up.

Also, logical operators have lower precedence than bitwise/relational
operators, so remove one layer of parentheses to make the condition a
bit simpler to follow.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Dietmar.Eggemann@arm.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: patrick.bellasi@arm.com
Cc: vincent.guittot@linaro.org
Link: http://lkml.kernel.org/r/1537974727-30788-1-git-send-email-valentin.schneider@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ee271bb661cc..4e298931a715 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8877,9 +8877,9 @@ out_all_pinned:
 
 out_one_pinned:
 	/* tune up the balancing interval */
-	if (((env.flags & LBF_ALL_PINNED) &&
-			sd->balance_interval < MAX_PINNED_INTERVAL) ||
-			(sd->balance_interval < sd->max_interval))
+	if ((env.flags & LBF_ALL_PINNED &&
+	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
+	    sd->balance_interval < sd->max_interval)
 		sd->balance_interval *= 2;
 
 	ld_moved = 0;

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

* [tip:sched/core] sched/fair: Don't increase sd->balance_interval on newidle balance
  2018-09-26 15:12 ` [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance Valentin Schneider
@ 2018-11-04  0:13   ` tip-bot for Valentin Schneider
  0 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Valentin Schneider @ 2018-11-04  0:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, mingo, peterz, linux-kernel, tglx, hpa, valentin.schneider

Commit-ID:  3f130a37c442d5c4d66531b240ebe9abfef426b5
Gitweb:     https://git.kernel.org/tip/3f130a37c442d5c4d66531b240ebe9abfef426b5
Author:     Valentin Schneider <valentin.schneider@arm.com>
AuthorDate: Wed, 26 Sep 2018 16:12:07 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 4 Nov 2018 00:59:23 +0100

sched/fair: Don't increase sd->balance_interval on newidle balance

When load_balance() fails to move some load because of task affinity,
we end up increasing sd->balance_interval to delay the next periodic
balance in the hopes that next time we look, that annoying pinned
task(s) will be gone.

However, idle_balance() pays no attention to sd->balance_interval, yet
it will still lead to an increase in balance_interval in case of
pinned tasks.

If we're going through several newidle balances (e.g. we have a
periodic task), this can lead to a huge increase of the
balance_interval in a very small amount of time.

To prevent that, don't increase the balance interval when going
through a newidle balance.

This is a similar approach to what is done in commit 58b26c4c0257
("sched: Increment cache_nice_tries only on periodic lb"), where we
disregard newidle balance and rely on periodic balance for more stable
results.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Dietmar.Eggemann@arm.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: patrick.bellasi@arm.com
Cc: vincent.guittot@linaro.org
Link: http://lkml.kernel.org/r/1537974727-30788-2-git-send-email-valentin.schneider@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4e298931a715..a17ca4254427 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8876,13 +8876,22 @@ out_all_pinned:
 	sd->nr_balance_failed = 0;
 
 out_one_pinned:
+	ld_moved = 0;
+
+	/*
+	 * idle_balance() disregards balance intervals, so we could repeatedly
+	 * reach this code, which would lead to balance_interval skyrocketting
+	 * in a short amount of time. Skip the balance_interval increase logic
+	 * to avoid that.
+	 */
+	if (env.idle == CPU_NEWLY_IDLE)
+		goto out;
+
 	/* tune up the balancing interval */
 	if ((env.flags & LBF_ALL_PINNED &&
 	     sd->balance_interval < MAX_PINNED_INTERVAL) ||
 	    sd->balance_interval < sd->max_interval)
 		sd->balance_interval *= 2;
-
-	ld_moved = 0;
 out:
 	return ld_moved;
 }

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

end of thread, other threads:[~2018-11-04  0:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26 15:12 [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
2018-09-26 15:12 ` [PATCH v2 2/2] sched/fair: Don't increase sd->balance_interval on newidle balance Valentin Schneider
2018-11-04  0:13   ` [tip:sched/core] " tip-bot for Valentin Schneider
2018-10-30 10:27 ` [PATCH v2 1/2] sched/fair: Cleanup load_balance() condition Valentin Schneider
2018-10-30 12:41   ` Peter Zijlstra
2018-11-04  0:13 ` [tip:sched/core] sched/fair: Clean up " tip-bot for Valentin Schneider

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).