From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org
Cc: Ben Segall <bsegall@google.com>, Roman Gushchin <klamm@yandex-team.ru>
Subject: [PATCH RFC] sched/fair: fix sudden expiration of cfq quota in put_prev_task()
Date: Fri, 03 Apr 2015 15:41:38 +0300 [thread overview]
Message-ID: <20150403124138.1349.11633.stgit@buzz> (raw)
Pick_next_task_fair() must be sure that here is at least one runnable
task before calling put_prev_task(), but put_prev_task() can expire
last remains of cfs quota and throttle all currently runnable tasks.
As a result pick_next_task_fair() cannot find next task and crashes.
This patch leaves 1 in ->runtime_remaining when current assignation
expires and tries to refill it right after that. In the worst case
task will be scheduled once and throttled at the end of slice.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
kernel/sched/fair.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7ce18f3c097a..91785d077db4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3447,11 +3447,12 @@ static void expire_cfs_rq_runtime(struct cfs_rq *cfs_rq)
{
struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg);
- /* if the deadline is ahead of our clock, nothing to do */
- if (likely((s64)(rq_clock(rq_of(cfs_rq)) - cfs_rq->runtime_expires) < 0))
+ /* nothing to expire */
+ if (cfs_rq->runtime_remaining <= 0)
return;
- if (cfs_rq->runtime_remaining < 0)
+ /* if the deadline is ahead of our clock, nothing to do */
+ if (likely((s64)(rq_clock(rq_of(cfs_rq)) - cfs_rq->runtime_expires) < 0))
return;
/*
@@ -3469,8 +3470,14 @@ static void expire_cfs_rq_runtime(struct cfs_rq *cfs_rq)
/* extend local deadline, drift is bounded above by 2 ticks */
cfs_rq->runtime_expires += TICK_NSEC;
} else {
- /* global deadline is ahead, expiration has passed */
- cfs_rq->runtime_remaining = 0;
+ /*
+ * Global deadline is ahead, expiration has passed.
+ *
+ * Do not expire runtime completely. Otherwise put_prev_task()
+ * can throttle all tasks when we already checked nr_running or
+ * put_prev_entity() can throttle already chosen next entity.
+ */
+ cfs_rq->runtime_remaining = 1;
}
}
@@ -3480,7 +3487,7 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)
cfs_rq->runtime_remaining -= delta_exec;
expire_cfs_rq_runtime(cfs_rq);
- if (likely(cfs_rq->runtime_remaining > 0))
+ if (likely(cfs_rq->runtime_remaining > 1))
return;
/*
next reply other threads:[~2015-04-03 12:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-03 12:41 Konstantin Khlebnikov [this message]
2015-04-03 12:51 ` [PATCH RFC] sched/fair: fix sudden expiration of cfq quota in put_prev_task() Konstantin Khlebnikov
2015-04-07 12:52 ` Peter Zijlstra
2015-04-07 13:47 ` Peter Zijlstra
2015-04-07 15:12 ` Peter Zijlstra
2015-04-07 15:32 ` Konstantin Khlebnikov
2015-04-07 15:43 ` Peter Zijlstra
2015-04-06 22:45 ` bsegall
2015-04-07 15:53 ` Konstantin Khlebnikov
2015-06-07 17:47 ` [tip:sched/core] sched/fair: Prevent throttling in early pick_next_task_fair() tip-bot for Ben Segall
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=20150403124138.1349.11633.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=bsegall@google.com \
--cc=klamm@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/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