From: Odin Ugedal <odin@uged.al>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Odin Ugedal <odin@uged.al>
Subject: [PATCH 2/3] sched/fair: Correctly insert cfs_rq's to list on unthrottle
Date: Tue, 18 May 2021 14:52:01 +0200 [thread overview]
Message-ID: <20210518125202.78658-3-odin@uged.al> (raw)
In-Reply-To: <20210518125202.78658-1-odin@uged.al>
This fixes an issue where fairness is decreased since cfs_rq's can
end up not being decayed properly. For two sibling control groups with
the same priority, this can often lead to a load ratio of 99/1 (!!).
This happen because when a cfs_rq is throttled, all the descendant cfs_rq's
will be removed from the leaf list. When they initial cfs_rq is
unthrottled, it will currently only re add descendant cfs_rq's if they
have one or more entities enqueued. This is not a perfect heuristic.
This fix change this behavior to save what cfs_rq's was removed from the
list, and readds them properly on unthrottle.
Can often lead to sutiations like this for equally weighted control
groups:
$ ps u -C stress
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 10009 88.8 0.0 3676 100 pts/1 R+ 11:04 0:13 stress --cpu 1
root 10023 3.0 0.0 3676 104 pts/1 R+ 11:04 0:00 stress --cpu 1
Fixes: 31bc6aeaab1d ("sched/fair: Optimize update_blocked_averages()")
Signed-off-by: Odin Ugedal <odin@uged.al>
---
kernel/sched/fair.c | 11 ++++++-----
kernel/sched/sched.h | 1 +
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ceda53c2a87a..e7423d658389 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -376,7 +376,8 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq)
return false;
}
-static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
+/* Returns 1 if cfs_rq was present in the list and removed */
+static inline bool list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
{
if (cfs_rq->on_list) {
struct rq *rq = rq_of(cfs_rq);
@@ -393,7 +394,9 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
list_del_rcu(&cfs_rq->leaf_cfs_rq_list);
cfs_rq->on_list = 0;
+ return 1;
}
+ return 0;
}
static inline void assert_list_leaf_cfs_rq(struct rq *rq)
@@ -4742,9 +4745,7 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
if (!cfs_rq->throttle_count) {
cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
cfs_rq->throttled_clock_task;
-
- /* Add cfs_rq with already running entity in the list */
- if (cfs_rq->nr_running >= 1)
+ if (cfs_rq->insert_on_unthrottle)
list_add_leaf_cfs_rq(cfs_rq);
}
@@ -4759,7 +4760,7 @@ static int tg_throttle_down(struct task_group *tg, void *data)
/* group is entering throttled state, stop time */
if (!cfs_rq->throttle_count) {
cfs_rq->throttled_clock_task = rq_clock_task(rq);
- list_del_leaf_cfs_rq(cfs_rq);
+ cfs_rq->insert_on_unthrottle = list_del_leaf_cfs_rq(cfs_rq);
}
cfs_rq->throttle_count++;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index a189bec13729..12a707d99ee6 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -602,6 +602,7 @@ struct cfs_rq {
u64 throttled_clock_task_time;
int throttled;
int throttle_count;
+ int insert_on_unthrottle;
struct list_head throttled_list;
#endif /* CONFIG_CFS_BANDWIDTH */
#endif /* CONFIG_FAIR_GROUP_SCHED */
--
2.31.1
next prev parent reply other threads:[~2021-05-18 12:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 12:51 [PATCH 0/3] sched/fair: Fix load decay issues related to throttling Odin Ugedal
2021-05-18 12:52 ` [PATCH 1/3] sched/fair: Add tg_load_contrib cfs_rq decay checking Odin Ugedal
2021-05-25 9:58 ` Vincent Guittot
2021-05-25 10:33 ` Odin Ugedal
2021-05-25 14:30 ` Vincent Guittot
2021-05-26 10:50 ` Vincent Guittot
2021-05-27 7:50 ` Odin Ugedal
2021-05-27 9:35 ` Vincent Guittot
2021-05-27 9:45 ` Odin Ugedal
2021-05-27 10:49 ` Vincent Guittot
2021-05-27 11:04 ` Odin Ugedal
2021-05-27 12:37 ` Vincent Guittot
2021-05-27 12:37 ` Odin Ugedal
2021-05-27 12:39 ` Odin Ugedal
2021-05-27 12:49 ` Vincent Guittot
2021-05-18 12:52 ` Odin Ugedal [this message]
2021-05-28 14:24 ` [PATCH 2/3] sched/fair: Correctly insert cfs_rq's to list on unthrottle Vincent Guittot
2021-05-28 15:06 ` Odin Ugedal
2021-05-28 15:27 ` Vincent Guittot
2021-05-29 9:33 ` Odin Ugedal
2021-05-31 12:14 ` Vincent Guittot
2021-05-18 12:52 ` [PATCH 3/3] sched/fair: Fix ascii art by relpacing tabs Odin Ugedal
2021-05-27 13:27 ` Vincent Guittot
2021-06-01 14:04 ` [tip: sched/core] " tip-bot2 for Odin Ugedal
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=20210518125202.78658-3-odin@uged.al \
--to=odin@uged.al \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.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;
as well as URLs for NNTP newsgroup(s).