* [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq
@ 2019-08-26 12:16 Liangyan
2019-08-28 10:16 ` Valentin Schneider
2019-09-03 8:31 ` [tip: sched/urgent] sched/fair: Don't " tip-bot2 for Liangyan
0 siblings, 2 replies; 4+ messages in thread
From: Liangyan @ 2019-08-26 12:16 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Ben Segall, Valentin Schneider,
linux-kernel
Cc: shanpeic, xlpang
do_sched_cfs_period_timer() will refill cfs_b runtime and call
distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime
will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs
attached to this cfs_b can't get runtime and will be throttled.
We find that one throttled cfs_rq has non-negative
cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64
in snippet: distribute_cfs_runtime() {
runtime = -cfs_rq->runtime_remaining + 1; }.
The runtime here will change to a large number and consume all
cfs_b->runtime in this cfs_b period.
According to Ben Segall, the throttled cfs_rq can have
account_cfs_rq_runtime called on it because it is throttled before
idle_balance, and the idle_balance calls update_rq_clock to add time
that is accounted to the task.
This commit prevents cfs_rq to be assgined new runtime if it has been
throttled until that distribute_cfs_runtime is called.
Signed-off-by: Liangyan <liangyan.peng@linux.alibaba.com>
Reviewed-by: Ben Segall <bsegall@google.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
---
kernel/sched/fair.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index bc9cfeaac8bd..500f5db0de0b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4470,6 +4470,8 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)
if (likely(cfs_rq->runtime_remaining > 0))
return;
+ if (cfs_rq->throttled)
+ return;
/*
* if we're unable to extend our runtime we resched so that the active
* hierarchy can be throttled
@@ -4673,6 +4675,9 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b,
if (!cfs_rq_throttled(cfs_rq))
goto next;
+ /* By the above check, this should never be true */
+ SCHED_WARN_ON(cfs_rq->runtime_remaining > 0);
+
runtime = -cfs_rq->runtime_remaining + 1;
if (runtime > remaining)
runtime = remaining;
--
2.14.4.44.g2045bb6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq
2019-08-26 12:16 [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq Liangyan
@ 2019-08-28 10:16 ` Valentin Schneider
2019-08-28 11:41 ` Peter Zijlstra
2019-09-03 8:31 ` [tip: sched/urgent] sched/fair: Don't " tip-bot2 for Liangyan
1 sibling, 1 reply; 4+ messages in thread
From: Valentin Schneider @ 2019-08-28 10:16 UTC (permalink / raw)
To: Liangyan, Ingo Molnar, Peter Zijlstra, Ben Segall, linux-kernel
Cc: shanpeic, xlpang
On 26/08/2019 13:16, Liangyan wrote:
> do_sched_cfs_period_timer() will refill cfs_b runtime and call
> distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime
> will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs
> attached to this cfs_b can't get runtime and will be throttled.
>
> We find that one throttled cfs_rq has non-negative
> cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64
> in snippet: distribute_cfs_runtime() {
> runtime = -cfs_rq->runtime_remaining + 1; }.
> The runtime here will change to a large number and consume all
> cfs_b->runtime in this cfs_b period.
>
> According to Ben Segall, the throttled cfs_rq can have
> account_cfs_rq_runtime called on it because it is throttled before
> idle_balance, and the idle_balance calls update_rq_clock to add time
> that is accounted to the task.
>
> This commit prevents cfs_rq to be assgined new runtime if it has been
> throttled until that distribute_cfs_runtime is called.
>
> Signed-off-by: Liangyan <liangyan.peng@linux.alibaba.com>
> Reviewed-by: Ben Segall <bsegall@google.com>
> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
@Peter/Ingo, if we care about it I believe it can't hurt to strap
Cc: <stable@vger.kernel.org>
Fixes: d3d9dc330236 ("sched: Throttle entities exceeding their allowed bandwidth")
to the thing.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq
2019-08-28 10:16 ` Valentin Schneider
@ 2019-08-28 11:41 ` Peter Zijlstra
0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2019-08-28 11:41 UTC (permalink / raw)
To: Valentin Schneider
Cc: Liangyan, Ingo Molnar, Ben Segall, linux-kernel, shanpeic, xlpang
On Wed, Aug 28, 2019 at 11:16:52AM +0100, Valentin Schneider wrote:
> On 26/08/2019 13:16, Liangyan wrote:
> > do_sched_cfs_period_timer() will refill cfs_b runtime and call
> > distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime
> > will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs
> > attached to this cfs_b can't get runtime and will be throttled.
> >
> > We find that one throttled cfs_rq has non-negative
> > cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64
> > in snippet: distribute_cfs_runtime() {
> > runtime = -cfs_rq->runtime_remaining + 1; }.
> > The runtime here will change to a large number and consume all
> > cfs_b->runtime in this cfs_b period.
> >
> > According to Ben Segall, the throttled cfs_rq can have
> > account_cfs_rq_runtime called on it because it is throttled before
> > idle_balance, and the idle_balance calls update_rq_clock to add time
> > that is accounted to the task.
> >
> > This commit prevents cfs_rq to be assgined new runtime if it has been
> > throttled until that distribute_cfs_runtime is called.
> >
> > Signed-off-by: Liangyan <liangyan.peng@linux.alibaba.com>
> > Reviewed-by: Ben Segall <bsegall@google.com>
> > Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
>
> @Peter/Ingo, if we care about it I believe it can't hurt to strap
>
> Cc: <stable@vger.kernel.org>
> Fixes: d3d9dc330236 ("sched: Throttle entities exceeding their allowed bandwidth")
>
> to the thing.
OK, done.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip: sched/urgent] sched/fair: Don't assign runtime for throttled cfs_rq
2019-08-26 12:16 [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq Liangyan
2019-08-28 10:16 ` Valentin Schneider
@ 2019-09-03 8:31 ` tip-bot2 for Liangyan
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Liangyan @ 2019-09-03 8:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: Liangyan, Peter Zijlstra (Intel), Valentin Schneider, Ben Segall,
Linus Torvalds, Thomas Gleixner, shanpeic, stable, xlpang,
Ingo Molnar, Borislav Petkov, linux-kernel
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 5e2d2cc2588bd3307ce3937acbc2ed03c830a861
Gitweb: https://git.kernel.org/tip/5e2d2cc2588bd3307ce3937acbc2ed03c830a861
Author: Liangyan <liangyan.peng@linux.alibaba.com>
AuthorDate: Mon, 26 Aug 2019 20:16:33 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Sep 2019 08:55:07 +02:00
sched/fair: Don't assign runtime for throttled cfs_rq
do_sched_cfs_period_timer() will refill cfs_b runtime and call
distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime
will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs
attached to this cfs_b can't get runtime and will be throttled.
We find that one throttled cfs_rq has non-negative
cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64
in snippet:
distribute_cfs_runtime() {
runtime = -cfs_rq->runtime_remaining + 1;
}
The runtime here will change to a large number and consume all
cfs_b->runtime in this cfs_b period.
According to Ben Segall, the throttled cfs_rq can have
account_cfs_rq_runtime called on it because it is throttled before
idle_balance, and the idle_balance calls update_rq_clock to add time
that is accounted to the task.
This commit prevents cfs_rq to be assgined new runtime if it has been
throttled until that distribute_cfs_runtime is called.
Signed-off-by: Liangyan <liangyan.peng@linux.alibaba.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Reviewed-by: Ben Segall <bsegall@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: shanpeic@linux.alibaba.com
Cc: stable@vger.kernel.org
Cc: xlpang@linux.alibaba.com
Fixes: d3d9dc330236 ("sched: Throttle entities exceeding their allowed bandwidth")
Link: https://lkml.kernel.org/r/20190826121633.6538-1-liangyan.peng@linux.alibaba.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/fair.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index bc9cfea..500f5db 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4470,6 +4470,8 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)
if (likely(cfs_rq->runtime_remaining > 0))
return;
+ if (cfs_rq->throttled)
+ return;
/*
* if we're unable to extend our runtime we resched so that the active
* hierarchy can be throttled
@@ -4673,6 +4675,9 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b,
if (!cfs_rq_throttled(cfs_rq))
goto next;
+ /* By the above check, this should never be true */
+ SCHED_WARN_ON(cfs_rq->runtime_remaining > 0);
+
runtime = -cfs_rq->runtime_remaining + 1;
if (runtime > remaining)
runtime = remaining;
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-09-03 8:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-26 12:16 [PATCH v3] sched/fair: don't assign runtime for throttled cfs_rq Liangyan
2019-08-28 10:16 ` Valentin Schneider
2019-08-28 11:41 ` Peter Zijlstra
2019-09-03 8:31 ` [tip: sched/urgent] sched/fair: Don't " tip-bot2 for Liangyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox