Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp729652rdb; Thu, 19 Oct 2023 18:40:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiI/BRlz8M0WnS1Ph105Qi0glt4NPWNnruReWr99m3eL4VdNrZqcjn+nwfIf+w8mADz1yj X-Received: by 2002:a17:902:d483:b0:1c8:90bf:4234 with SMTP id c3-20020a170902d48300b001c890bf4234mr724231plg.61.1697766057260; Thu, 19 Oct 2023 18:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697766057; cv=none; d=google.com; s=arc-20160816; b=qv6mmXAn6M7Jq+yWE4hRkKNEs/nP8w2/7K+gIxHVbt9mLSI86wPdZKVHHVTAD0oKJH Wnjrpq5HpqRFR0UX4s8ZiKgYnwDliPsuPX5k5ow3q37PPRbUgsQtDabEqngOi86KSraI QzMHgtXI7P6kMCovImXrDMVqvp7BkKOaXhuXDtXQz9+B9LpMBLHGibe0Et8HwUJUrlyV 4eCxQ6pyjeJ1IbI8mMgeo1pCqwWckxS0QwN4AMkaWwpMZqXRqmkFrzVn6Z20lqiLrvh5 mdAOHw1EBC7uA3e88CaP13juvxfhjw4e8DlljwbT9tosoGJHyh7TcLI5u06bgK/a9DnV lGcw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m0pwSa2GbXJihOZrNu7aMcnrt6aomdhOt1W1hRoVbr8=; fh=eUeDaXEoz+BmTGwje8HoWK/5Htsj786g1xe5Bw+HP1U=; b=xmvDgFrtBbfPLwriztnnnQumEd5Qs7lxbCAMUnWuqsuth/JyMudzM2m3NTHwik0HLO Mgsa8cO8b/Rnt+UuEH9umyPIhOFSWBPkXcp+PqT83PenkDXt+ZiDeVoEN7I8VRfHqq+p R8YYQTMn170H21hrvVpl7wQWSaQhdOeh7tHO65+W4swn8QwxBCsekrBmMxkqNNhCSBz1 +meQDXY2dDtMKw7ue7RKJOoNwHmiBb1R89yshrhZvmbUKARV99cuHFD/F+eJ9zNqK2Rd jU4pYLuHKdp8gEp7MewrtISln407SA21jAaWyRQowAYXkgzo64eCNr1E6tJduDzm8qxC MN4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=N44iB+Am; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x8-20020a170902ec8800b001ca176b7974si765715plg.103.2023.10.19.18.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 18:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=N44iB+Am; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3C67C8288C8E; Thu, 19 Oct 2023 18:40:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346830AbjJTBkv (ORCPT + 99 others); Thu, 19 Oct 2023 21:40:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346805AbjJTBkq (ORCPT ); Thu, 19 Oct 2023 21:40:46 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB347124 for ; Thu, 19 Oct 2023 18:40:44 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-3574cde48b4so1066595ab.1 for ; Thu, 19 Oct 2023 18:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1697766044; x=1698370844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m0pwSa2GbXJihOZrNu7aMcnrt6aomdhOt1W1hRoVbr8=; b=N44iB+AmDtzIIgLBjpm32TTYi98/zApjmjJ1fnQPghi2nhfvDY8fJqkFIMsg2+ukGu pg/OlKXxJlIg9T9ys70LiFam6r7U+LUiS/9irMfmvHS9XRsKaIQWY2ysuMCgGzSJ/VGv h+TG+s8yfyMKNkXAC/6cCnfY9gGFxdiD1vUa8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697766044; x=1698370844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m0pwSa2GbXJihOZrNu7aMcnrt6aomdhOt1W1hRoVbr8=; b=ONOFXLSR4mtBa0sYKumbyqiEIDNAT3IilqL0Rv/qNVjuwCGHTBTt9N3gncQFGTD1a4 XSfAYRbXzTaZNBoyiRgZ9ISA7xGQCmTivuLUX1Bw9BEuVrO6mPpKjvQu82egCYAN7Q9i AgXQnyX7G8NcpaYjDWJVYK0TrisqSYUjL0mLJVVXBFSxXqtLNO0W6yT9U2mlJauIskgx t+F9EKOLPskxCYBTbxajjATHIonro2vc6IvvQW3vwV3x3ULjcVA72EkWFrOh6uN24v2v m2kh814ulLbQASF8GUaP8CMbRulzvPCLVdjMi/2DzcYaJS2yKhtTXA2jY99nTSesxJG9 iBOw== X-Gm-Message-State: AOJu0Yzc8D8ODGlX9YANZMxZMbtI4Uvp1KEX4nKKatbDG0wRWvjyGz1b YoHa8lWjUAb+JbEYmN+LOclMNqgTFt8yiomefAPFnA== X-Received: by 2002:a05:6e02:214b:b0:34d:e998:fb4f with SMTP id d11-20020a056e02214b00b0034de998fb4fmr850150ilv.10.1697766043833; Thu, 19 Oct 2023 18:40:43 -0700 (PDT) Received: from joelboxx5.c.googlers.com.com (20.10.132.34.bc.googleusercontent.com. [34.132.10.20]) by smtp.gmail.com with ESMTPSA id h9-20020a056e020d4900b00350f5584876sm270394ilj.27.2023.10.19.18.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 18:40:43 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider Cc: "Vineeth Pillai (Google)" , Suleiman Souhlal , Frederic Weisbecker , "Paul E . McKenney" , Joel Fernandes Subject: [PATCH 3/3] sched: Update ->next_balance correctly during newidle balance Date: Fri, 20 Oct 2023 01:40:28 +0000 Message-ID: <20231020014031.919742-3-joel@joelfernandes.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231020014031.919742-1-joel@joelfernandes.org> References: <20231020014031.919742-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 19 Oct 2023 18:40:56 -0700 (PDT) From: "Vineeth Pillai (Google)" When newidle balancing triggers, we see that it constantly clobbers rq->next_balance even when there is no newidle balance happening due to the cost estimates. Due to this, we see that periodic load balance (rebalance_domains) may trigger way more often when the CPU is going in and out of idle at a high rate but is no really idle. Repeatedly triggering load balance there is a bad idea as it is a heavy operation. It also causes increases in softirq. Another issue is ->last_balance is not updated after newidle balance causing mistakes in the ->next_balance calculations. Fix by updating last_balance when a newidle load balance actually happens and then updating next_balance. This is also how it is done in other load balance paths. Testing shows a significant drop in softirqs when running: cyclictest -i 100 -d 100 --latency=1000 -D 5 -t -m -q Goes from ~6k to ~800. Cc: Suleiman Souhlal Cc: Steven Rostedt Cc: Frederic Weisbecker Cc: Paul E. McKenney Signed-off-by: Vineeth Pillai (Google) Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) --- kernel/sched/fair.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8e276d12c3cb..b147ad09126a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12076,11 +12076,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) if (!READ_ONCE(this_rq->rd->overload) || (sd && this_rq->avg_idle < sd->max_newidle_lb_cost)) { - - if (sd) - update_next_balance(sd, &next_balance); rcu_read_unlock(); - goto out; } rcu_read_unlock(); @@ -12095,8 +12091,6 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) int continue_balancing = 1; u64 domain_cost; - update_next_balance(sd, &next_balance); - if (this_rq->avg_idle < curr_cost + sd->max_newidle_lb_cost) break; @@ -12109,6 +12103,8 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) t1 = sched_clock_cpu(this_cpu); domain_cost = t1 - t0; update_newidle_cost(sd, domain_cost); + sd->last_balance = jiffies; + update_next_balance(sd, &next_balance); curr_cost += domain_cost; t0 = t1; -- 2.42.0.655.g421f12c284-goog