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 019B13B388E for ; Mon, 15 Jun 2026 06:57:55 +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=1781506677; cv=none; b=Ci4qIcUT5GuZOqxK+B++VnUw3bNvEiAV79+gpwNKPxWIhDlZ4QyzyrfQxMPqUptcIkntn5KhIFSnsN+F4Qc7/8RBj8SC0Dif7UWR7CB3+1i+kH2iEaI98IZPosZn7m0HHz74WkAR3gu2VimU3uyGU7loh75+uNUID93yvuEiuEM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781506677; c=relaxed/simple; bh=BgIqhu3vtATBFVKg9JTHo60vUQmkqXRzbswXRKVatiQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MXelD6kqOExmtWVM5a9XQd3O9pwDZZmB34qGyBoVW8rn43jhnfAPL7FjUeEufIVtANXxaH9Nu0r+4OEbgsny49C4usuNkpKQUKXFTqlG7tENdNJBA/ei833NGWrAUKoM+EEcoYLQRvfZa147BHtKH+H+RWOE30XYlOoDLcNtuFc= 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=h6cfX5W0; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=T7JltBlV; 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="h6cfX5W0"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="T7JltBlV" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65F6IxAh3346622 for ; Mon, 15 Jun 2026 06:57:55 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= gfadikbLkrICUcSVv4D0WofDng4XBJSqHuN0IqaPQDo=; b=h6cfX5W0Zi+C+S76 yrGNbslC5q4gok4b45zio0KiND45uoNeauU14dqNWttddjg0Iu2GCVt6tsb0xdgu q+sxNuMbEySX1sHQH0qSAwfvkdhSE5712aFHg+GLdKawo3IwK3pi88uUcWa0a41S zEfZjSJJUdLxhZohVt1ZnK8FvA+zcGKrhe8SB8LQzH+jbqzK823fdea+PFJxuq05 WTgyxaI0JmVkD3r2WgTmgQpPFVcsqgpgUS0Pxb6lIpApuZO6vinsUBU5OuqMqSSa TvAFJNP7WWYjLSZ+9nl54LHKc5h5h6xFEN43l6VMTvnRmUugKyh3zJa+31OGVJRX sydR/Q== Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4es0g862en-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 15 Jun 2026 06:57:55 +0000 (GMT) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-36d98b68d77so853583a91.2 for ; Sun, 14 Jun 2026 23:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781506675; x=1782111475; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=gfadikbLkrICUcSVv4D0WofDng4XBJSqHuN0IqaPQDo=; b=T7JltBlVew8TCfkq7C5CBNKLwFjn1sbD/ti5z5ALWdBMR3dqZY81D+oPnNrAm3T63S Q1HpjXFUNkUEXXWyw+aczN9lrgndNUMJ+ZvAWE9H3PW2QPrtTxvs31C+U/SxdjTNptJa etzTMuJ2xv0DLgzdIUsv5bQoRqJkY5oHRBQ3vSeMuDobeep01AOsI5rGlZGuQ0PLK22O ccyzoK/BfwaahcBsMgIE+ANZEY7LYUutK4jqRW+99RESYigWlRgqCzNBcJ++Yb5GtGgi ePLIh0zpfglDje2RpdCyU5memPpU6tVMDgZH89RKTxX7O8ab9QJxNaYeSbMWVejfkQ/A qcnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781506675; x=1782111475; h=content-transfer-encoding:in-reply-to:content-language:from :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=gfadikbLkrICUcSVv4D0WofDng4XBJSqHuN0IqaPQDo=; b=rvIquv/kI/0qlYNAFXxWgBvarsPFd8ogfxq2VlE1fkFJdVE9a029dQRtysqm+qJ6Cg COenOlh46/lRUyrf6WsUcGsUrRNAE6ltIi7xTm2YYAxQ3htqEtk7gXNiq6t2TdqlDPe4 XWFH5+O/QeHzUE7N6IN0J2wL22YuMQXUbGRijkk829hwdbg/aUDtryzixSb4078wTiMG s0EPHhsL+81UkkdJ8uwi5jTj1YGiNdT8PFVQ3WRPflQqnFlm0h6ZvrGcVXNAlrota6De nIB4g8ysW4Mn/4CW7GjpJ/TkNJxBkaMF3EDakwFQRHYRmV0KKpSDHLMme7YzSKOxjl75 GqaA== X-Forwarded-Encrypted: i=1; AFNElJ+t6jLcvD9y17LIhsG7VGX7tZVRZDNUe6Gd27yPl6uMU32gJUnX8l9IBA4as8vehc3h1CwLNpmbo70tNKU=@vger.kernel.org X-Gm-Message-State: AOJu0YyO+kuHuJ4v/b+EDJhxkcAiiJ4XLVxrINKy90dZHLpFAAn4VeGH PDXSIAkWBK0Yf4wPpdQ+2JnMW+x2pq5ejTlDY7dvXIWl5BoK+vb5TudJgAg6gjPAXHTDdi0/hdm UaywVTUq3zjbSqnmenxCAvI7dBOHOO5g8/GvP5Qqbf1uMB+oIuLy2yDNFtz5x6R3PFRbrKOewwL wSrg== X-Gm-Gg: Acq92OFGAjkmvGsDEhcbJ02bevThNe1vNHLmUE/LYVAQpnHxRM/hf25LQnX3+6EB7Hk gDf67dJWvtwdngQ0KkFCbRB7xo65iJ7KCABBs8udRaQMdvSlshF8PAEBCU5X92dbflPuWhzHcLS eRq+v+yJ+EuCpR6TlQb8N5GQ1QMu9NJRn3VRuhJ4BqEdCgSl2YGwaJLGhx58pfPaywnbYqoSZo+ /xT4/FpxIouIPwOup+R/pSE0PxJyWYBx9NFgiAyjd5oIPan28P699Qt9pUCJ3ADbNUwta3/HuYb SzWUl5Q6VgusQnTIaNNleKlthb/IbZFVm5SU9JG/PpilywURntbkfQHgQDnXkvrVVP1QZGa/9iw kHCMhM44VhUEYUezm4E/JzK0Hv15FTc3nZBJ1wDwwtolSVzojKOSb86987w8lvlQrfwFKXOI6gu 3ajY4R99bJXLw= X-Received: by 2002:a17:90b:3850:b0:36b:900a:d295 with SMTP id 98e67ed59e1d1-37a015600b8mr6520692a91.2.1781506674439; Sun, 14 Jun 2026 23:57:54 -0700 (PDT) X-Received: by 2002:a17:90b:3850:b0:36b:900a:d295 with SMTP id 98e67ed59e1d1-37a015600b8mr6520681a91.2.1781506673862; Sun, 14 Jun 2026 23:57:53 -0700 (PDT) Received: from [10.133.33.25] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37a212ab3d0sm11378984a91.16.2026.06.14.23.57.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Jun 2026 23:57:53 -0700 (PDT) Message-ID: Date: Mon, 15 Jun 2026 14:57:49 +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 v2] sched/fair: Don't trigger active lb if src_rq->curr is CFS and not on_rq To: Xin Zhao Cc: bsegall@google.com, dietmar.eggemann@arm.com, juri.lelli@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, vincent.guittot@linaro.org, vschneid@redhat.com References: <20260614120358.2936759-1-jackzxcui1989@163.com> From: "Aiqun(Maria) Yu" Content-Language: en-US In-Reply-To: <20260614120358.2936759-1-jackzxcui1989@163.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=OOoXGyaB c=1 sm=1 tr=0 ts=6a2fa273 cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=k3sC4vxmh-k7Ad0RD0gA:9 a=QEXdDO2ut3YA:10 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-GUID: lrZdIx6LwRtSqlxmNI4c-fp4YwTN5inb X-Proofpoint-ORIG-GUID: lrZdIx6LwRtSqlxmNI4c-fp4YwTN5inb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE1MDA3MCBTYWx0ZWRfX8II40juag4DG HrqqWJEjS+kvwwIvDWCmJaquNcnCOUdU64WSFFoVjCSjXoPF8gma8G14BfwZ/BN29gacZsv2Ka5 fDPQ8EB/tcYqVQaUjT0rZMvUtGPwGYY5YOv0dse5nmTnPvCtt/Kbx1OBmLPxUmNbe7iOhtNs6tI bjTZlUeIO/gTaoEdTKSKEeACRoYRbm8rtesLhs6d5EQM3gSiISZrxjIVrGlX28TzFYK5ZP1poS/ efRU7BEwXP2hzn4Zquf8nsP8pekYgiMwa6KvhHZ4NATUADVLg1E7spuDdc2q3qKnEJ8OTG0Awqz trcfNaMCm9dsgE7fKV07Fd4Xg+HR6/pEv9HPnV+l1zTgSc7H2nEE3Ngi8DQ2dLI8vkCwPYgugfL 1fDPrD/hPdWK9iMEfdyRP+B3vJ3Oa58VDJf/kgIdyv1ASzbnPid9qERCzN8a7PHNuEbUrRW5cei I82y649KFbo2s2D0JQw== X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE1MDA3MCBTYWx0ZWRfX/9cBIxVCq2ka lL+rkG0glNGREkqGUAD7XhwSgpX+vBUzLpHOdhmF/EardATzqWr3QA3OOYLeOm1RdjcX3TZTEJy MJVsLaOGBvXrnnTBx2Cyx9ZgDqRePSk= 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-15_02,2026-06-12_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606150070 On 6/14/2026 8:03 PM, Xin Zhao wrote: > On Sun, 14 Jun 2026 12:17:37 +0800 "Aiqun(Maria) Yu" wrote: > >> What's the probability that curr->on_rq is 1 throughout the entire check? >> >>> >>> In __schedule(), before setting curr to next, during the execution of >>> pick_next_task(), sched_balance_rq() is called. It will unlock and then >>> re-lock the rq, creating "holes" during which other CPUs may see zero >>> rq->curr->on_rq. This situation occurs quite frequently because: >>> 1. Periodic load balancing across CPUs often happens in close succession, >>> leading to collisions in the rq lock during sched_balance_rq(). >>> 2. try_to_block_task() sets curr->on_rq to 0, and during the rq lock >>> "hole" in pick_next_task(), rq->curr has not yet been assigned to next, >>> resulting in curr->on_rq being seen as 0. >> >> It is possible that curr->on_rq is seen as 0 and don't need to do active >> balance. >> While my concern is the overhead of check "curr->on_rq" every time to >> the possibility of curr->on_rq should be considered as well. > > This indeed reminds me that I should move the checks for curr->sched_class > and curr->on_rq to a more appropriate place. > > The number of checks before executing active balancing will increase from > two to three with this patch: > 1. Do cpumask_test_cpu() for busiest->curr, ensure it can run on dst_cpu. > 2. Confirm that there are no already triggered active balances for the > busiest's run queue. > 3. Check busiest->curr; if busiest->curr is a CFS task, it's on_rq should > not be 0. > Testing has shown that condition 1 filters out approximately 91.4% of all Could you describe the scenario under which this data was collected? Without that context, the numbers don't give me a meaningful reference point. > cases, which is a sufficiently high filtering rate. Therefore, conditions > 2 and 3 should be evaluated based on this condition. If we consider the > samples filtered out by condition 1, condition 2 will filter out about > 5.4% of the cases, and condition 3 will filter out about 2.36% of the Shall we also have busiest->curr is not a CFS task as a separate condition? > cases. > > Thus, it is better to place the filtering of condition 3 after the > filtering of condition 2. This change will be reflected in PATCH v3. > Additionally, this modification will not introduce new cases that skip the > logic for resetting balance_interval to min_interval. > > >>> Additionally, in sched_balance_rq(), we unconditionally reset the >>> balance_interval to min_interval. The difference is that original logic >>> does not reset the balance_interval when dst_cpu softirq handler is >>> preempted while src_cpu successfully run the just-dispatched active >>> balancing, during the gaps between two need_active_balance() checks. It >>> seems that we haven't observed any substantial benefits from reducing the >>> opportunities for balance under such fluctuating conditions. So simplify >> >> This is not that clear to me. And could you pls help to have more data >> and example to have more details? >> Maybe it can be separate with different patch? > > The changes in this part do indeed seem subtle. I think you're right; they > should be separated into an independent patch with a detailed explanation. > > >>> - if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) { >>> + if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr) || >>> + (busiest->curr->sched_class == &fair_sched_class && >>> + !busiest->curr->on_rq)) { >> >> if busiest->curr->sched_class != &fair_sched_class, do we really need to >> do active balance here? >> >> Also maybe unlikely(!busiest->curr->on_rq) instead. > > This is also one of the points that puzzled me when I first saw this piece > of code: why there isn't a further check for fair_sched_class. My test > data shows that if the cpumask_test_cpu test is satisfied and > busiest->curr is not a CFS task, the success rate of active balancing > reaches as high as 98.7%. This result is clearly different from our > initial expectations. Since the busiest rq lock was newly hold, so it is potentially have new conditions like current task is not cfs task running and don't need to do the active load balance. So if the current busiest_rq->cfs_tasks is not empty, the light weight best effort balance is just detach from busiest_rq and attach to this rq. > > I believe this could be attributed to a few reasons: > 1. The proportion of real-time tasks in the system is generally quite > small, so they are more likely to occupy busiest->curr for only a brief > period. The CFS tasks we want to migrate may easily be "buried" by this > recently executed real-time task. > 2. If this task's CPU can run on dst_cpu, it indicates that the real-time > task is correlated with dst_cpu. Real-time tasks often trigger new > associated CFS tasks, which increases the success rate of executing active > load balancing. I also mentioned this point in the commit log. > The current task is changed to other higher priority task, either it is rt or other non-cfs task, it is possible that the previous identified cfs task is not current running, and don't need active load balance at all. > >>> >>> - if (likely(!active_balance) || need_active_balance(&env)) { >> >> If the active_balance already triggered, why still need reset balancing >> interval? > > As mentioned earlier, this part is not very obvious. I will separate this > section and provide a detailed explanation in PATCH v3. great thx. > > > Thanks > Xin Zhao > -- Thx and BRs, Aiqun(Maria) Yu