Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2277002ybh; Sun, 15 Mar 2020 23:34:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vudBIeOivfUZkrt2lIF25FXF7eSqJBuCR2qx893AyWKT6sH/gKmydNWZE1UAAFaXpx95MOD X-Received: by 2002:aca:3f09:: with SMTP id m9mr15421462oia.55.1584340494247; Sun, 15 Mar 2020 23:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584340494; cv=none; d=google.com; s=arc-20160816; b=l7AI5Ooixax6qZgGz4QtL0WaqkjdbKkRkxuakMlIiAsKby1jGhob7173CBm4TUXs20 N0m/AtUTXe2oq1WEapV32v7v0b6n3cc32j/iiaJDZtx3/frRvkhum6UeNmzUzB+BTEnD p5cOBm9mzhxaO10KyBF/hTWj5SgqBQMe5ShejQSiaWBeXFVwvyVCCEVd7xuji/X1qN+1 qA20XDbeQC8URuNzAgSTnIgAQucsOl60iVOzqQWzcWRJDQPxia0Ws6x3n2wZHz+sZwlj y4YucFbqlxuWX9OJ5JPifOkzDqrlfrf7Cks84Yudwqw2oa/SXnndOxdL+QbpzG/wxOc5 4kCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:to:from:subject; bh=qX6Udm3NAW/5c1GFuXfyy1U9dhyBNXs+cD0+iPr9pPI=; b=Vm8C4PVkSRRCRWSUiz3LXGqKIhvK1dCmb+i1nKmU4/O/bUB5nD+HC8rLjHJ8wkMM/T 7S3htFKrAeiNJr3bmFLL5qrY48R29TaLxzwiZBxIfO6YlFifI3B0aES04gziWaQjNBiH QiuUD/P/84p4cxfW/Oa2pf5RsawFE4zM8QtiDj3ua4Yi3icTP+YyoUB7Xvg6wquU8D2d 4AEsQn8Wd1k5ehFvI67BLwjPAvwnsuz+1TaCNVCfAjOM1YVZ/XCQfVDHXgazYZlEss6L 3L2Hg9VYXV60cv6ojw5omctV0qJJP+nsxk53Nc/bavEN+HZljr4Ol+Ibh2qe3vrqGbDQ F8HQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g35si9690137otg.32.2020.03.15.23.34.38; Sun, 15 Mar 2020 23:34:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729668AbgCPGdj (ORCPT + 99 others); Mon, 16 Mar 2020 02:33:39 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:32883 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729407AbgCPGdj (ORCPT ); Mon, 16 Mar 2020 02:33:39 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R981e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TshR7Hp_1584340410; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0TshR7Hp_1584340410) by smtp.aliyun-inc.com(127.0.0.1); Mon, 16 Mar 2020 14:33:31 +0800 Subject: Re: [PATCH] sched: avoid scale real weight down to zero From: =?UTF-8?B?546L6LSH?= To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , "open list:SCHEDULER" , Vincent Guittot References: Message-ID: Date: Mon, 16 Mar 2020 14:33:30 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Peter I've done more complicated testing with share 2 and every thing looks fine. Should we apply this? or is there any concern? Regards, Michael Wang On 2020/3/5 上午10:57, ηŽ‹θ΄‡ wrote: > 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. > > Cc: Ben Segall > Cc: Vincent Guittot > Suggested-by: Peter Zijlstra > Signed-off-by: Michael Wang > --- > 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 2a0caf394dd4..75c283f22256 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -118,7 +118,13 @@ extern long calc_load_fold_active(struct rq *this_rq, long adjust); > #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(MIN_SHARES, __w >> SCHED_FIXEDPOINT_SHIFT); \ > + __w; \ > +}) > #else > # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT) > # define scale_load(w) (w) >