Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp794866rwb; Thu, 6 Oct 2022 04:46:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PobDnzXQAT0a2AWhL+2PPiOEcqywDNP0xYK4MQeQ8nGvzoBltPUvzFdn4ykof+893kzd/ X-Received: by 2002:a17:90b:3ec6:b0:20a:eb6b:c832 with SMTP id rm6-20020a17090b3ec600b0020aeb6bc832mr8740339pjb.22.1665056783610; Thu, 06 Oct 2022 04:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665056783; cv=none; d=google.com; s=arc-20160816; b=XNW8wWxtq6zVI06nckZrvyF6TrvH5msqJaMWvgC3mcHaqvxHQSgEvu1EXdgRCE91+b kW+CzJLWNzb5saIFaLZ7NsOq5wbz664lzgd8jq1xxdOc/c+QqH7I04A1J2lCg+6+z7uc BM0kfffZP+T8FYg1GbJZB2AXugZmIdN8gS6t0d6GeLaHdTtCgMZNCdZDQf/QdT42tZyh N6B/a7cTbv4S+lKB29b9/qu3+cM7nSQGb0nPcvde8ttyzzuxHndwmglmO6iWsA6p4i4o PAbvwC2Tk7T7zASY30+fUW57B2e8dBsJl4gXZiQpN2VHi+qJJE1xYM7XCKWjkC724MKM KljA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=TVtFReAxelJqlT3Qo+5ekEJNyu/6i3BPBo/085MjFh0=; b=Sj+rZFqUQ+Wat7wzNeYmmYwpTwRHolbe2CnTnrUNKC07BwTyxnltMaAnzMY+aTPyKg /y0udPzceOV5+ODFhnExxe6Av19f+gTivfQkAOHdc6pt607ULR1InrFsyJhpmxKnEBRV NDjt34Psn8M2wCQclGs4BxVK1+QYT41Fu34q4NVj/KqepETkXy1w+1uEdLnuq7q/kbfJ UeZ5iyNGrx55yuTdxlF5JTLdTvQRFt54lLzJHbQ9RM5K+gVyxZWG0Kgl6csJH54z6a9G w10ge2Az7ZpTH00E0eKL/EIEqz7IOGSzI9fkkgXL1Q8CmQNB50o+sUY6aR+DGucPQ/iU gogw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az1-20020a17090b028100b001fac102fdeesi4482984pjb.95.2022.10.06.04.46.12; Thu, 06 Oct 2022 04:46:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbiJFLfH (ORCPT + 99 others); Thu, 6 Oct 2022 07:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiJFLfD (ORCPT ); Thu, 6 Oct 2022 07:35:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 424AB2182E for ; Thu, 6 Oct 2022 04:35:02 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 145501042; Thu, 6 Oct 2022 04:35:08 -0700 (PDT) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C26163F73B; Thu, 6 Oct 2022 04:34:59 -0700 (PDT) Message-ID: <5c65740d-6f10-f8c5-94a9-a1af631f0c07@arm.com> Date: Thu, 6 Oct 2022 13:34:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] sched/fair: limit sched slice duration Content-Language: en-US To: Vincent Guittot , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org Cc: zhangqiao22@huawei.com References: <20221003122111.611-1-vincent.guittot@linaro.org> From: Dietmar Eggemann In-Reply-To: <20221003122111.611-1-vincent.guittot@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/10/2022 14:21, Vincent Guittot wrote: > In presence of a lot of small weight tasks like sched_idle tasks, normal > or high weight tasks can see their ideal runtime (sched_slice) to increase > to hundreds ms whereas it normally stays below sysctl_sched_latency. > > 2 normal tasks running on a CPU will have a max sched_slice of 12ms > (half of the sched_period). This means that they will make progress > every sysctl_sched_latency period. > > If we now add 1000 idle tasks on the CPU, the sched_period becomes > 3006 ms and the ideal runtime of the normal tasks becomes 609 ms. > It will even become 1500ms if the idle tasks belongs to an idle cgroup. > This means that the scheduler will look for picking another waiting task > after 609ms running time (1500ms respectively). The idle tasks change > significantly the way the 2 normal tasks interleave their running time > slot whereas they should have a small impact. > > Such long sched_slice can delay significantly the release of resources > as the tasks can wait hundreds of ms before the next running slot just > because of idle tasks queued on the rq. > > Cap the ideal_runtime to sysctl_sched_latency to make sure that tasks will > regularly make progress and will not be significantly impacted by > idle/background tasks queued on the rq. > > Signed-off-by: Vincent Guittot > --- > > Change since v2: > - Cap ideal_runtime from the beg as suggested by Peter > > kernel/sched/fair.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 5ffec4370602..c309d57efb2c 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -4584,7 +4584,13 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) > struct sched_entity *se; > s64 delta; > > - ideal_runtime = sched_slice(cfs_rq, curr); > + /* > + * When many tasks blow up the sched_period; it is possible that > + * sched_slice() reports unusually large results (when many tasks are > + * very light for example). Therefore impose a maximum. > + */ > + ideal_runtime = min_t(u64, sched_slice(cfs_rq, curr), sysctl_sched_latency); > + > delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime; > if (delta_exec > ideal_runtime) { > resched_curr(rq_of(cfs_rq)); Tested on 6 CPU system (sysctl_sched_latency=18ms, sysctl_sched_min_granularity=2.25ms) I start to see `slice > period` when I run: (a) > ~50 idle tasks in '/' for an arbitrary nice=0 task (b) > ~50 nice=0 tasks in '/A' w/ cpu.shares = max for se of '/A' Essentially in moments in which cfs_rq->nr_running > sched_nr_latency and se_weight is relatively high compared to cfs_rq_weight. Tested-By: Dietmar Eggemann