Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3926626pxj; Mon, 21 Jun 2021 09:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoeRI4aJSBCksJ3bLJduAngqPmizGn7FtmZ5KRbpYGma2eTlfy6r2VNLmexfVO6K3kWtr+ X-Received: by 2002:a05:6638:2707:: with SMTP id m7mr18471168jav.66.1624293112516; Mon, 21 Jun 2021 09:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293112; cv=none; d=google.com; s=arc-20160816; b=w4zPq02Nx0HJhCwWOAmOxwvI9jTwEcOkuuCmou8DSfAKV6pwoFcqic96iQtNbCP2L6 thH1zeh3sCcZYJ1sR5bJyfPHloSnmMmWDGcFt7oN6+HQJUtZxRcE0OUvWkb4iQJg+SmQ pLk9Ss4uChnt7nPRwZYsl1mkxQ97Uq7Q6kWoeXlFnWkxJMRE3s4ix9LB5B3007B1gGy0 Ah8srbD4od1s7HIyiaqqkld8QVCbIeEC3i2PIdn3nclOFJnuIr8cKfjavUy7hP/2dexI n+Wtf448mgSnYMODz8Pi6nVtCWhZlDTWVwMJPZjRDtkJPLkE49auDaGGkJksTVYYIsci NBFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9hUrRG05wEBEg3u2PwA9lKHGLgOKQ9ZUP8qM0RH3u6Q=; b=SLctrcvbJEKJxThtYKCRCF44irsx8ue5JXoJgJNWVsR7wJgEBga1nV0r8eJVXCTjbh fSAI09r+bBCymIcUmWkH+oFR4aON5DtRO4fTyeUC/T7StqpX5vYdPHO1I/WZ5dvuGuYI R/vHLUF54snxTjS9f99K7Z4RfabOHlTtfh1hqoNzKT3PrRXCG0XsT5f+Inc7gBgN1ISy JHphZEQyYMlIDIc+ou0xf55DMDjpRHN4lpImy4TQcr4YhYJ3tHj22KOGjXijRcG1pM4T 4BNTxPi2UrZCI7eivgUB4GdCUE3+eskWem7QiSqbs79eqVTaZszz6hofLNMGInYIQKC1 qN9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h9BkTaCZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si12484660ilj.66.2021.06.21.09.31.39; Mon, 21 Jun 2021 09:31:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h9BkTaCZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232273AbhFUQdR (ORCPT + 99 others); Mon, 21 Jun 2021 12:33:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:48302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbhFUQ3z (ORCPT ); Mon, 21 Jun 2021 12:29:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 57204613BE; Mon, 21 Jun 2021 16:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292692; bh=f7SmqwtvVeCF2VQ3kASw7xUwr+LcfPjSTITIGlBxQB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h9BkTaCZL1+aNhNp0KXrXy0pS3GQS9FltUe4wRV46HlI9Hs/ySSboFELnK0odkLB0 M1IVfcVqoW2otREJALUvrzmwHnaSlZzkxs081hnDSApkP7J24t5Nn9XBfyoXq1tWw5 j5g3v8oRezNd7qO1bnJtjfX6K2P7T6vya8+F5vGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Odin Ugedal , "Peter Zijlstra (Intel)" , Vincent Guittot , Sasha Levin Subject: [PATCH 5.10 095/146] sched/fair: Correctly insert cfs_rqs to list on unthrottle Date: Mon, 21 Jun 2021 18:15:25 +0200 Message-Id: <20210621154917.185551238@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Odin Ugedal [ Upstream commit a7b359fc6a37faaf472125867c8dc5a068c90982 ] Fix 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 happens 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. Instead, we insert all cfs_rq's that contain one or more enqueued entities, or it its load is not completely decayed. Can often lead to situations 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()") [vingo: !SMP build fix] Signed-off-by: Odin Ugedal Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Link: https://lore.kernel.org/r/20210612112815.61678-1-odin@uged.al Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d6e1c90de570..1cbb7f80db31 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3300,6 +3300,24 @@ static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq, int flags) #ifdef CONFIG_SMP #ifdef CONFIG_FAIR_GROUP_SCHED + +static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq) +{ + if (cfs_rq->load.weight) + return false; + + if (cfs_rq->avg.load_sum) + return false; + + if (cfs_rq->avg.util_sum) + return false; + + if (cfs_rq->avg.runnable_sum) + return false; + + return true; +} + /** * update_tg_load_avg - update the tg's load avg * @cfs_rq: the cfs_rq whose avg changed @@ -4093,6 +4111,11 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) #else /* CONFIG_SMP */ +static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq) +{ + return true; +} + #define UPDATE_TG 0x0 #define SKIP_AGE_LOAD 0x0 #define DO_ATTACH 0x0 @@ -4751,8 +4774,8 @@ static int tg_unthrottle_up(struct task_group *tg, void *data) 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) + /* Add cfs_rq with load or one or more already running entities to the list */ + if (!cfs_rq_is_decayed(cfs_rq) || cfs_rq->nr_running) list_add_leaf_cfs_rq(cfs_rq); } @@ -7927,23 +7950,6 @@ static bool __update_blocked_others(struct rq *rq, bool *done) #ifdef CONFIG_FAIR_GROUP_SCHED -static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq) -{ - if (cfs_rq->load.weight) - return false; - - if (cfs_rq->avg.load_sum) - return false; - - if (cfs_rq->avg.util_sum) - return false; - - if (cfs_rq->avg.runnable_sum) - return false; - - return true; -} - static bool __update_blocked_fair(struct rq *rq, bool *done) { struct cfs_rq *cfs_rq, *pos; -- 2.30.2