From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 6578B3BCD3C for ; Tue, 4 Aug 2026 19:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785872581; cv=none; b=m2dujUAkJk5PI5oGNYZJzM9aejcKuXl5EPt+tE4ITgYHaXPpZRR3AgsDLSrOa0SsYkffnPJcMK9Mxh4Mw38mAV1p+dc+gFEut+hKi2DGo75wLb3D3juijKBkyrc3OeGEq9DbzuqlNxcWXuu74A2OcWDBLoQU+QE017L4Xy1X2sQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785872581; c=relaxed/simple; bh=P83wQDJAn1A/gKTtphEg4YaRaIaIoSypWAiIyKtk7FA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=SjMHUoTqPt0+f3kPccGZWlQ6tTeRxgPjizpNexYPq7MFbXfJFU4Mou/AifnDiuX6616t0gvVyLseV4QmrL1X17vf3KZYodljYuUpw6Nm+tkE30DqJetbGe6BXmkz1ncKqx/sT14FwX/RUV6PzZzyeIYufJzOj7Z0F9Jzmhx0ddA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JKV86yzN; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JKV86yzN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785872579; x=1817408579; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=P83wQDJAn1A/gKTtphEg4YaRaIaIoSypWAiIyKtk7FA=; b=JKV86yzNR2PlkzSySnD1xn6yBrKTOcWsg+G9R7E8/My7bIjVqfSMibYV xYJzTn+TwYdSHNTPDvl9xjULwftGDv/z4gipoW6zEub9gsKWNYcJRKyx5 XlT8saB5MJnO3Ma4635jWrCjGOT2WjukyPpPF7HRO47yaNS2MPPMJlc4M VaRzCorOm9+rMMUVZ7evhw/8r7M98VY1ypwwNVjDIZTfI7rLe8IkAw9Rj Ecg4LtAt33asVE1m+hBU1U3bEghvqoIgOeLx/8kx4UuY0P75xXGui51rE eKeZauMyR6ft/qbD6qAYPz2d6qH3bqAwy2P+njXihx6Yu3cs5QeO0nKEG Q==; X-CSE-ConnectionGUID: KmtBF4RCQQ+wnv4SFgMDIw== X-CSE-MsgGUID: pAkFIyV0S3u2zkrJ7w56FQ== X-IronPort-AV: E=McAfee;i="6800,10657,11865"; a="90320111" X-IronPort-AV: E=Sophos;i="6.25,205,1779174000"; d="scan'208";a="90320111" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2026 12:42:58 -0700 X-CSE-ConnectionGUID: RcK8SIkTRnC/dWdGMUjlSA== X-CSE-MsgGUID: WtRZJL4XSnu3eUqZYHHNXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,205,1779174000"; d="scan'208";a="257714892" Received: from schen9-mobl4.amr.corp.intel.com (HELO [10.125.108.237]) ([10.125.108.237]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2026 12:42:57 -0700 Message-ID: <2b23308912135b92e8f10e1b8909c89d8b46f41b.camel@linux.intel.com> Subject: Re: [PATCH] sched/cache: honor migrate_llc_task semantics in active load balance From: Tim Chen To: Lu Wang , yu.c.chen@intel.com Cc: peterz@infradead.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, chen.yu@linux.dev Date: Tue, 04 Aug 2026 12:42:55 -0700 In-Reply-To: <20260804150733.3406828-1-wanglu.priv@gmail.com> References: <20260804150733.3406828-1-wanglu.priv@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.1 (3.58.1-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2026-08-04 at 23:07 +0800, Lu Wang wrote: > Thanks, Chenyu. >=20 > On Tue, 2026-08-04 at 16:17 +0800, Chen, Yu C wrote: > > Yes. Besides, if I understand correctly, I suppose Lu Wang was > > referring to the following scenario: > >=20 > > src_rq has 2 runnable tasks, p1 and p2. p1 prefers dst_rq (dst_llc), > > while p2 prefers src_rq (src_llc). In this case, migrate_llc_task is > > set because src_rq has at least one task, p1, that wants to migrate > > to dst_rq. In ALB, can_migrate_task() found p2 and returns true for p2 > > thus moves p2 out of its preferred LLC. >=20 > That's exactly the scenario I had in mind. >=20 > > Firstly, before ALB is triggered, the generic (passive) load balance is > > triggered. It iterates over p1 and p2 on src_rq to see if it can move a= ny > > one of them to dst_rq, and in most cases it succeeds in moving p1 to > > dst_cpu. As a result, ALB will not be triggered. >=20 > My question is whether p1 is guaranteed to be moved out in passive > LB. can_migrate_task()/migrate_degrades_llc() can reject p1 for > several independent reasons =E2=80=94 p1 pinned by cpus_ptr, p1 cache-hot > with nr_balance_failed still below cache_nice_tries, or > can_migrate_llc_task() returning something other than mig_forbid due > to capacity constraints on dst_llc at that instant. If passive LB > rejects p1 for any of these, ALB is still triggered with p1 and p2 > both present on src_rq. >=20 > Can we conclude that p1 and p2 never end up on src_rq together when > ALB fires? Or would it help to set up a simple experiment and trace > this path to see whether it actually occurs in practice? >=20 >=20 With 2 tasks on rq with different preference, active load balance could pick the wrong task as can_migrate_task() checked in active load balance will not consult migrate_degrades_llc(). How about the following patch to fix this issue. Tim --- sched/cache: skip active load balance for LLC-motivated imbalance For a migrate_llc_task imbalance, ALB runs detach_one_task() with LBF_ACTIVE_LB set, which makes can_migrate_task() return early before migrate_degrades_llc() is consulted. The victim is then the first eligible task at the tail of cfs_tasks, regardless of LLC preference, so ALB can pull a task that prefers the source LLC - the opposite of the intent. Skip ALB for migrate_llc_task when more than one CFS task is runnable, and let a later balance pass pull a task that prefers the destination LLC. With a single runnable task ALB is retained: that task prefers the destination LLC and cannot migrate otherwise. Other ALB reasons (asym, misfit, imbalanced, capacity) arrive with a different migration_type and are unaffected. Reported-by: Lu Wang Signed-off-by: Tim Chen --- kernel/sched/fair.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d78467ec6ee1..615c9aeab621 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10642,6 +10642,19 @@ alb_break_llc(struct lb_env *env) return true; } + /* + * When the imbalance is for migrate_llc_task, the ALB victim is + * chosen by can_migrate_task() under LBF_ACTIVE_LB, which ignores + * LLC preference and may pull a task that prefers the source LLC. + * Skip ALB when more than one CFS task is runnable, and let a + * later balance pass pull a task that prefers the destination LLC + * instead. With a single runnable task, ALB is still needed: that + * task prefers the destination LLC and cannot migrate otherwise. + */ + if (env->migration_type =3D=3D migrate_llc_task && + env->src_rq->cfs.h_nr_runnable > 1) + return true; + return false; } =20