From patchwork Fri Jan 13 13:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 43312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp276268wrt; Fri, 13 Jan 2023 05:44:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvwd1LvSLMAKyAoSbLOlUjzb0z/kvkkxxslfvPmr6NBQYFMgmGowpFQaG5IY1omDeMyd4V6 X-Received: by 2002:a17:906:9bf4:b0:84d:141b:7e4b with SMTP id de52-20020a1709069bf400b0084d141b7e4bmr24027718ejc.76.1673617492406; Fri, 13 Jan 2023 05:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673617492; cv=none; d=google.com; s=arc-20160816; b=AzzX6e+wX3JBCF+2amvytkIVka/ZB6cWcJCGitDzr1S8DuhILvuU5tYia68M+eFrcX Lfk0iENNcyhSYaw9q8z/dh1HE4Lvx1XCvuAc75Yy4zHxwUo+JFmcMktCf5v6nhq+Q7Xv NUd4DElLHAjQ/suR+YSaEQybT0hfhx6JY4qfRW/rQT/TQrKDw8meVnhdECTaqf1zFjPg TUP+jooiOkLBu6VuwI5BrJ5NnJTijy+gHtvzKie4AOvOal+gHiCb9nO4uokjg6UEtmGE jrVAcZ+0t5XAG7GerI9/kdeDo5EdkyygY43uzz7vaFj2miGGhPdKeAAkcoYIRO9ADhfV xZDQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=no/No00/dUadTgkiqCjE1V7uzOtAh13kNBL63Zyd1c0=; b=qtzL7wiflVP7CKMs+dhlzOILpIaMcGTFkzpEJX2h830qNxvtoCxHsuJEqmH1EWNYFu ZU67G0/cKXPWUIvZUUP/+k5o4x3uC1iFnwZlilx/rNM/P3roU4liYYhlaBm9+x9LXhM2 H8yh7LOnqWdyOTzYmoWdSegAhgIaK0xoC0G3ZA7rPXU0y46PADj9LyqgbEf5RwTBMduh n+dIcbi38uqk6Daw9dxFcn1P7STtoLX1mmGk0sw8VbFc+RtI8VsezeEqHEQ9l2UYeJ3/ G7ZfmAMmegWjfXDYYnBj31vTyRkZ1Vyu3zrRE5CsGoJA3J40gGnxgmFrYg8X8ZRkhgli sm/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DhEzzOKd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rn5-20020a170906d92500b007bed39516b0si15979315ejb.921.2023.01.13.05.44.26; Fri, 13 Jan 2023 05:44:52 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=DhEzzOKd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241765AbjAMNnZ (ORCPT + 99 others); Fri, 13 Jan 2023 08:43:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241754AbjAMNmO (ORCPT ); Fri, 13 Jan 2023 08:42:14 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1029CB1E9 for ; Fri, 13 Jan 2023 05:36:18 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id g19-20020a05600c4ed300b003d9eb1dbc0aso14404584wmq.3 for ; Fri, 13 Jan 2023 05:36:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=no/No00/dUadTgkiqCjE1V7uzOtAh13kNBL63Zyd1c0=; b=DhEzzOKdo9LfA6gSAquygvXRjkhj9nQ922NqGep8Xbfc8XNBzPihRyc9TdA0EWhTie F76eyr/wtmgYKZ6XjdCJf5vvOthtGWZKWPx/mA7MSTBA3JjYexWThLDxZ7sJp2M8ZALS rISoTp8igr8je9DOIUgZUSqsFHiOSpniyKtpQOQJG6rKiCpAEqbYIeN/zN2hmwnvtbfE Sgr66vV7HeFWnbtilMGnvhWWfTFyjlgVeb0o1EKYUUADymnfI0u5ZT6r0GGmcFqU5EtM DaOcs1aj1uIzelutM4DzyysOUfAMQ1AXioetEYCdGXYfngQZaRiJapNXqR7BOB9IgS37 FAcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=no/No00/dUadTgkiqCjE1V7uzOtAh13kNBL63Zyd1c0=; b=mx4GtYTBEzrXl68DX+rYA+vAU0Aem8mKoxAjkZlsrYUJ8o9d2AcA+4+23wS3pMeZgZ 23GuYp3sb9mnTxlfy+fGQqvqDhAp2dawuqYgfOI5fkyyr6D6DlkA1Y6GE1sl4ZphtSzG R8ynfihXWdFK0KvZVab9PAza38k/U1qt6ajLE+a+9NfteUkZNI6nksLIJff0eHD7JzFv yvYsPHVX+Zpxr2j+oWRhsgcoYfObBI/H/WoNNxdnd1uvkUpe8IwNxlcKZY3kGpfaR9D7 aKTonXVKOssupgvGnn/Fd6tww/ua0abjGEEWlBmaW0Fw7kbHZQcjpBK+r/IHTMuuCpA7 y8PQ== X-Gm-Message-State: AFqh2kog9lA68Z6vfi0eXKZhbHiV9sKLxArSdEBfLSo693Ygm+tvnSAp YEdWXG+JqrbPyPp0BhzWK9PNiA== X-Received: by 2002:a7b:c851:0:b0:3d9:f067:1c32 with SMTP id c17-20020a7bc851000000b003d9f0671c32mr13863320wml.29.1673616976552; Fri, 13 Jan 2023 05:36:16 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:1563:65bf:c344:661e]) by smtp.gmail.com with ESMTPSA id n23-20020a05600c3b9700b003cf71b1f66csm28900643wms.0.2023.01.13.05.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 05:36:15 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.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, Vincent Guittot Subject: [PATCH v4] sched/fair: limit sched slice duration Date: Fri, 13 Jan 2023 14:36:13 +0100 Message-Id: <20230113133613.257342-1-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754915135502513274?= X-GMAIL-MSGID: =?utf-8?q?1754915135502513274?= 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 Tested-By: Dietmar Eggemann Acked-by: Mel Gorman --- Change since v3: - Rebased - Added Tested tag 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 e9d906a9bba9..d4db72f8f84e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4896,7 +4896,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));