From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 20D8F2D594F for ; Tue, 17 Feb 2026 22:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771365867; cv=none; b=Ig/i3Ll7k60KdGm1KbLrEMdVjLK5PStl9fZeFNl/RmtD1BtZFhJyOCmDBPpJpB3UJndhEDPgO5zAB/ltAl4ApuUkBJExwTVftO3qDas2ovWgsYEhrHRN9eQS17cOElD2iNd8V1fA4MjTo6prxi0Jw+yMTT7LkbgY9fGMl2dtV/4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771365867; c=relaxed/simple; bh=p528nwPr8ajSHCPkpt4kqCWvrHaKgM1KQWpeapaR9+o=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=t/xJhoD5roVdp/fAyl+3dSfjym7DoJ3MlaiWFnaF62g0xIiBcTSFqkKjvD9dezvaaBf857ie9yE9G8ZTzPQZeABqDaAdyadAyP009I1Kl85i0Qd3cuQdhu6VE0k60Zmrer4crenJ381TFn3B8K+/DJ4GWSMCMw8BG21H+3GdNzM= 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=AQ5FQ0KV; arc=none smtp.client-ip=192.198.163.13 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="AQ5FQ0KV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771365865; x=1802901865; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=p528nwPr8ajSHCPkpt4kqCWvrHaKgM1KQWpeapaR9+o=; b=AQ5FQ0KVmbM9tP3L9h0+UuSY+BMjcQ8dUsud/hGRfPRSAAMGL+pNCixT 36DTNoGmgHSU79m7OOsAI41yYRgb14adhxsL6Sd3xLAHuN4cgOunuwsBn 12MELVnFP2xIi6M8+P6cxqGFCSiiV9sPbagvePiURLuXbKCxg1VZxaDBi pbBOTszlcbcfKadsvnQqb2elc/YIPJoePDCF6TTFjkDEbeAlSg+giFWfE XHw5as2BRfQq9g0SzFEqmDU6KR8gbQqF8ErVUx2m7JBuJjpgFi/8vC9vY Zb3+u3OftFQxHfAA9XbZuRP7Nk6p1masOr411Gjn6nLsyYxKf2N+cRp+5 w==; X-CSE-ConnectionGUID: R4VTyF+sSxq4mI9QjADULg== X-CSE-MsgGUID: VcP9kGprSDefHCRKrFyHSQ== X-IronPort-AV: E=McAfee;i="6800,10657,11704"; a="75044269" X-IronPort-AV: E=Sophos;i="6.21,297,1763452800"; d="scan'208";a="75044269" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2026 14:04:24 -0800 X-CSE-ConnectionGUID: kD3aLtunQbuDYa0JsVTeIA== X-CSE-MsgGUID: bI1aApmiRLeu+IcUkxPE5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,297,1763452800"; d="scan'208";a="218149013" Received: from unknown (HELO [10.241.243.83]) ([10.241.243.83]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2026 14:04:24 -0800 Message-ID: Subject: Re: [PATCH v3 13/21] sched/cache: Handle moving single tasks to/from their preferred LLC From: Tim Chen To: Madadi Vineeth Reddy Cc: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org Date: Tue, 17 Feb 2026 14:04:23 -0800 In-Reply-To: <6797dfae-5ff6-4035-a0d0-ca8eeccbed05@linux.ibm.com> References: <92fa33fc26f069d8044bac3b0efc3598f53131de.1770760558.git.tim.c.chen@linux.intel.com> <6797dfae-5ff6-4035-a0d0-ca8eeccbed05@linux.ibm.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 Wed, 2026-02-18 at 00:30 +0530, Madadi Vineeth Reddy wrote: > On 11/02/26 03:48, Tim Chen wrote: > > In the generic load balance(non-cache-aware-load-balance), > > if the busiest runqueue has only one task, active balancing may be > > invoked to move it. However, this migration might break LLC locality. > >=20 > > Before migration, check whether the task is running on its preferred > > LLC: Do not move a lone task to another LLC if it would move the task > > away from its preferred LLC or cause excessive imbalance between LLCs. > >=20 > > On the other hand, if the migration type is migrate_llc_task, it means > > that there are tasks on the env->src_cpu that want to be migrated to > > their preferred LLC, launch the active load balance anyway. >=20 > Nit: > But the check of migrate_llc_task is made after checking alb_break_llc > which seems to be contradicting. I understand that this check >=20 > env->src_rq->nr_pref_llc_running =3D=3D env->src_rq->cfs.h_nr_runnable >=20 > prevents alb_break_llc to return true when migrate_llc_task exists. Howev= er, > checking migrate_llc_task first would make the priority and intent more > explicit. We have actually considered that. Suppose we do migrate_llc_task check first, we still have to check that this migration will not cause load balance to go beyond the load imbalance we allow with can_migrate_llc(), i.e. do the same check as in alb_break_llc(). =C2=A0 Then for other kinds of task migration, we also need to check that those migrations don't break LLC policy with alb_break_llc(). So it is better to just do the alb_break_llc() check first to cover all migration types. It doesn't really help to save any code by moving migrate_llc_task check up. Tim >=20 > Thanks, > Vineeth >=20 > >=20 > > Co-developed-by: Chen Yu > > Signed-off-by: Chen Yu > > Signed-off-by: Tim Chen > > --- > >=20 > > Notes: > > v2->v3: > > Remove redundant rcu read lock in break_llc_locality(). > >=20 > > kernel/sched/fair.c | 54 ++++++++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 53 insertions(+), 1 deletion(-) > >=20 > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 1697791ef11c..03959a701514 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -9999,12 +9999,60 @@ static __maybe_unused enum llc_mig can_migrate_= llc_task(int src_cpu, int dst_cpu > > task_util(p), to_pref); > > } > > =20 > > +/* > > + * Check if active load balance breaks LLC locality in > > + * terms of cache aware load balance. > > + */ > > +static inline bool > > +alb_break_llc(struct lb_env *env) > > +{ > > + if (!sched_cache_enabled()) > > + return false; > > + > > + if (cpus_share_cache(env->src_cpu, env->dst_cpu)) > > + return false; > > + /* > > + * All tasks prefer to stay on their current CPU. > > + * Do not pull a task from its preferred CPU if: > > + * 1. It is the only task running there; OR > > + * 2. Migrating it away from its preferred LLC would violate > > + * the cache-aware scheduling policy. > > + */ > > + if (env->src_rq->nr_pref_llc_running && > > + env->src_rq->nr_pref_llc_running =3D=3D env->src_rq->cfs.h_nr_run= nable) { > > + unsigned long util =3D 0; > > + struct task_struct *cur; > > + > > + if (env->src_rq->nr_running <=3D 1) > > + return true; > > + > > + /* > > + * Reach here in load balance with > > + * rcu_read_lock() protected. > > + */ > > + cur =3D rcu_dereference(env->src_rq->curr); > > + if (cur) > > + util =3D task_util(cur); > > + > > + if (can_migrate_llc(env->src_cpu, env->dst_cpu, > > + util, false) =3D=3D mig_forbid) > > + return true; > > + } > > + > > + return false; > > +} > > #else > > static inline bool get_llc_stats(int cpu, unsigned long *util, > > unsigned long *cap) > > { > > return false; > > } > > + > > +static inline bool > > +alb_break_llc(struct lb_env *env) > > +{ > > + return false; > > +} > > #endif > > /* > > * can_migrate_task - may task p from runqueue rq be migrated to this_= cpu? > > @@ -12421,6 +12469,9 @@ static int need_active_balance(struct lb_env *e= nv) > > { > > struct sched_domain *sd =3D env->sd; > > =20 > > + if (alb_break_llc(env)) > > + return 0; > > + > > if (asym_active_balance(env)) > > return 1; > > =20 > > @@ -12440,7 +12491,8 @@ static int need_active_balance(struct lb_env *e= nv) > > return 1; > > } > > =20 > > - if (env->migration_type =3D=3D migrate_misfit) > > + if (env->migration_type =3D=3D migrate_misfit || > > + env->migration_type =3D=3D migrate_llc_task) > > return 1; > > =20 > > return 0; >=20