[PATCH] sched/fair: Avoid active balance on small load imbalance

From: Srikar Dronamraju
Date: Tue Jul 02 2019 - 17:38:29 EST


Skip active load balance when destination CPU is busy and the imbalance
is small and fix_small_imabalance is unable to calculate minor
imbalance. Its observed that active load balances can lead to ping-pong
of tasks between two CPUs.

Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
---
kernel/sched/fair.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3599bdcab395..0db380c8eb6c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7094,6 +7094,7 @@ enum group_type {
#define LBF_SOME_PINNED 0x08
#define LBF_NOHZ_STATS 0x10
#define LBF_NOHZ_AGAIN 0x20
+#define LBF_SMALL_IMBL 0x40

struct lb_env {
struct sched_domain *sd;
@@ -8386,6 +8387,8 @@ void fix_small_imbalance(struct lb_env *env, struct sd_lb_stats *sds)
/* Move if we gain throughput */
if (capa_move > capa_now)
env->imbalance = busiest->load_per_task;
+ else if (env->idle == CPU_NOT_IDLE)
+ env->flags |= LBF_SMALL_IMBL;
}

/**
@@ -8466,7 +8469,7 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s
* moved
*/
if (env->imbalance < busiest->load_per_task)
- return fix_small_imbalance(env, sds);
+ fix_small_imbalance(env, sds);
}

/******* find_busiest_group() helpers end here *********************/
@@ -8732,6 +8735,13 @@ static int need_active_balance(struct lb_env *env)
if (voluntary_active_balance(env))
return 1;

+ /*
+ * Destination CPU is not idle and fix_small_imbalance is unable
+ * to calculate even minor imbalances, skip active balance.
+ */
+ if (env->flags & LBF_SMALL_IMBL)
+ return 0;
+
return unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2);
}

--
2.18.1