From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D59063E0C55 for ; Thu, 18 Jun 2026 09:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781775673; cv=none; b=Y7uI9r8GfMm9RhUA3WwdCwUqoXx3JKbEO3tIzQzpjr9UxYEbUoAgMSUCBdpfewmK42f77MtBb/YjjPV+8oMXQ9CyKwhgNVeeBgzCUuexAqCfnwW08o2blJytO+qH68csLM880Ei0/870MA/Rd5Fhic/kdeKNC/EMx2ZJyBijd7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781775673; c=relaxed/simple; bh=VG7kYeeUVvJWNBkon6dFWXr9+X3knZGrMDG5MeTdJL4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R/nhiFBjzjl6gDRj78yHVecRO7O4jZ6Ww74yJpr6mwek4skEnxaxGZO01syjSYQ90PeOF36mSRzs1/CW/EnqEDxV0Am9lUef8lZRySsjq5HVkQMG6lADhJdz85rE5p2B7fc/eFrf/+sTMM5pzwy4dfIiz8Y+lMQ17BfpfIzVUck= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=LVfpcgeT; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LVfpcgeT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fNQumMCdukEkwj6FTp4JivoAHftRS/kstowvC/Ctx4s=; b=LVfpcgeT0lgroIWQ/C2FJE1A6b +aA9556pzyGjrbi2clqQ9y9xcsUJgezi6fomPnDKgLLmD7BymWkNDWapKvEF8tWD8REB1GKV5q3hE Ic5pDXUYsymR/evdoouJ6u3XAuLEh2UkN/dYuLxk7QVzttWF1BFJwBiNzn+GtuotAgN30n1Ovi7gv 5EKkwQuMh+6kwA4poGAj6aeNamKVS3mKkV9NGe7dHdRkEvavxsak37MVbYrtE+71nErcAGqidHtSf NTq68SkFUhqW4y5fMM8MCtemlmLJakQNk/+ofDyx9BnK7rv/vxbVjdnj8O0cb9YZRPgmzN+9z6Fyh 2HKnUA1A==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wa9F2-0000000EEGM-3LeK; Thu, 18 Jun 2026 09:40:57 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 4EEDD300578; Thu, 18 Jun 2026 11:40:56 +0200 (CEST) Date: Thu, 18 Jun 2026 11:40:56 +0200 From: Peter Zijlstra To: Xin Zhao Cc: vschneid@redhat.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, kprateek.nayak@amd.com, pauld@redhat.com, aiqun.yu@oss.qualcomm.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/2] sched/fair: Simplify balance_interval reset logic in sched_balance_rq() Message-ID: <20260618094056.GN42921@noisy.programming.kicks-ass.net> References: <20260617072151.1173416-1-jackzxcui1989@163.com> <20260617072151.1173416-3-jackzxcui1989@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260617072151.1173416-3-jackzxcui1989@163.com> On Wed, Jun 17, 2026 at 03:21:51PM +0800, Xin Zhao wrote: > In sched_balance_rq(), it is possible to call need_active_balance() twice > in quick succession, which is not appropriate. There are two conditions in > sched_balance_rq() that reset balance_interval to min_interval, one is > when the local variable active_balance is 0, and the other is when > need_active_balance() returns a non-zero value. The local variable > active_balance is initialized to 0. Therefore, the only situation in which > balance_interval NOT be reset to min_interval is if need_active_balance() > has been executed once, marking the local variable active_balance as 1, > and then the second call to need_active_balance() returns 0. In other > words, the case is that during the interval between two close calls to > need_active_balance(), busiest rq completes the recently dispatched active > balance stop work, which is quite rare. > > There are mainly two scenarios that lead to reaching sched_balance_rq(): > one is the newly idle balance triggered by __schedule(), and the other is > the periodic balance logic controlled by sd->balance_interval or > nohz.next_balance, which ultimately executes in the softirq context. The > vast majority of cases executing sched_balance_rq() is the first scenario. > During the execution of __schedule(), preemption is disabled, so the > interval between two checks of need_active_balance() will not be long. > Thus, only in the second scenario, balance_interval may NOT be reset to > min_interval, but it's still not likely. The second scenario is in softirq > context, the execution of two need_active_balance() checks can be > preempted by other tasks, leading to a longer interval between the two > checks. However, there is no evidence to suggest that not resetting > min_interval in these low-probability cases caused by scheduling > preemption offers any significant benefits. It would be better to simplify > this complex reset logic for balance_interval to an unconditional reset. This is very confusing, and my AI helper isn't helping much this time around. active_balance is initialized 0, it is only (but not always) set 1 when need_active_balance(). Therefore, the condition: !active_balance || need_active_balance() is a truism and can be removed. Or am I missing something more complicated? > Signed-off-by: Xin Zhao > --- > kernel/sched/fair.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 2b9653623..9c78241e9 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -13464,10 +13464,8 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq, > sd->nr_balance_failed = 0; > } > > - if (likely(!active_balance) || need_active_balance(&env)) { > - /* We were unbalanced, so reset the balancing interval */ > - sd->balance_interval = sd->min_interval; > - } > + /* We were unbalanced, so reset the balancing interval */ > + sd->balance_interval = sd->min_interval; > > goto out; > > -- > 2.34.1 >