mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihui Zhang <zzhsuny@gmail.com>
To: riel@redhat.com, peterz@infradead.org, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] sched/fair: remove the swap() logic in load_too_imbalanced()
Date: Sat, 17 Oct 2015 11:06:32 -0400	[thread overview]
Message-ID: <1445094392-12398-1-git-send-email-zzhsuny@gmail.com> (raw)

The swap() logic was introduced before we scaled the load by the
actual CPU capacity. Now it looks funny that we swap the load but
not the CPU capacity. In fact, we probably need to check both
directions to ensure that the load of neither side increase too
high compared to the other side.

Signed-off-by: Zhihui Zhang <zzhsuny@gmail.com>
---
 kernel/sched/fair.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6e2e348..5e8e17b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1203,7 +1203,7 @@ static void task_numa_assign(struct task_numa_env *env,
 static bool load_too_imbalanced(long src_load, long dst_load,
 				struct task_numa_env *env)
 {
-	long imb, old_imb;
+	long imb1, imb2, orig_imb1, orig_imb2;
 	long orig_src_load, orig_dst_load;
 	long src_capacity, dst_capacity;
 
@@ -1217,31 +1217,33 @@ static bool load_too_imbalanced(long src_load, long dst_load,
 	src_capacity = env->src_stats.compute_capacity;
 	dst_capacity = env->dst_stats.compute_capacity;
 
-	/* We care about the slope of the imbalance, not the direction. */
-	if (dst_load < src_load)
-		swap(dst_load, src_load);
-
-	/* Is the difference below the threshold? */
-	imb = dst_load * src_capacity * 100 -
-	      src_load * dst_capacity * env->imbalance_pct;
-	if (imb <= 0)
+	/* Does the difference in either direction exceed the threshold? */
+	imb1 = dst_load * src_capacity * 100 -
+	       src_load * dst_capacity * env->imbalance_pct;
+	imb2 = src_load * dst_capacity * 100 -
+	       dst_load * src_capacity * env->imbalance_pct;
+	if (imb1 <= 0 && imb2 <= 0)
 		return false;
 
 	/*
-	 * The imbalance is above the allowed threshold.
-	 * Compare it with the old imbalance.
+	 * At least one imbalance is above the allowed threshold.
+	 * Compare it with the original imbalance.
 	 */
 	orig_src_load = env->src_stats.load;
 	orig_dst_load = env->dst_stats.load;
 
-	if (orig_dst_load < orig_src_load)
-		swap(orig_dst_load, orig_src_load);
-
-	old_imb = orig_dst_load * src_capacity * 100 -
-		  orig_src_load * dst_capacity * env->imbalance_pct;
+	orig_imb1 = orig_dst_load * src_capacity * 100 -
+		    orig_src_load * dst_capacity * env->imbalance_pct;
+	orig_imb2 = orig_src_load * dst_capacity * 100 -
+		    orig_dst_load * src_capacity * env->imbalance_pct;
 
 	/* Would this change make things worse? */
-	return (imb > old_imb);
+	if (imb1 > 0 && imb1 > orig_imb1)
+		return true;
+	if (imb2 > 0 && imb2 > orig_imb2)
+		return true;
+
+	return false;
 }
 
 /*
-- 
1.9.1


                 reply	other threads:[~2015-10-17 15:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445094392-12398-1-git-send-email-zzhsuny@gmail.com \
    --to=zzhsuny@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®