Skip to content

Commit 14dbc56

Browse files
committed
Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Ingo writes: "scheduler fixes: Two fixes: a CFS-throttling bug fix, and an interactivity fix." * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/fair: Fix the min_vruntime update logic in dequeue_entity() sched/fair: Fix throttle_list starvation with low CFS quota
2 parents 9b00eb8 + 9845c49 commit 14dbc56

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

kernel/sched/fair.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
40014001
* put back on, and if we advance min_vruntime, we'll be placed back
40024002
* further than we started -- ie. we'll be penalized.
40034003
*/
4004-
if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
4004+
if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
40054005
update_min_vruntime(cfs_rq);
40064006
}
40074007

@@ -4476,9 +4476,13 @@ static void throttle_cfs_rq(struct cfs_rq *cfs_rq)
44764476

44774477
/*
44784478
* Add to the _head_ of the list, so that an already-started
4479-
* distribute_cfs_runtime will not see us
4479+
* distribute_cfs_runtime will not see us. If disribute_cfs_runtime is
4480+
* not running add to the tail so that later runqueues don't get starved.
44804481
*/
4481-
list_add_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq);
4482+
if (cfs_b->distribute_running)
4483+
list_add_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq);
4484+
else
4485+
list_add_tail_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq);
44824486

44834487
/*
44844488
* If we're the first throttled task, make sure the bandwidth
@@ -4622,14 +4626,16 @@ static int do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b, int overrun)
46224626
* in us over-using our runtime if it is all used during this loop, but
46234627
* only by limited amounts in that extreme case.
46244628
*/
4625-
while (throttled && cfs_b->runtime > 0) {
4629+
while (throttled && cfs_b->runtime > 0 && !cfs_b->distribute_running) {
46264630
runtime = cfs_b->runtime;
4631+
cfs_b->distribute_running = 1;
46274632
raw_spin_unlock(&cfs_b->lock);
46284633
/* we can't nest cfs_b->lock while distributing bandwidth */
46294634
runtime = distribute_cfs_runtime(cfs_b, runtime,
46304635
runtime_expires);
46314636
raw_spin_lock(&cfs_b->lock);
46324637

4638+
cfs_b->distribute_running = 0;
46334639
throttled = !list_empty(&cfs_b->throttled_cfs_rq);
46344640

46354641
cfs_b->runtime -= min(runtime, cfs_b->runtime);
@@ -4740,6 +4746,11 @@ static void do_sched_cfs_slack_timer(struct cfs_bandwidth *cfs_b)
47404746

47414747
/* confirm we're still not at a refresh boundary */
47424748
raw_spin_lock(&cfs_b->lock);
4749+
if (cfs_b->distribute_running) {
4750+
raw_spin_unlock(&cfs_b->lock);
4751+
return;
4752+
}
4753+
47434754
if (runtime_refresh_within(cfs_b, min_bandwidth_expiration)) {
47444755
raw_spin_unlock(&cfs_b->lock);
47454756
return;
@@ -4749,6 +4760,9 @@ static void do_sched_cfs_slack_timer(struct cfs_bandwidth *cfs_b)
47494760
runtime = cfs_b->runtime;
47504761

47514762
expires = cfs_b->runtime_expires;
4763+
if (runtime)
4764+
cfs_b->distribute_running = 1;
4765+
47524766
raw_spin_unlock(&cfs_b->lock);
47534767

47544768
if (!runtime)
@@ -4759,6 +4773,7 @@ static void do_sched_cfs_slack_timer(struct cfs_bandwidth *cfs_b)
47594773
raw_spin_lock(&cfs_b->lock);
47604774
if (expires == cfs_b->runtime_expires)
47614775
cfs_b->runtime -= min(runtime, cfs_b->runtime);
4776+
cfs_b->distribute_running = 0;
47624777
raw_spin_unlock(&cfs_b->lock);
47634778
}
47644779

@@ -4867,6 +4882,7 @@ void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b)
48674882
cfs_b->period_timer.function = sched_cfs_period_timer;
48684883
hrtimer_init(&cfs_b->slack_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
48694884
cfs_b->slack_timer.function = sched_cfs_slack_timer;
4885+
cfs_b->distribute_running = 0;
48704886
}
48714887

48724888
static void init_cfs_rq_runtime(struct cfs_rq *cfs_rq)

kernel/sched/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ struct cfs_bandwidth {
346346
int nr_periods;
347347
int nr_throttled;
348348
u64 throttled_time;
349+
350+
bool distribute_running;
349351
#endif
350352
};
351353

0 commit comments

Comments
 (0)