From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 B4B014A23 for ; Mon, 22 Jun 2026 12:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782130551; cv=none; b=jX/PcU4WVg2NiXWb9x45lRph9o+npznt33fJJWmAeOHbwAGKQOlLnQwa2o2L/yqLzthTHXxz4LvDwt7T6F9VuuXPRX+Zp2SU7ZaLi/JDzbdiA64j43xp6gd33HhqwpG1uTW3aPOY9l3gDiq2iINyu3SaUDIE2eJg9GqxjlFgAgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782130551; c=relaxed/simple; bh=ANwfYlRdCBGI3baRDWIr7m+DHAr7RWOIgCGw7RAVghM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sotzFXtFOy8CcKGH0Fj/4yz++wED2DRU53RdGTcaVf1XedYgsZRbcPLozySS2dPxZtyzanH6MHYA0UYmvDDv45q7/5REK/CiRUHq4UMfyEFOFr4YOP1UZLlJG6qul+LrU7zKM94hrYH9VG5hboIgzGlkUUK4Kl00n3AUa3YqnS4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=T/F+6vsS; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=InIU/r+Y; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="T/F+6vsS"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="InIU/r+Y" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65MAne2b397276 for ; Mon, 22 Jun 2026 12:15:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 7L8C4islr9sgs0Xog4oDO0kMVQ844SCSRiI0B7JwiNM=; b=T/F+6vsSFUS9J5Tk V9EPQjizBr0fvdgGDLj7MfnlnbAPSYzf5D56posysDqMbabW+rbgMyz/bcou8zrm n8pUvkTWRCDwVLQOZ5mIu/gb9+VfQ+rXqXI+8nLUooO2nXPtsNe+8YJkuzv6dmDV U9XIY+uTAjax9d49ftVrF62qg3Zh+ilnjoWFf6DdRiNm7aqoIw4+IqMWi7pX6K0W HIt4E3/AD3q8MuOVKampWfIN7pQn2Y20VRXgQnQuhPFy3Px1XlPhNNdBu+b4L61F zcbCeQ2/J4lzj5aRywZ1vIK4KsTE6bCet/ObGGsMTmsRguMqzgTV1o1AeBvGiiqQ zw5EmA== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ewm1k68kc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 22 Jun 2026 12:15:48 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c8fc6442dccso8054a12.1 for ; Mon, 22 Jun 2026 05:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1782130548; x=1782735348; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7L8C4islr9sgs0Xog4oDO0kMVQ844SCSRiI0B7JwiNM=; b=InIU/r+YkZUzG8xVDZBJVt3zIm9FnbUjk9CYoO8OG4xaTIYChJtU/cLrkSJe1CLVxo Y5ox5yj999m8hwHX8qDno5LkkpbTBdjcWhh/pPi7h+2ilZUc8mdfy5cLfM2V387gO/Iu bI9HfOdwMRufifBUKQGTG6yMIHdSjbFbHDak7Ej0pTIcfcp+kRitEP9vK8K8l7g0LKTH 6VWL/fRSv2eXupOjltKicEv7FWvV5WpVsA9hInO9TUjoC/AyEPDN1EXuqfnimGkblYfP dEygiA6JaeoKtb3rOHioAPsp5EA6g/4hwsxNlK97ISBni40qbSUHBfsQ0t2GwYOaGBGq ePLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782130548; x=1782735348; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7L8C4islr9sgs0Xog4oDO0kMVQ844SCSRiI0B7JwiNM=; b=V2Z+7SJXL+3sSQWcfhddKNlw62qiZ2uQ/KRmn3la/U2u4s3MSbpub6zLXO2Uwmn1St CW1/bYDHEli3j1LF7w/aaPa84cQSH/r4BGCoCiB3I6bD5OfvIlURTmGE60+ycGN4XP7w 7Sd6RBLy+jRmp7RaqKSnCnYmfMvxCLzscoeOaJcMwgaVoi/PDwWTwgdVXocl/onlK24J sQjblKHSKCBEkkRGiHCuBoTz7gaWb9yFYZxjGaNTD1FYO06OW7wxiaiAISCTB+qvqjxN EdPsFJZVspgAg7ofJ/OQGmvPmqLzgT9JnhONSAgKIWHgUkeD/VyUrItHapmDU9PNNdlN EIdg== X-Forwarded-Encrypted: i=1; AHgh+RpiQTEowkzbAGW0oiwxeGPcgHFvB1AAfGWAcKKs522Hz+QPJHgC3c7JX3YB/0xkv3WqsHcogFto0q9/CJQ=@vger.kernel.org X-Gm-Message-State: AOJu0YymwXVv7HiLYeSPKUAChqBjYEmssffDni3uuIyUOWkf5vPfVCJ9 K1+NOfZT4SC1GVKPhLD+1rbhJhdd4NiFn9NZ5+UggAfWVLNkdy4O2OJw+0DPxv7bKyGqxH406q4 GW9quArg3/Vo7sZmjnhoPoWki1ZH3nSIDXFDJwb0qahBG2V+MSB14YWBIeAX/RHh+aG4= X-Gm-Gg: AfdE7clVlJxATaZKxDWjYAPoyYLWvrXLpjy2YdGkaOT05JQSGuh4uGG/Up98TyMFZlW 0gFhtmDyfI76OjhcsUlntgdISgx/yxUWRYiq/sNX2pd+mk3b3uqKYuzhIiRgiUfFEWzH2zX8h8F Qc7fqqvJyuxDeB/4zKBj3xgYSWX/zDR3xcR7nWIAjMr8y4ebhHGqju6a+KOLlop7cNEdT4mVkJ3 D0DvgQHeR+Ft754FHp6/zZlOr8oUgwrTVbIYqeguF+ZNO4t93PwiClqE4QLgHAfELvl3wPGvBHB 3Dzx0U68SOwr11t7SBVHNBcYwjiNRaiE/NXHP1RCL9t1mHcdeQvM2x7lNunDNsj9K1LOESq14Pf LeL3nJgnX2er7G6GGENo24KjRRSWBGTFmjRahAGXEAJ7fwkD9YTKD5ZGbS3aOR4jiZluWcsPkZy 5yZg== X-Received: by 2002:a17:903:1104:b0:2bf:ac4:b015 with SMTP id d9443c01a7336-2c7bea33e3fmr1194775ad.0.1782130548084; Mon, 22 Jun 2026 05:15:48 -0700 (PDT) X-Received: by 2002:a17:903:1104:b0:2bf:ac4:b015 with SMTP id d9443c01a7336-2c7bea33e3fmr1194435ad.0.1782130547458; Mon, 22 Jun 2026 05:15:47 -0700 (PDT) Received: from [10.133.33.176] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c743bfd9ddsm78889795ad.55.2026.06.22.05.15.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jun 2026 05:15:47 -0700 (PDT) Message-ID: Date: Mon, 22 Jun 2026 20:15:42 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 0/2] sched/fair: Optimize some active balance logic To: Peter Zijlstra , 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, linux-kernel@vger.kernel.org References: <20260617072151.1173416-1-jackzxcui1989@163.com> <20260618105627.GP49951@noisy.programming.kicks-ass.net> Content-Language: en-US From: "Aiqun(Maria) Yu" In-Reply-To: <20260618105627.GP49951@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: aoR2mK6R_zArl1ENJzxiE3fp11KoGnku X-Proofpoint-Spam-Info: AW1haW4tMjYwNjIyMDEyMSBTYWx0ZWRfXxtCr3J0urTZC 4RVyQOu60O2/kpaFSLrf65G1/3KJhdSlJh8HaTzs8XpG+DZ9hTB31jAF4xbraqInyLYbfZylR/2 bU14IjOW/cRdnCQMVXcKBT+lYEls0g8= X-Authority-Analysis: v=2.4 cv=T6S8ifKQ c=1 sm=1 tr=0 ts=6a392774 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=JfrnYn6hAAAA:8 a=fQBmyv5MCO8xTpF_XAYA:9 a=QEXdDO2ut3YA:10 a=x9snwWr2DeNwDh03kgHS:22 a=1CNFftbPRP8L7MoqJWF3:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjIyMDEyMSBTYWx0ZWRfX/PS9AQoQn/SC wPBI/rxT7epfY88/4PFGw9VD9IglMW7z7gA4jkxWmtwErPi1evnKNdcjLetctrtnMQosmmnpD+l nSrzDTSsXo8vWoexug3DYqz4GtuPFNYJo2QKgoP58e4t24vidhv//PPEaGR6sogy3q0S9DMGG3+ fxiQne8LNxkNAGCLJZGkmLSkg0wAXJdHf2+M/KSqfAxlp13K0MVBj4FhzhiC0vup5U2gpwmtyI2 exqZ/R45FPFvt49+RDal4O+QJxqvR6ZC5cVycznyBAAlRHzfqAIDXMimc5xTs4VPIdVYbKK0PW6 e6HWjmYeuF/1wkeSsHyKd2MHQmM0qRPKRIaWQvgyBhzgizOSeDhiHLlvH9trmEzaOhhObj9pFPS sWY3lOsmfNoPx+ao4glQb8zYSHsY7upna2swa+JE9dG/1AubDKToqmmh27K0T+tQ3Jr4SkVefPu W2+zU/Q8k29PEDI70yA== X-Proofpoint-ORIG-GUID: aoR2mK6R_zArl1ENJzxiE3fp11KoGnku X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-22_02,2026-06-18_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 malwarescore=0 adultscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606220121 On 6/18/2026 6:56 PM, Peter Zijlstra wrote: > > > And since I've been staring at this code far too long, I accidentally > did the below cleanup on top. > > > --- > Subject: sched/fair: Reflow sched_balance_rq() > From: Peter Zijlstra > Date: Thu Jun 18 10:51:49 CEST 2026 > > Reflow to reduce indenting. > > Signed-off-by: Peter Zijlstra (Intel) > --- > kernel/sched/fair.c | 136 ++++++++++++++++++++++++--------------------------- > kernel/sched/sched.h | 19 ++++++- > 2 files changed, 82 insertions(+), 73 deletions(-) > > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -13437,82 +13437,78 @@ static int sched_balance_rq(int this_cpu > } > } > > - if (!ld_moved) { > - schedstat_inc(sd->lb_failed[idle]); > + if (ld_moved) { > + sd->nr_balance_failed = 0; > + goto out_unbalanced; > + } > + > + schedstat_inc(sd->lb_failed[idle]); > + /* > + * Increment the failure counter only on periodic balance. > + * We do not want newidle balance, which can be very > + * frequent, pollute the failure counter causing > + * excessive cache_hot migrations and active balances. > + * > + * Similarly for migration_misfit which is not related to > + * load/util migration, don't pollute nr_balance_failed. > + * > + * The same for cache aware scheduling's allowance for > + * load imbalance. If regular load balance does not > + * migrate task due to LLC locality, it is a expected > + * behavior and don't pollute nr_balance_failed. > + * See can_migrate_task(). > + */ > + if (idle != CPU_NEWLY_IDLE && > + env.migration_type != migrate_misfit && > + !(env.flags & LBF_LLC_PINNED)) > + sd->nr_balance_failed++; > + > + if (!need_active_balance(&env)) > + goto out_unbalanced; > + > + scoped_guard (raw_spin_rq_lock_irqsave, busiest) { > /* > - * Increment the failure counter only on periodic balance. > - * We do not want newidle balance, which can be very > - * frequent, pollute the failure counter causing > - * excessive cache_hot migrations and active balances. > - * > - * Similarly for migration_misfit which is not related to > - * load/util migration, don't pollute nr_balance_failed. > - * > - * The same for cache aware scheduling's allowance for > - * load imbalance. If regular load balance does not > - * migrate task due to LLC locality, it is a expected > - * behavior and don't pollute nr_balance_failed. > - * See can_migrate_task(). > + * Don't kick the active_load_balance_cpu_stop, > + * if the curr task on busiest CPU can't be > + * moved to this_cpu: > */ > - if (idle != CPU_NEWLY_IDLE && > - env.migration_type != migrate_misfit && > - !(env.flags & LBF_LLC_PINNED)) > - sd->nr_balance_failed++; > - > - if (need_active_balance(&env)) { > - unsigned long flags; > - > - raw_spin_rq_lock_irqsave(busiest, flags); > - > - /* > - * Don't kick the active_load_balance_cpu_stop, > - * if the curr task on busiest CPU can't be > - * moved to this_cpu: > - */ > - if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) { > - raw_spin_rq_unlock_irqrestore(busiest, flags); > - goto out_one_pinned; > - } > - > - /* Record that we found at least one task that could run on this_cpu */ > - env.flags &= ~LBF_ALL_PINNED; > - > - /* > - * ->active_balance synchronizes accesses to > - * ->active_balance_work. Once set, it's cleared > - * only after active load balance is finished. > - */ > - if (busiest->active_balance) > - goto no_active_balance; > - > - /* > - * @busiest dropped its rq_lock in the middle of > - * scheduling out its ->curr task (->on_rq := 0), no > - * need to forcefully punt it away with active balance. > - */ > - if (!busiest->curr->on_rq) > - goto no_active_balance; > - > - busiest->active_balance = 1; > - busiest->push_cpu = this_cpu; > - active_balance = 1; > -no_active_balance: > - preempt_disable(); > - raw_spin_rq_unlock_irqrestore(busiest, flags); > - if (active_balance) { > - stop_one_cpu_nowait(cpu_of(busiest), > - active_load_balance_cpu_stop, busiest, > - &busiest->active_balance_work); > - } > - preempt_enable(); > - } > - } else { > - sd->nr_balance_failed = 0; > + if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) > + goto out_one_pinned; > + > + /* Record that we found at least one task that could run on this_cpu */ > + env.flags &= ~LBF_ALL_PINNED; > + > + /* > + * ->active_balance synchronizes accesses to > + * ->active_balance_work. Once set, it's cleared > + * only after active load balance is finished. > + */ > + if (busiest->active_balance) > + goto out_unbalanced; > + > + /* > + * @busiest dropped its rq_lock in the middle of > + * scheduling out its ->curr task (->on_rq := 0), no > + * need to forcefully punt it away with active balance. > + */ > + if (!busiest->curr->on_rq) This looks better than the previous patch. While at it, should we check busiest->cfs.h_nr_queued instead of !busiest->curr->on_rq? It is possible that busiest->curr is an RT/DL task and is still on_rq while busiest->cfs.h_nr_queued == 0 and list_empty(&busiest->cfs_tasks) may both be true, meaning there is no CFS task available for active balancing. This series has been moving quickly, and I only got back from the Dragon Boat Festival recently. I should have raised this earlier, but I am commenting here since this is now the clean top patch. > + goto out_unbalanced; > + > + busiest->active_balance = 1; > + busiest->push_cpu = this_cpu; > + active_balance = 1; > + preempt_disable(); > } > + if (active_balance) { > + stop_one_cpu_nowait(cpu_of(busiest), > + active_load_balance_cpu_stop, busiest, > + &busiest->active_balance_work); > + } > + preempt_enable(); > > +out_unbalanced: > /* We were unbalanced, so reset the balancing interval */ > sd->balance_interval = sd->min_interval; > - > goto out; > > out_balanced: > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -2018,7 +2018,8 @@ DEFINE_LOCK_GUARD_1(rq_lock, struct rq, > rq_unlock(_T->lock, &_T->rf), > struct rq_flags rf) > > -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock, __acquires(__rq_lockp(_T)), __releases(__rq_lockp(*(struct rq **)_T))); > +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock, __acquires(__rq_lockp(_T)), > + __releases(__rq_lockp(*(struct rq **)_T))); > #define class_rq_lock_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_lock, _T) > > DEFINE_LOCK_GUARD_1(rq_lock_irq, struct rq, > @@ -2026,7 +2027,8 @@ DEFINE_LOCK_GUARD_1(rq_lock_irq, struct > rq_unlock_irq(_T->lock, &_T->rf), > struct rq_flags rf) > > -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irq, __acquires(__rq_lockp(_T)), __releases(__rq_lockp(*(struct rq **)_T))); > +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irq, __acquires(__rq_lockp(_T)), > + __releases(__rq_lockp(*(struct rq **)_T))); > #define class_rq_lock_irq_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_lock_irq, _T) > > DEFINE_LOCK_GUARD_1(rq_lock_irqsave, struct rq, > @@ -2034,9 +2036,20 @@ DEFINE_LOCK_GUARD_1(rq_lock_irqsave, str > rq_unlock_irqrestore(_T->lock, &_T->rf), > struct rq_flags rf) > > -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irqsave, __acquires(__rq_lockp(_T)), __releases(__rq_lockp(*(struct rq **)_T))); > +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irqsave, __acquires(__rq_lockp(_T)), > + __releases(__rq_lockp(*(struct rq **)_T))); > #define class_rq_lock_irqsave_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_lock_irqsave, _T) > > +DEFINE_LOCK_GUARD_1(raw_spin_rq_lock_irqsave, struct rq, > + raw_spin_rq_lock_irqsave(_T->lock, _T->flags), > + raw_spin_rq_unlock_irqrestore(_T->lock, _T->flags), > + unsigned long flags) > + > +DECLARE_LOCK_GUARD_1_ATTRS(raw_spin_rq_lock_irqsave, __acquires(__rq_lockp(_T)), > + __releases(__rq_lockp(*(struct rq **)_T))); > +#define class_raw_spin_rq_lock_irqsave_constructor(_T) \ > + WITH_LOCK_GUARD_1_ATTRS(raw_spin_rq_lock_irqsave, _T) > + > #define this_rq_lock_irq(...) __acquire_ret(_this_rq_lock_irq(__VA_ARGS__), __rq_lockp(__ret)) > static inline struct rq *_this_rq_lock_irq(struct rq_flags *rf) __acquires_ret > { -- Thx and BRs, Aiqun(Maria) Yu