sched/fair: Fix overutilized update in enqueue_task_fair()
PATCH 1/1 sched/fair: Fix overutilized update in enqueue_task_fair()
enqueue_task_fair() attempts to skip the overutilized update for new tasks as their util_avg is not accurate yet. However, the flag we check to do so is overwritten earlier on in the function, which makes the condition pretty much a nop.
Fix this by saving the flag early on.
indicator")
--- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +2 -1
@@ -5477,6 +5477,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se;int idle_h_nr_running =task_has_idle_policy (p); +int task_new = !(flags &ENQUEUE_WAKEUP );/* * The code below (indirectly) updates schedutil which looks at
@@ -5549,7 +5550,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)* into account, but that is not straightforward to implement, * and the following generally works well enough in practice. */ -if (flags &ENQUEUE_WAKEUP ) +if (!task_new)update_overutilized_status (rq); enqueue_throttle:
Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog
Quoted 6 lines · Quentin Perret
enqueue_task_fair()attempts to skip the overutilized update for new tasks as theirutil_avgis not accurate yet. However, the flag we check to do so is overwritten earlier on in the function, which makes the condition pretty much a nop.
Quoted 6 lines
Fix this by saving the flag early on.
Fixes 2802bf3cd936 ("sched/fair: Add over-utilization/tipping pointindicator")
Reported-by Rick Yiu <[email protected]>Signed-off-by Quentin Perret <[email protected]>
Quoted 28 lines
--- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/fair.c +2
-2@@ -5477,6 +5477,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se;int idle_h_nr_running =task_has_idle_policy (p); +int task_new = !(flags &ENQUEUE_WAKEUP );/* * The code below (indirectly) updates schedutil which looks at @@ -5549,7 +5550,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)* into account, but that is not straightforward to implement, * and the following generally works well enough in practice. */ -if (flags &ENQUEUE_WAKEUP ) +if (!task_new)update_overutilized_status (rq); enqueue_throttle: --2.29.2.222.g5d2a92d10f8-goog
Hi Quentin,
Quoted 11 lines · Quentin Perret
enqueue_task_fair()attempts to skip the overutilized update for new tasks as theirutil_avgis not accurate yet. However, the flag we check to do so is overwritten earlier on in the function, which makes the condition pretty much a nop.Fix this by saving the flag early on.
Fixes 2802bf3cd936 ("sched/fair: Add over-utilization/tipping pointindicator")
Reported-by Rick Yiu <[email protected]>Signed-off-by Quentin Perret <[email protected]>
Alternatively: how much does not updating the overutilized status here help us? The next tick will unconditionally update it, which for arm64 is anywhere in the next ]0, 4]ms. That "fake" fork-time util_avg should already be accounted in the rq util_avg, and even if the new task was running the entire time, 4ms doesn't buy us much decay.
Quoted 25 lines
--- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/fair.c +2
-1@@ -5477,6 +5477,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se;int idle_h_nr_running =task_has_idle_policy (p); +int task_new = !(flags &ENQUEUE_WAKEUP );/* * The code below (indirectly) updates schedutil which looks at @@ -5549,7 +5550,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)* into account, but that is not straightforward to implement, * and the following generally works well enough in practice. */ -if (flags &ENQUEUE_WAKEUP ) +if (!task_new)update_overutilized_status (rq); enqueue_throttle:
Quoted 5 lines · Valentin Schneider
Alternatively: how much does not updating the overutilized status here help us? The next tick will unconditionally update it, which for arm64 is anywhere in the next ]0, 4]ms. That "fake" fork-time
util_avgshould already be accounted in the rqutil_avg, and even if the new task was running the entire time, 4ms doesn't buy us much decay.
Yes, this is arguably a dodgy hack, which will not save us in a number of cases. The only situation where this helps is for short-lived tasks that will run only once. And this is a sadly common programming pattern.
So yeah, this is not the prettiest thing in the world, but it doesn't cost us much and helps some real-world workloads, so ...
Thanks,
Quentin
Quoted 7 lines · Quentin Perret
Quoted 5 lines · Valentin Schneider
Alternatively: how much does not updating the overutilized status here help us? The next tick will unconditionally update it, which for arm64 is anywhere in the next ]0, 4]ms. That "fake" fork-time
util_avgshould already be accounted in the rqutil_avg, and even if the new task was running the entire time, 4ms doesn't buy us much decay.
Quoted 7 lines
Yes, this is arguably a dodgy hack, which will not save us in a number of cases. The only situation where this helps is for short-lived tasks that will run only once. And this is a sadly common programming pattern.
So yeah, this is not the prettiest thing in the world, but it doesn't cost us much and helps some real-world workloads, so ...
Aye aye
Quoted 2 lines
Thanks,
Quentin
Peter Zijlstra
maintainerQuoted 9 lines · Quentin Perret
enqueue_task_fair()attempts to skip the overutilized update for new tasks as theirutil_avgis not accurate yet. However, the flag we check to do so is overwritten earlier on in the function, which makes the condition pretty much a nop.Fix this by saving the flag early on.
Fixes 2802bf3cd936 ("sched/fair: Add over-utilization/tipping pointindicator")
Fix that wrapping for you :-)
Quoted 2 lines
Reported-by Rick Yiu <[email protected]>Signed-off-by Quentin Perret <[email protected]>
Thanks!
The following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 8e1ac4299a6e8726de42310d9c1379f188140c71 Gitweb: https://git.kernel.org/tip/8e1ac4299a6e8726de42310d9c1379f188140c71 Author: Quentin Perret <[email protected]> AuthorDate: Thu, 12 Nov 2020 11:12:01 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 17 Nov 2020 13:15:27 +01:00
sched/fair: Fix overutilized update in enqueue_task_fair()
enqueue_task_fair() attempts to skip the overutilized update for new tasks as their util_avg is not accurate yet. However, the flag we check to do so is overwritten earlier on in the function, which makes the condition pretty much a nop.
Fix this by saving the flag early on.
--- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +2 -1
@@ -5477,6 +5477,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se;int idle_h_nr_running =task_has_idle_policy (p); +int task_new = !(flags &ENQUEUE_WAKEUP );/* * The code below (indirectly) updates schedutil which looks at
@@ -5549,7 +5550,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)* into account, but that is not straightforward to implement, * and the following generally works well enough in practice. */ -if (flags &ENQUEUE_WAKEUP ) +if (!task_new)update_overutilized_status (rq); enqueue_throttle: