Commit fab47622 authored by Nikhil Rao's avatar Nikhil Rao Committed by Ingo Molnar

sched: Force balancing on newidle balance if local group has capacity

This patch forces a load balance on a newly idle cpu when the local group has
extra capacity and the busiest group does not have any. It improves system
utilization when balancing tasks with a large weight differential.

Under certain situations, such as a niced down task (i.e. nice = -15) in the
presence of nr_cpus NICE0 tasks, the niced task lands on a sched group and
kicks away other tasks because of its large weight. This leads to sub-optimal
utilization of the machine. Even though the sched group has capacity, it does
not pull tasks because sds.this_load >> sds.max_load, and f_b_g() returns NULL.

With this patch, if the local group has extra capacity, we shortcut the checks
in f_b_g() and try to pull a task over. A sched group has extra capacity if the
group capacity is greater than the number of running tasks in that group.

Thanks to Mike Galbraith for discussions leading to this patch and for the
insight to reuse SD_NEWIDLE_BALANCE.
Signed-off-by: default avatarNikhil Rao <ncrao@google.com>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1287173550-30365-4-git-send-email-ncrao@google.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 2582f0eb
...@@ -1764,6 +1764,10 @@ static void pull_task(struct rq *src_rq, struct task_struct *p, ...@@ -1764,6 +1764,10 @@ static void pull_task(struct rq *src_rq, struct task_struct *p,
set_task_cpu(p, this_cpu); set_task_cpu(p, this_cpu);
activate_task(this_rq, p, 0); activate_task(this_rq, p, 0);
check_preempt_curr(this_rq, p, 0); check_preempt_curr(this_rq, p, 0);
/* re-arm NEWIDLE balancing when moving tasks */
src_rq->avg_idle = this_rq->avg_idle = 2*sysctl_sched_migration_cost;
this_rq->idle_stamp = 0;
} }
/* /*
...@@ -2030,12 +2034,14 @@ struct sd_lb_stats { ...@@ -2030,12 +2034,14 @@ struct sd_lb_stats {
unsigned long this_load; unsigned long this_load;
unsigned long this_load_per_task; unsigned long this_load_per_task;
unsigned long this_nr_running; unsigned long this_nr_running;
unsigned long this_has_capacity;
/* Statistics of the busiest group */ /* Statistics of the busiest group */
unsigned long max_load; unsigned long max_load;
unsigned long busiest_load_per_task; unsigned long busiest_load_per_task;
unsigned long busiest_nr_running; unsigned long busiest_nr_running;
unsigned long busiest_group_capacity; unsigned long busiest_group_capacity;
unsigned long busiest_has_capacity;
int group_imb; /* Is there imbalance in this sd */ int group_imb; /* Is there imbalance in this sd */
#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
...@@ -2058,6 +2064,7 @@ struct sg_lb_stats { ...@@ -2058,6 +2064,7 @@ struct sg_lb_stats {
unsigned long sum_weighted_load; /* Weighted load of group's tasks */ unsigned long sum_weighted_load; /* Weighted load of group's tasks */
unsigned long group_capacity; unsigned long group_capacity;
int group_imb; /* Is there an imbalance in the group ? */ int group_imb; /* Is there an imbalance in the group ? */
int group_has_capacity; /* Is there extra capacity in the group? */
}; };
/** /**
...@@ -2456,6 +2463,9 @@ static inline void update_sg_lb_stats(struct sched_domain *sd, ...@@ -2456,6 +2463,9 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE); sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE);
if (!sgs->group_capacity) if (!sgs->group_capacity)
sgs->group_capacity = fix_small_capacity(sd, group); sgs->group_capacity = fix_small_capacity(sd, group);
if (sgs->group_capacity > sgs->sum_nr_running)
sgs->group_has_capacity = 1;
} }
/** /**
...@@ -2554,12 +2564,14 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu, ...@@ -2554,12 +2564,14 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu,
sds->this = sg; sds->this = sg;
sds->this_nr_running = sgs.sum_nr_running; sds->this_nr_running = sgs.sum_nr_running;
sds->this_load_per_task = sgs.sum_weighted_load; sds->this_load_per_task = sgs.sum_weighted_load;
sds->this_has_capacity = sgs.group_has_capacity;
} else if (update_sd_pick_busiest(sd, sds, sg, &sgs, this_cpu)) { } else if (update_sd_pick_busiest(sd, sds, sg, &sgs, this_cpu)) {
sds->max_load = sgs.avg_load; sds->max_load = sgs.avg_load;
sds->busiest = sg; sds->busiest = sg;
sds->busiest_nr_running = sgs.sum_nr_running; sds->busiest_nr_running = sgs.sum_nr_running;
sds->busiest_group_capacity = sgs.group_capacity; sds->busiest_group_capacity = sgs.group_capacity;
sds->busiest_load_per_task = sgs.sum_weighted_load; sds->busiest_load_per_task = sgs.sum_weighted_load;
sds->busiest_has_capacity = sgs.group_has_capacity;
sds->group_imb = sgs.group_imb; sds->group_imb = sgs.group_imb;
} }
...@@ -2756,6 +2768,7 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu, ...@@ -2756,6 +2768,7 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu,
return fix_small_imbalance(sds, this_cpu, imbalance); return fix_small_imbalance(sds, this_cpu, imbalance);
} }
/******* find_busiest_group() helpers end here *********************/ /******* find_busiest_group() helpers end here *********************/
/** /**
...@@ -2807,6 +2820,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, ...@@ -2807,6 +2820,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
* 4) This group is more busy than the avg busieness at this * 4) This group is more busy than the avg busieness at this
* sched_domain. * sched_domain.
* 5) The imbalance is within the specified limit. * 5) The imbalance is within the specified limit.
*
* Note: when doing newidle balance, if the local group has excess
* capacity (i.e. nr_running < group_capacity) and the busiest group
* does not have any capacity, we force a load balance to pull tasks
* to the local group. In this case, we skip past checks 3, 4 and 5.
*/ */
if (!(*balance)) if (!(*balance))
goto ret; goto ret;
...@@ -2818,6 +2836,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, ...@@ -2818,6 +2836,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
if (!sds.busiest || sds.busiest_nr_running == 0) if (!sds.busiest || sds.busiest_nr_running == 0)
goto out_balanced; goto out_balanced;
/* SD_BALANCE_NEWIDLE trumps SMP nice when underutilized */
if (idle == CPU_NEWLY_IDLE && sds.this_has_capacity &&
!sds.busiest_has_capacity)
goto force_balance;
if (sds.this_load >= sds.max_load) if (sds.this_load >= sds.max_load)
goto out_balanced; goto out_balanced;
...@@ -2829,6 +2852,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, ...@@ -2829,6 +2852,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
if (100 * sds.max_load <= sd->imbalance_pct * sds.this_load) if (100 * sds.max_load <= sd->imbalance_pct * sds.this_load)
goto out_balanced; goto out_balanced;
force_balance:
/* Looks like there is an imbalance. Compute it */ /* Looks like there is an imbalance. Compute it */
calculate_imbalance(&sds, this_cpu, imbalance); calculate_imbalance(&sds, this_cpu, imbalance);
return sds.busiest; return sds.busiest;
...@@ -3162,11 +3186,9 @@ static void idle_balance(int this_cpu, struct rq *this_rq) ...@@ -3162,11 +3186,9 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
interval = msecs_to_jiffies(sd->balance_interval); interval = msecs_to_jiffies(sd->balance_interval);
if (time_after(next_balance, sd->last_balance + interval)) if (time_after(next_balance, sd->last_balance + interval))
next_balance = sd->last_balance + interval; next_balance = sd->last_balance + interval;
if (pulled_task) { if (pulled_task)
this_rq->idle_stamp = 0;
break; break;
} }
}
raw_spin_lock(&this_rq->lock); raw_spin_lock(&this_rq->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment