From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 867B8C2D0EC for ; Fri, 10 Apr 2020 03:53:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DB18206C0 for ; Fri, 10 Apr 2020 03:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586490798; bh=b4IWSodilP/n6yol7fL8g/RGKl2d0kiQs1kpArRe4r0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IKpZrrFAqm4yUeJUX0MHRPiOiOfLP49vaIXtp1Jp7J3048ngoQiALqllS3roBrpPz 4uZgY/9rslMq8yOWxyGKvFnArWuB0EGZ9DAHL5sM9fXeo70I9q9Plp29sCOGfU7DLZ DG9VqM57kubUhIgQYzQWAdfTW/2SFv6A59vNFOVs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727162AbgDJDxN (ORCPT ); Thu, 9 Apr 2020 23:53:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:35752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729008AbgDJDux (ORCPT ); Thu, 9 Apr 2020 23:50:53 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A11ED21775; Fri, 10 Apr 2020 03:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586490653; bh=b4IWSodilP/n6yol7fL8g/RGKl2d0kiQs1kpArRe4r0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wrd005U4bEXohk7SBhiyCq6GI1e9SVRIQgmKRro1VArngCUITvD30CfvVu5daniQ+ K+lKvkpRxnjMnBv0M6eQGfda7OjaqtMDfkIOWbGDu6YFHK0XLEqO/vZUnwWVf2egqs w0kU+wnssD+QtsCj9217Kb8eGs3wR6iKhujuBAz8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Wang , Peter Zijlstra , Vincent Guittot , Sasha Levin Subject: [PATCH AUTOSEL 4.14 07/22] sched: Avoid scale real weight down to zero Date: Thu, 9 Apr 2020 23:50:29 -0400 Message-Id: <20200410035044.9698-7-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200410035044.9698-1-sashal@kernel.org> References: <20200410035044.9698-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Michael Wang [ Upstream commit 26cf52229efc87e2effa9d788f9b33c40fb3358a ] During our testing, we found a case that shares no longer working correctly, the cgroup topology is like: /sys/fs/cgroup/cpu/A (shares=102400) /sys/fs/cgroup/cpu/A/B (shares=2) /sys/fs/cgroup/cpu/A/B/C (shares=1024) /sys/fs/cgroup/cpu/D (shares=1024) /sys/fs/cgroup/cpu/D/E (shares=1024) /sys/fs/cgroup/cpu/D/E/F (shares=1024) The same benchmark is running in group C & F, no other tasks are running, the benchmark is capable to consumed all the CPUs. We suppose the group C will win more CPU resources since it could enjoy all the shares of group A, but it's F who wins much more. The reason is because we have group B with shares as 2, since A->cfs_rq.load.weight == B->se.load.weight == B->shares/nr_cpus, so A->cfs_rq.load.weight become very small. And in calc_group_shares() we calculate shares as: load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg); shares = (tg_shares * load) / tg_weight; Since the 'cfs_rq->load.weight' is too small, the load become 0 after scale down, although 'tg_shares' is 102400, shares of the se which stand for group A on root cfs_rq become 2. While the se of D on root cfs_rq is far more bigger than 2, so it wins the battle. Thus when scale_load_down() scale real weight down to 0, it's no longer telling the real story, the caller will have the wrong information and the calculation will be buggy. This patch add check in scale_load_down(), so the real weight will be >= MIN_SHARES after scale, after applied the group C wins as expected. Suggested-by: Peter Zijlstra Signed-off-by: Michael Wang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Link: https://lkml.kernel.org/r/38e8e212-59a1-64b2-b247-b6d0b52d8dc1@linux.alibaba.com Signed-off-by: Sasha Levin --- kernel/sched/sched.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 268f560ec9986..391d73a12ad72 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -89,7 +89,13 @@ static inline void cpu_load_update_active(struct rq *this_rq) { } #ifdef CONFIG_64BIT # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT + SCHED_FIXEDPOINT_SHIFT) # define scale_load(w) ((w) << SCHED_FIXEDPOINT_SHIFT) -# define scale_load_down(w) ((w) >> SCHED_FIXEDPOINT_SHIFT) +# define scale_load_down(w) \ +({ \ + unsigned long __w = (w); \ + if (__w) \ + __w = max(2UL, __w >> SCHED_FIXEDPOINT_SHIFT); \ + __w; \ +}) #else # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT) # define scale_load(w) (w) -- 2.20.1