From: <byungchul.park@lge.com>
To: <mingo@kernel.org>, <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, efault@gmx.de, tglx@linutronix.de,
yuyang.du@intel.com, pjt@google.com,
Byungchul Park <byungchul.park@lge.com>
Subject: [PATCH] sched: prevent getting too much vruntime
Date: Wed, 11 Nov 2015 17:50:27 +0900 [thread overview]
Message-ID: <1447231827-1891-1-git-send-email-byungchul.park@lge.com> (raw)
From: Byungchul Park <byungchul.park@lge.com>
Especially in the case below, se->vruntime can be too large and
scheduling cannot work properly.
1. set se->vruntime to "cfs_rq->min_vruntime - sysctl_sched_latency" in
place_entity() when detaching the se from cfs_rq.
2. do a normalization by "se->vruntime -= cfs_rq->min_vruntime".
(see detach_task_cfs_rq().)
3. do "se->vruntime += cfs_rq->min_vruntime", when attaching the se to
a cfs_rq where cfs_rq->min_vruntime < sysctl_sched_latency.
In this case, se->vruntime is suppose to be a negative value, but
actually it is a too large value because vruntime is a unsigned type.
It's wrong. To avoid this situation, this patch takes the case into
account.
Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
kernel/sched/fair.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 077076f..a7cc8e8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -480,6 +480,13 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
#endif
}
+static inline void vruntime_unnormalize(struct cfs_rq *cfs_rq, struct sched_entity *se)
+{
+ se->vruntime += cfs_rq->min_vruntime;
+ if (unlikely((s64)se->vruntime < 0))
+ se->vruntime = 0;
+}
+
/*
* Enqueue an entity into the rb-tree:
*/
@@ -3002,7 +3009,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
* through calling update_curr().
*/
if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING))
- se->vruntime += cfs_rq->min_vruntime;
+ vruntime_unnormalize(cfs_rq, se);
/*
* Update run-time statistics of the 'current'.
@@ -8019,7 +8026,7 @@ static void attach_task_cfs_rq(struct task_struct *p)
attach_entity_load_avg(cfs_rq, se);
if (!vruntime_normalized(p))
- se->vruntime += cfs_rq->min_vruntime;
+ vruntime_unnormalize(cfs_rq, se);
}
static void switched_from_fair(struct rq *rq, struct task_struct *p)
--
1.7.9.5
next reply other threads:[~2015-11-11 8:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-11 8:50 byungchul.park [this message]
2015-11-11 9:26 ` Peter Zijlstra
2015-11-11 9:48 ` Byungchul Park
2015-11-11 11:50 ` Peter Zijlstra
2015-11-12 5:10 ` Byungchul Park
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=1447231827-1891-1-git-send-email-byungchul.park@lge.com \
--to=byungchul.park@lge.com \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=tglx@linutronix.de \
--cc=yuyang.du@intel.com \
/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
all inboxes | Powered by JetHome®