Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp119214ybh; Tue, 17 Mar 2020 19:25:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs7ogjwpzSqIcCKn2u2PpuzLha3amOOygoLsgk9AKLOfU23GX1tF87n4aPIFwYp2xibrIL9 X-Received: by 2002:a9d:4d0d:: with SMTP id n13mr2033721otf.19.1584498304315; Tue, 17 Mar 2020 19:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584498304; cv=none; d=google.com; s=arc-20160816; b=Di4ckoKwIxjr5h8mZAfcbcijE7JMAPC5E+hAe/MTguqAHVBRF3D1pWOdI5yjqYcTT6 zq8PcF0zbK9ZAewkSO+NwOG6ySwGCjrEjB4W/WzUv1nQVv4HCX86ArvUd6e7MkV1ls0+ 2SjVYQzJpONTaODGpn4FcKWmsUkll2R4JTPBpzLAU72U1nCLczFg/04eyhTHh+MpFtaj p4V3Kpx4NkR5zppk2B7c8DsKJ4TtAbSZTiuC/w9KvOrWYI4kLtuuR9AOOO7acLFRQvFb kbtNiyvmyZz3ZLs2tqM4gXBSiszyEWAlpVnsbI1zXIc6Hy7XOCJY93IsuEFrC1bTx9en NLwA== 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=wet377VmYT3I1gGG+dv9nNlzCvByRJtGcKbueR/9dSE=; b=FHYt43a1sj99iXgrRsZlhE0lisYJM6nq4noJyc26cSF1WJmDrHOzgPpuSNWN+OzlBU jipzqTBiFyWbHpoDcBepD07oR4fPtDqavvcPwYTpvWlVVICovtHW0pXbayyqka9sIzKj PfgUE8b+OHSBQcqcz9Rf1GZCsSmyDaa01Ohf+50bESR6yW28wrBo/V4waeFYX19U8vku jwZMRjYmedrhee/7d6BupeXjxRdzvUrb1mlrtrfn9P0FWW4GuquRHrPfs6fGfolneWZU 78lTF772+v5y2l9qDA2FqP5G0se9i7S7870HK3emaLuldwGd3H4URIfuNFK19Z8E3/7t bwig== 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 h9si2631458oti.155.2020.03.17.19.24.52; Tue, 17 Mar 2020 19:25:04 -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 S1727234AbgCRCY2 (ORCPT + 99 others); Tue, 17 Mar 2020 22:24:28 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:55920 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726229AbgCRCY2 (ORCPT ); Tue, 17 Mar 2020 22:24:28 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Tsuy4fR_1584498229; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0Tsuy4fR_1584498229) by smtp.aliyun-inc.com(127.0.0.1); Wed, 18 Mar 2020 10:23:50 +0800 Subject: Re: [PATCH v2] 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" References: <38e8e212-59a1-64b2-b247-b6d0b52d8dc1@linux.alibaba.com> Message-ID: <234bfc8a-c60d-c375-f681-e4230d8c5a20@linux.alibaba.com> Date: Wed, 18 Mar 2020 10:23:49 +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: <38e8e212-59a1-64b2-b247-b6d0b52d8dc1@linux.alibaba.com> 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, Vincent My apologies to missing the case when CONFIG_FAIR_GROUP_SCHED is disabled, I've replaced the MIN_SHARE with 2UL as it was defined, sorry for the trouble... Regards, Michael Wang On 2020/3/18 上午10:15, ηŽ‹θ΄‡ 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 > Reviewed-by: Vincent Guittot > Suggested-by: Peter Zijlstra > Signed-off-by: Michael Wang > --- > v2: > * replace MIN_SHARE with 2UL to cover CONFIG_FAIR_GROUP_SCHED=n case > > 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..9bca26bd60d9 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(2UL, __w >> SCHED_FIXEDPOINT_SHIFT); \ > + __w; \ > +}) > #else > # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT) > # define scale_load(w) (w) >