From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752269AbbKKIuo (ORCPT ); Wed, 11 Nov 2015 03:50:44 -0500 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:49538 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752175AbbKKIul (ORCPT ); Wed, 11 Nov 2015 03:50:41 -0500 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 165.244.98.150 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com From: To: , CC: linux-kernel@vger.kernel.org, efault@gmx.de, tglx@linutronix.de, yuyang.du@intel.com, pjt@google.com, Byungchul Park Subject: [PATCH] sched: prevent getting too much vruntime Date: Wed, 11 Nov 2015 17:50:27 +0900 Message-ID: <1447231827-1891-1-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.7.9.5 X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB06/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2015/11/11 17:50:32, Serialize by Router on LGEKRMHUB06/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2015/11/11 17:50:32, Serialize complete at 2015/11/11 17:50:32 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Byungchul Park 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 --- 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