mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: avoid creating misfits during cache-aware balancing
@ 2026-08-25 17:41 Tim Chen
  2026-08-26 15:57 ` Tim Chen
  2026-08-31  8:41 ` Peter Zijlstra
  0 siblings, 2 replies; 6+ messages in thread
From: Tim Chen @ 2026-08-25 17:41 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: Tim Chen, K Prateek Nayak, Vincent Guittot, Chen Yu,
	Ricardo Neri, Len Brown, Aubrey Li, linux-kernel, Ricardo Neri

Cache-aware load balancing biases tasks toward their preferred LLC. On
asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
contain CPUs that are too small to run the task. Pulling the task there
turns it into a misfit, trading a cache-locality gain for a capacity loss
that's more detrimental to performance.

Guard both cache-aware migration entry points against this:

 - can_migrate_llc_task(): forbid the LLC migration when the task fits its
   source CPU but would not fit the destination CPU.
 - alb_break_llc(): veto the active balance under the same condition so the
   runnable task is not pushed onto a CPU that cannot accommodate it.

Both checks are gated with checks for hybrid processors, so symmetric
systems are unaffected. Tasks that already do not fit their source CPU
are left to the existing LLC policy, since the move cannot make their
fitness worse (this also preserves misfit up-migration to bigger CPUs).

Additionally, if there are misfit tasks found in the load balancing
classification phase, prioritize misfit task migrations
over LLC load aggregation on asymmetric systems. A better fitting
CPU will boost performance more than better cache locality.

Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
---
 kernel/sched/fair.c | 50 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6d881e530f89..cf5c022bbd55 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu,
 	return mig_llc;
 }
 
+static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p)
+{
+	/*
+	 * On asymmetric CPU capacity domains, do not let cache-aware
+	 * balancing pull the task onto a destination CPU that cannot
+	 * accommodate it. Doing so would turn the task into a misfit on
+	 * the destination, trading a cache-locality gain for a capacity
+	 * loss. If the task already does not fit its source CPU, the move
+	 * cannot make things worse, so let the LLC preference decide.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p &&
+	    !task_fits_cpu(p, env->dst_cpu) &&
+	    task_fits_cpu(p, env->src_cpu))
+		return true;
+
+	return false;
+}
+
 /*
  * Check if task p can migrate from source LLC to
  * destination LLC in terms of cache aware load balance.
  */
-static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
+static enum llc_mig can_migrate_llc_task(struct lb_env *env,
 					 struct task_struct *p)
 {
 	struct mm_struct *mm;
 	bool to_pref;
-	int cpu;
+	int cpu, src_cpu, dst_cpu;
+
+	if (task_misfits_asym_cpu(env, p))
+		return mig_forbid;
 
+	src_cpu = env->src_cpu;
+	dst_cpu = env->dst_cpu;
 	mm = p->mm;
 	if (!mm)
 		return mig_unrestricted;
@@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env)
 		unsigned long util = 0;
 		struct task_struct *cur;
 
+		/*
+		 * Migrating misfit tasks from current CPU
+		 * to CPU with a better fit.
+		 * Prioritize that over LLC preference.
+		 */
+		if (env->migration_type == migrate_misfit)
+			return false;
+
 		if (env->src_rq->nr_running <= 1)
 			return true;
 
@@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env)
 		if (cur && cur->sched_class == &fair_sched_class)
 			util = task_util(cur);
 
-		if (can_migrate_llc(env->src_cpu, env->dst_cpu,
+		if (task_misfits_asym_cpu(env, cur) ||
+		    can_migrate_llc(env->src_cpu, env->dst_cpu,
 				    util, false) == mig_forbid)
 			return true;
 	}
@@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
 	    READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu))
 		return true;
 
-	if (can_migrate_llc_task(env->src_cpu,
-				 env->dst_cpu, p) != mig_forbid)
+	if (can_migrate_llc_task(env, p) != mig_forbid)
 		return false;
 
 	return true;
@@ -11869,6 +11900,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs,
 	if (env->sd->flags & SD_SHARE_LLC)
 		return false;
 
+	/*
+	 * On asymmetric domains, group_misfit_task_load
+	 * should be prioritized to move tasks to CPU that fit them
+	 * over aggregating tasks to their preferred LLC.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
+	    sgs->group_misfit_task_load)
+		return false;
+
 	/*
 	 * Skip cache aware tagging if nr_balanced_failed is sufficiently high.
 	 * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed
-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/fair: avoid creating misfits during cache-aware balancing
  2026-08-25 17:41 [PATCH] sched/fair: avoid creating misfits during cache-aware balancing Tim Chen
@ 2026-08-26 15:57 ` Tim Chen
  2026-08-31  8:41 ` Peter Zijlstra
  1 sibling, 0 replies; 6+ messages in thread
From: Tim Chen @ 2026-08-26 15:57 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: K Prateek Nayak, Vincent Guittot, Chen Yu, Ricardo Neri,
	Len Brown, Aubrey Li, linux-kernel, Ricardo Neri

On Tue, 2026-08-25 at 10:41 -0700, Tim Chen wrote:
> Cache-aware load balancing biases tasks toward their preferred LLC. On
> asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
> contain CPUs that are too small to run the task. Pulling the task there
> turns it into a misfit, trading a cache-locality gain for a capacity loss
> that's more detrimental to performance.
> 
> Guard both cache-aware migration entry points against this:
> 
>  - can_migrate_llc_task(): forbid the LLC migration when the task fits its
>    source CPU but would not fit the destination CPU.
>  - alb_break_llc(): veto the active balance under the same condition so the
>    runnable task is not pushed onto a CPU that cannot accommodate it.
> 
> Both checks are gated with checks for hybrid processors, so symmetric
> systems are unaffected. Tasks that already do not fit their source CPU
> are left to the existing LLC policy, since the move cannot make their
> fitness worse (this also preserves misfit up-migration to bigger CPUs).
> 
> Additionally, if there are misfit tasks found in the load balancing
> classification phase, prioritize misfit task migrations
> over LLC load aggregation on asymmetric systems. A better fitting
> CPU will boost performance more than better cache locality.
> 
> Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> Reviewed-by: Chen Yu <yu.c.chen@intel.com>

Forgot my signed off

Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>

Tim
> ---
>  kernel/sched/fair.c | 50 ++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 45 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 6d881e530f89..cf5c022bbd55 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu,
>  	return mig_llc;
>  }
>  
> +static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p)
> +{
> +	/*
> +	 * On asymmetric CPU capacity domains, do not let cache-aware
> +	 * balancing pull the task onto a destination CPU that cannot
> +	 * accommodate it. Doing so would turn the task into a misfit on
> +	 * the destination, trading a cache-locality gain for a capacity
> +	 * loss. If the task already does not fit its source CPU, the move
> +	 * cannot make things worse, so let the LLC preference decide.
> +	 */
> +	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p &&
> +	    !task_fits_cpu(p, env->dst_cpu) &&
> +	    task_fits_cpu(p, env->src_cpu))
> +		return true;
> +
> +	return false;
> +}
> +
>  /*
>   * Check if task p can migrate from source LLC to
>   * destination LLC in terms of cache aware load balance.
>   */
> -static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
> +static enum llc_mig can_migrate_llc_task(struct lb_env *env,
>  					 struct task_struct *p)
>  {
>  	struct mm_struct *mm;
>  	bool to_pref;
> -	int cpu;
> +	int cpu, src_cpu, dst_cpu;
> +
> +	if (task_misfits_asym_cpu(env, p))
> +		return mig_forbid;
>  
> +	src_cpu = env->src_cpu;
> +	dst_cpu = env->dst_cpu;
>  	mm = p->mm;
>  	if (!mm)
>  		return mig_unrestricted;
> @@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env)
>  		unsigned long util = 0;
>  		struct task_struct *cur;
>  
> +		/*
> +		 * Migrating misfit tasks from current CPU
> +		 * to CPU with a better fit.
> +		 * Prioritize that over LLC preference.
> +		 */
> +		if (env->migration_type == migrate_misfit)
> +			return false;
> +
>  		if (env->src_rq->nr_running <= 1)
>  			return true;
>  
> @@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env)
>  		if (cur && cur->sched_class == &fair_sched_class)
>  			util = task_util(cur);
>  
> -		if (can_migrate_llc(env->src_cpu, env->dst_cpu,
> +		if (task_misfits_asym_cpu(env, cur) ||
> +		    can_migrate_llc(env->src_cpu, env->dst_cpu,
>  				    util, false) == mig_forbid)
>  			return true;
>  	}
> @@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
>  	    READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu))
>  		return true;
>  
> -	if (can_migrate_llc_task(env->src_cpu,
> -				 env->dst_cpu, p) != mig_forbid)
> +	if (can_migrate_llc_task(env, p) != mig_forbid)
>  		return false;
>  
>  	return true;
> @@ -11869,6 +11900,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs,
>  	if (env->sd->flags & SD_SHARE_LLC)
>  		return false;
>  
> +	/*
> +	 * On asymmetric domains, group_misfit_task_load
> +	 * should be prioritized to move tasks to CPU that fit them
> +	 * over aggregating tasks to their preferred LLC.
> +	 */
> +	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
> +	    sgs->group_misfit_task_load)
> +		return false;
> +
>  	/*
>  	 * Skip cache aware tagging if nr_balanced_failed is sufficiently high.
>  	 * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/fair: avoid creating misfits during cache-aware balancing
  2026-08-25 17:41 [PATCH] sched/fair: avoid creating misfits during cache-aware balancing Tim Chen
  2026-08-26 15:57 ` Tim Chen
@ 2026-08-31  8:41 ` Peter Zijlstra
  2026-08-31 17:17   ` Tim Chen
  2026-08-31 17:40   ` Tim Chen
  1 sibling, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2026-08-31  8:41 UTC (permalink / raw)
  To: Tim Chen
  Cc: Ingo Molnar, K Prateek Nayak, Vincent Guittot, Chen Yu,
	Ricardo Neri, Len Brown, Aubrey Li, linux-kernel, Ricardo Neri

On Tue, Aug 25, 2026 at 10:41:12AM -0700, Tim Chen wrote:
> Cache-aware load balancing biases tasks toward their preferred LLC. On
> asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
> contain CPUs that are too small to run the task. Pulling the task there
> turns it into a misfit, trading a cache-locality gain for a capacity loss
> that's more detrimental to performance.
> 
> Guard both cache-aware migration entry points against this:
> 
>  - can_migrate_llc_task(): forbid the LLC migration when the task fits its
>    source CPU but would not fit the destination CPU.
>  - alb_break_llc(): veto the active balance under the same condition so the
>    runnable task is not pushed onto a CPU that cannot accommodate it.
> 
> Both checks are gated with checks for hybrid processors, so symmetric
> systems are unaffected. Tasks that already do not fit their source CPU
> are left to the existing LLC policy, since the move cannot make their
> fitness worse (this also preserves misfit up-migration to bigger CPUs).
> 
> Additionally, if there are misfit tasks found in the load balancing
> classification phase, prioritize misfit task migrations
> over LLC load aggregation on asymmetric systems. A better fitting
> CPU will boost performance more than better cache locality.
> 
> Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> Reviewed-by: Chen Yu <yu.c.chen@intel.com>

Tim sends patch, Tim adds SoB, yes?

Also, we start $subject with capital after subsystem: part.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/fair: avoid creating misfits during cache-aware balancing
  2026-08-31  8:41 ` Peter Zijlstra
@ 2026-08-31 17:17   ` Tim Chen
  2026-08-31 17:40   ` Tim Chen
  1 sibling, 0 replies; 6+ messages in thread
From: Tim Chen @ 2026-08-31 17:17 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, K Prateek Nayak, Vincent Guittot, Chen Yu,
	Ricardo Neri, Len Brown, Aubrey Li, linux-kernel, Ricardo Neri

On Mon, 2026-08-31 at 10:41 +0200, Peter Zijlstra wrote:
> On Tue, Aug 25, 2026 at 10:41:12AM -0700, Tim Chen wrote:
> > Cache-aware load balancing biases tasks toward their preferred LLC. On
> > asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
> > contain CPUs that are too small to run the task. Pulling the task there
> > turns it into a misfit, trading a cache-locality gain for a capacity loss
> > that's more detrimental to performance.
> > 
> > Guard both cache-aware migration entry points against this:
> > 
> >  - can_migrate_llc_task(): forbid the LLC migration when the task fits its
> >    source CPU but would not fit the destination CPU.
> >  - alb_break_llc(): veto the active balance under the same condition so the
> >    runnable task is not pushed onto a CPU that cannot accommodate it.
> > 
> > Both checks are gated with checks for hybrid processors, so symmetric
> > systems are unaffected. Tasks that already do not fit their source CPU
> > are left to the existing LLC policy, since the move cannot make their
> > fitness worse (this also preserves misfit up-migration to bigger CPUs).
> > 
> > Additionally, if there are misfit tasks found in the load balancing
> > classification phase, prioritize misfit task migrations
> > over LLC load aggregation on asymmetric systems. A better fitting
> > CPU will boost performance more than better cache locality.
> > 
> > Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > Reviewed-by: Chen Yu <yu.c.chen@intel.com>
> 
> Tim sends patch, Tim adds SoB, yes?

Yeah, I forgot to add my SoB.  Added that in a followed up email.

> 
> Also, we start $subject with capital after subsystem: part.

Sorry about that.  Let me know if you prefer me send an updated
patch with those corrected.

Thanks.

Tim

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/fair: avoid creating misfits during cache-aware balancing
  2026-08-31  8:41 ` Peter Zijlstra
  2026-08-31 17:17   ` Tim Chen
@ 2026-08-31 17:40   ` Tim Chen
  2026-09-02  7:21     ` [tip: sched/urgent] sched/fair: Avoid " tip-bot2 for Tim Chen
  1 sibling, 1 reply; 6+ messages in thread
From: Tim Chen @ 2026-08-31 17:40 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, K Prateek Nayak, Vincent Guittot, Chen Yu,
	Ricardo Neri, Len Brown, Aubrey Li, linux-kernel, Ricardo Neri

On Mon, 2026-08-31 at 10:41 +0200, Peter Zijlstra wrote:
> On Tue, Aug 25, 2026 at 10:41:12AM -0700, Tim Chen wrote:
> > Cache-aware load balancing biases tasks toward their preferred LLC. On
> > asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
> > contain CPUs that are too small to run the task. Pulling the task there
> > turns it into a misfit, trading a cache-locality gain for a capacity loss
> > that's more detrimental to performance.
> > 
> > Guard both cache-aware migration entry points against this:
> > 
> >  - can_migrate_llc_task(): forbid the LLC migration when the task fits its
> >    source CPU but would not fit the destination CPU.
> >  - alb_break_llc(): veto the active balance under the same condition so the
> >    runnable task is not pushed onto a CPU that cannot accommodate it.
> > 
> > Both checks are gated with checks for hybrid processors, so symmetric
> > systems are unaffected. Tasks that already do not fit their source CPU
> > are left to the existing LLC policy, since the move cannot make their
> > fitness worse (this also preserves misfit up-migration to bigger CPUs).
> > 
> > Additionally, if there are misfit tasks found in the load balancing
> > classification phase, prioritize misfit task migrations
> > over LLC load aggregation on asymmetric systems. A better fitting
> > CPU will boost performance more than better cache locality.
> > 
> > Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > Reviewed-by: Chen Yu <yu.c.chen@intel.com>
> 
> Tim sends patch, Tim adds SoB, yes?
> 
> Also, we start $subject with capital after subsystem: part.

Here is the patch updated with the fixes.

Thanks.

Tim

---

From d28acbf5a7f30125a7f15d85bf77b8e4b6e8bfc5 Mon Sep 17 00:00:00 2001
Message-Id: <d28acbf5a7f30125a7f15d85bf77b8e4b6e8bfc5.1788198279.git.tim.c.chen@linux.intel.com>
From: Tim Chen <tim.c.chen@linux.intel.com>
Date: Wed, 19 Aug 2026 13:03:56 -0700
Subject: [PATCH] sched/fair: Avoid creating misfits during cache-aware
 balancing
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>, Vincent Guittot <vincent.guittot@linaro.org>, Chen Yu <yu.c.chen@intel.com>, Ricardo Neri <ricardo.neri@intel.com>, Len Brown <len.brown@intel.com>,
Aubrey Li <aubrey.li@intel.com>, linux-kernel@vger.kernel.org

Cache-aware load balancing biases tasks toward their preferred LLC. On
asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
contain CPUs that are too small to run the task. Pulling the task there
turns it into a misfit, trading a cache-locality gain for a capacity loss
that's more detrimental to performance.

Guard both cache-aware migration entry points against this:

 - can_migrate_llc_task(): forbid the LLC migration when the task fits its
   source CPU but would not fit the destination CPU.
 - alb_break_llc(): veto the active balance under the same condition so the
   runnable task is not pushed onto a CPU that cannot accommodate it.

Both checks are gated with checks for hybrid processors, so symmetric
systems are unaffected. Tasks that already do not fit their source CPU
are left to the existing LLC policy, since the move cannot make their
fitness worse (this also preserves misfit up-migration to bigger CPUs).

Additionally, if there are misfit tasks found in the load balancing
classification phase, prioritize misfit task migrations
over LLC load aggregation on asymmetric systems. A better fitting
CPU will boost performance more than better cache locality.

Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
 kernel/sched/fair.c | 50 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6d881e530f89..cf5c022bbd55 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu,
 	return mig_llc;
 }
 
+static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p)
+{
+	/*
+	 * On asymmetric CPU capacity domains, do not let cache-aware
+	 * balancing pull the task onto a destination CPU that cannot
+	 * accommodate it. Doing so would turn the task into a misfit on
+	 * the destination, trading a cache-locality gain for a capacity
+	 * loss. If the task already does not fit its source CPU, the move
+	 * cannot make things worse, so let the LLC preference decide.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p &&
+	    !task_fits_cpu(p, env->dst_cpu) &&
+	    task_fits_cpu(p, env->src_cpu))
+		return true;
+
+	return false;
+}
+
 /*
  * Check if task p can migrate from source LLC to
  * destination LLC in terms of cache aware load balance.
  */
-static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
+static enum llc_mig can_migrate_llc_task(struct lb_env *env,
 					 struct task_struct *p)
 {
 	struct mm_struct *mm;
 	bool to_pref;
-	int cpu;
+	int cpu, src_cpu, dst_cpu;
+
+	if (task_misfits_asym_cpu(env, p))
+		return mig_forbid;
 
+	src_cpu = env->src_cpu;
+	dst_cpu = env->dst_cpu;
 	mm = p->mm;
 	if (!mm)
 		return mig_unrestricted;
@@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env)
 		unsigned long util = 0;
 		struct task_struct *cur;
 
+		/*
+		 * Migrating misfit tasks from current CPU
+		 * to CPU with a better fit.
+		 * Prioritize that over LLC preference.
+		 */
+		if (env->migration_type == migrate_misfit)
+			return false;
+
 		if (env->src_rq->nr_running <= 1)
 			return true;
 
@@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env)
 		if (cur && cur->sched_class == &fair_sched_class)
 			util = task_util(cur);
 
-		if (can_migrate_llc(env->src_cpu, env->dst_cpu,
+		if (task_misfits_asym_cpu(env, cur) ||
+		    can_migrate_llc(env->src_cpu, env->dst_cpu,
 				    util, false) == mig_forbid)
 			return true;
 	}
@@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
 	    READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu))
 		return true;
 
-	if (can_migrate_llc_task(env->src_cpu,
-				 env->dst_cpu, p) != mig_forbid)
+	if (can_migrate_llc_task(env, p) != mig_forbid)
 		return false;
 
 	return true;
@@ -11869,6 +11900,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs,
 	if (env->sd->flags & SD_SHARE_LLC)
 		return false;
 
+	/*
+	 * On asymmetric domains, group_misfit_task_load
+	 * should be prioritized to move tasks to CPU that fit them
+	 * over aggregating tasks to their preferred LLC.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
+	    sgs->group_misfit_task_load)
+		return false;
+
 	/*
 	 * Skip cache aware tagging if nr_balanced_failed is sufficiently high.
 	 * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed
-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: sched/urgent] sched/fair: Avoid creating misfits during cache-aware balancing
  2026-08-31 17:40   ` Tim Chen
@ 2026-09-02  7:21     ` tip-bot2 for Tim Chen
  0 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Tim Chen @ 2026-09-02  7:21 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ricardo Neri, Chen Yu, Tim Chen, Peter Zijlstra (Intel),
	x86, linux-kernel

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     f0d243a96f2684ad771d678767d17972cf840bd7
Gitweb:        https://git.kernel.org/tip/f0d243a96f2684ad771d678767d17972cf840bd7
Author:        Tim Chen <tim.c.chen@linux.intel.com>
AuthorDate:    Mon, 31 Aug 2026 10:40:53 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 02 Sep 2026 09:17:50 +02:00

sched/fair: Avoid creating misfits during cache-aware balancing

Cache-aware load balancing biases tasks toward their preferred LLC. On
asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may
contain CPUs that are too small to run the task. Pulling the task there
turns it into a misfit, trading a cache-locality gain for a capacity loss
that's more detrimental to performance.

Guard both cache-aware migration entry points against this:

 - can_migrate_llc_task(): forbid the LLC migration when the task fits its
   source CPU but would not fit the destination CPU.
 - alb_break_llc(): veto the active balance under the same condition so the
   runnable task is not pushed onto a CPU that cannot accommodate it.

Both checks are gated with checks for hybrid processors, so symmetric
systems are unaffected. Tasks that already do not fit their source CPU
are left to the existing LLC policy, since the move cannot make their
fitness worse (this also preserves misfit up-migration to bigger CPUs).

Additionally, if there are misfit tasks found in the load balancing
classification phase, prioritize misfit task migrations
over LLC load aggregation on asymmetric systems. A better fitting
CPU will boost performance more than better cache locality.

Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/edbb2503d554c63dc9b72e201fb4a17e1cb119e7.camel@linux.intel.com
---
 kernel/sched/fair.c | 50 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 97021a5..ade1ece 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu,
 	return mig_llc;
 }
 
+static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p)
+{
+	/*
+	 * On asymmetric CPU capacity domains, do not let cache-aware
+	 * balancing pull the task onto a destination CPU that cannot
+	 * accommodate it. Doing so would turn the task into a misfit on
+	 * the destination, trading a cache-locality gain for a capacity
+	 * loss. If the task already does not fit its source CPU, the move
+	 * cannot make things worse, so let the LLC preference decide.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p &&
+	    !task_fits_cpu(p, env->dst_cpu) &&
+	    task_fits_cpu(p, env->src_cpu))
+		return true;
+
+	return false;
+}
+
 /*
  * Check if task p can migrate from source LLC to
  * destination LLC in terms of cache aware load balance.
  */
-static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
+static enum llc_mig can_migrate_llc_task(struct lb_env *env,
 					 struct task_struct *p)
 {
 	struct mm_struct *mm;
 	bool to_pref;
-	int cpu;
+	int cpu, src_cpu, dst_cpu;
+
+	if (task_misfits_asym_cpu(env, p))
+		return mig_forbid;
 
+	src_cpu = env->src_cpu;
+	dst_cpu = env->dst_cpu;
 	mm = p->mm;
 	if (!mm)
 		return mig_unrestricted;
@@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env)
 		unsigned long util = 0;
 		struct task_struct *cur;
 
+		/*
+		 * Migrating misfit tasks from current CPU
+		 * to CPU with a better fit.
+		 * Prioritize that over LLC preference.
+		 */
+		if (env->migration_type == migrate_misfit)
+			return false;
+
 		if (env->src_rq->nr_running <= 1)
 			return true;
 
@@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env)
 		if (cur && cur->sched_class == &fair_sched_class)
 			util = task_util(cur);
 
-		if (can_migrate_llc(env->src_cpu, env->dst_cpu,
+		if (task_misfits_asym_cpu(env, cur) ||
+		    can_migrate_llc(env->src_cpu, env->dst_cpu,
 				    util, false) == mig_forbid)
 			return true;
 	}
@@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
 	    READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu))
 		return true;
 
-	if (can_migrate_llc_task(env->src_cpu,
-				 env->dst_cpu, p) != mig_forbid)
+	if (can_migrate_llc_task(env, p) != mig_forbid)
 		return false;
 
 	return true;
@@ -11870,6 +11901,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs,
 		return false;
 
 	/*
+	 * On asymmetric domains, group_misfit_task_load
+	 * should be prioritized to move tasks to CPU that fit them
+	 * over aggregating tasks to their preferred LLC.
+	 */
+	if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
+	    sgs->group_misfit_task_load)
+		return false;
+
+	/*
 	 * Skip cache aware tagging if nr_balanced_failed is sufficiently high.
 	 * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed
 	 * to avoid excessive task migration at the same time.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-02  7:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25 17:41 [PATCH] sched/fair: avoid creating misfits during cache-aware balancing Tim Chen
2026-08-26 15:57 ` Tim Chen
2026-08-31  8:41 ` Peter Zijlstra
2026-08-31 17:17   ` Tim Chen
2026-08-31 17:40   ` Tim Chen
2026-09-02  7:21     ` [tip: sched/urgent] sched/fair: Avoid " tip-bot2 for Tim Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®