From: Rik van Riel <riel@surriel.com>
To: linux-kernel@vger.kernel.org
Cc: kernel-team@fb.com, pjt@google.com, dietmar.eggemann@arm.com,
peterz@infradead.org, mingo@redhat.com, morten.rasmussen@arm.com,
tglx@linutronix.de, mgorman@techsingularity.net,
vincent.guittot@linaro.org, Rik van Riel <riel@surriel.com>,
Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH 12/14] sched,fair: track cfs_rq->max_h_load for more legitimate h_weight
Date: Mon, 22 Jul 2019 13:33:46 -0400 [thread overview]
Message-ID: <20190722173348.9241-13-riel@surriel.com> (raw)
In-Reply-To: <20190722173348.9241-1-riel@surriel.com>
The cfs_rq->h_load decays to zero quite rapidly, which can easily lead
to tasks getting enqueued with an h_weight and h_load of zero, confusing
the load balancer, the preemption code, and other parts of the kernel.
Add a slow moving cfs_rq->max_h_load, with a half life of just over a minute,
to help tasks get enqueued with more legitimate h_weight values.
Suggested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Rik van Riel <riel@surriel.com>
---
kernel/sched/debug.c | 2 ++
kernel/sched/fair.c | 6 +++++-
kernel/sched/pelt.c | 16 ++++++++++++++++
kernel/sched/pelt.h | 1 +
kernel/sched/sched.h | 2 ++
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 6e7c8ff210a8..88ed6d4429e6 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -553,6 +553,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
atomic_long_read(&cfs_rq->tg->load_avg));
SEQ_printf(m, " .%-30s: %lu\n", "h_load",
cfs_rq->h_load);
+ SEQ_printf(m, " .%-30s: %lu\n", "max_h_load",
+ cfs_rq->max_h_load);
#endif
#endif
#ifdef CONFIG_CFS_BANDWIDTH
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 1d5145cb6096..224cd9b20887 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7636,6 +7636,8 @@ static void update_cfs_rq_h_load(struct cfs_rq *cfs_rq)
if (!se) {
cfs_rq->h_load = cfs_rq_load_avg(cfs_rq);
+ slow_decay(&cfs_rq->max_h_load, &cfs_rq->last_max_h_decay);
+ cfs_rq->max_h_load = max(cfs_rq->max_h_load, cfs_rq->h_load);
cfs_rq->last_h_load_update = now;
}
@@ -7645,6 +7647,8 @@ static void update_cfs_rq_h_load(struct cfs_rq *cfs_rq)
cfs_rq_load_avg(cfs_rq) + 1);
cfs_rq = group_cfs_rq(se);
cfs_rq->h_load = load;
+ slow_decay(&cfs_rq->max_h_load, &cfs_rq->last_max_h_decay);
+ cfs_rq->max_h_load = max(load, cfs_rq->max_h_load);
cfs_rq->last_h_load_update = now;
}
}
@@ -7660,7 +7664,7 @@ static unsigned long task_se_h_weight(struct sched_entity *se)
update_cfs_rq_h_load(cfs_rq);
/* Reduce the load.weight by the h_load of the group the task is in. */
- return (cfs_rq->h_load * se->load.weight) >> SCHED_FIXEDPOINT_SHIFT;
+ return (cfs_rq->max_h_load * se->load.weight) >> SCHED_FIXEDPOINT_SHIFT;
}
static unsigned long task_se_h_load(struct sched_entity *se)
diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
index 2c901e0f9fbd..2173db8c6209 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -58,6 +58,22 @@ static u64 decay_load(u64 val, u64 n)
return val;
}
+/*
+ * Like above, with a period of close to a minute for very slow decay.
+ * At 2 seconds per period, LOAD_AVG_PERIOD periods is just over a minute.
+ */
+void slow_decay(unsigned long *load, unsigned long *time)
+{
+ unsigned long periods = (jiffies - *time) / 2;
+
+ if (!periods)
+ return;
+
+ *time += periods * 2;
+
+ *load = decay_load(*load, periods);
+}
+
static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
{
u32 c1, c2, c3 = d3; /* y^0 == 1 */
diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
index 1152c4ebf314..f16042e2aa06 100644
--- a/kernel/sched/pelt.h
+++ b/kernel/sched/pelt.h
@@ -6,6 +6,7 @@ int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se
int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
+void slow_decay(unsigned long *load, unsigned long *time);
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
int update_irq_load_avg(struct rq *rq, u64 running);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index b05fd87cf8b5..b627ca594f97 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -540,6 +540,8 @@ struct cfs_rq {
* this group.
*/
unsigned long h_load;
+ unsigned long max_h_load;
+ unsigned long last_max_h_decay;
u64 last_h_load_update;
struct sched_entity *h_load_next;
#endif /* CONFIG_FAIR_GROUP_SCHED */
--
2.20.1
next prev parent reply other threads:[~2019-07-22 17:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 17:33 [PATCH RFC v3 0/14] sched,fair: flatten CPU controller runqueues Rik van Riel
2019-07-22 17:33 ` [PATCH 01/14] sched: introduce task_se_h_load helper Rik van Riel
2019-08-12 17:40 ` Dietmar Eggemann
2019-07-22 17:33 ` [PATCH 02/14] sched: change /proc/sched_debug fields Rik van Riel
2019-07-22 17:33 ` [PATCH 03/14] sched,fair: redefine runnable_load_avg as the sum of task_h_load Rik van Riel
2019-07-29 20:05 ` Peter Zijlstra
2019-07-29 21:13 ` Rik van Riel
2019-07-29 20:11 ` Peter Zijlstra
2019-07-29 20:26 ` Peter Zijlstra
2019-07-22 17:33 ` [PATCH 04/14] sched,fair: move runnable_load_avg to cfs_rq Rik van Riel
2019-07-30 8:55 ` Peter Zijlstra
2019-07-22 17:33 ` [PATCH 06/14] sched,cfs: use explicit cfs_rq of parent se helper Rik van Riel
2019-07-22 17:33 ` [PATCH 07/14] sched,cfs: fix zero length timeslice calculation Rik van Riel
2019-07-22 17:33 ` [PATCH 08/14] sched,fair: simplify timeslice length code Rik van Riel
2019-07-22 17:33 ` [PATCH 09/14] sched,fair: refactor enqueue/dequeue_entity Rik van Riel
2019-07-30 9:36 ` Peter Zijlstra
2019-07-30 12:58 ` Rik van Riel
2019-07-31 9:35 ` Peter Zijlstra
2019-07-31 15:03 ` Rik van Riel
2019-07-31 15:30 ` Peter Zijlstra
2019-07-22 17:33 ` [PATCH 10/14] sched,fair: add helper functions for flattened runqueue Rik van Riel
2019-07-22 17:33 ` [PATCH 11/14] sched,fair: flatten hierarchical runqueues Rik van Riel
2019-07-22 17:33 ` Rik van Riel [this message]
2019-07-22 17:33 ` [PATCH 13/14] sched,fair: flatten update_curr functionality Rik van Riel
2019-07-22 17:33 ` [PATCH 14/14] sched,fair: propagate sum_exec_runtime up the hierarchy Rik van Riel
2019-07-30 16:29 ` [PATCH RFC v3 0/14] sched,fair: flatten CPU controller runqueues Peter Zijlstra
2019-07-30 18:27 ` Rik van Riel
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=20190722173348.9241-13-riel@surriel.com \
--to=riel@surriel.com \
--cc=dietmar.eggemann@arm.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=tglx@linutronix.de \
--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