From nobody Mon May 25 00:09:00 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 718A33B992A; Wed, 20 May 2026 08:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266090; cv=none; b=ETRpOcRR8r9MUbnhaJqgsHRkpDO1LiL/+f2DQhexcQ2zVMBtPsR8Cy9dz+LL4at7FXhWkzHaFOqf0wkmDputbKqfOifa/1FQGX1l0kJFIsA2tbbSIO76aByHN/ZtvVUx+9PAd3UfTnoSdzYa5CXrjK03m3gb1HWwFe9nV9GviNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266090; c=relaxed/simple; bh=k8sE7ThZIgJJpZnXaSd/2LKo0aNQdxhR9LjqL/7apOA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=GuSV+FqKyRCZmZqrmt7IlmK9pp/bDz9VVSStis3Q8QIvwTr+3LjIgdNuXvF1vFadr+hKAiktiIL+NBU+hb63wYMM4+Z3EYdHgR+aq4hVciwMke9vuNOzTjBHDb+CVJuTVjwJMOWIs+qx1bRYl1X3SXSawesMU4ap2yn1p/fPd+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ohiY/EaV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q/346sPM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ohiY/EaV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q/346sPM" Date: Wed, 20 May 2026 08:34:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779266087; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FGhjUk5TVMkk1YNe8VCbbfhXX5iV7ZDDcaVMBptsfFs=; b=ohiY/EaVgjhjSu9125JgoLMk/wJ0uMlkqG/AapICzyS8O5mIOFHAjXT8AA0CM8edtoibpW GmYwJben387HXGnX4qdmZBx2GG9zWL6boo/HEcfSrQFqNjriUy6lVmVzj+6G3TFMCGb927 wZ9gihi4z+navO7acHU3hpdczIn64ItKuBMRzLUvLaxU0gZVatRvkor5XPNG+Dl7C/+Ca4 mvUrUGKHtkKGjiEX1HTmWtxPlfTLjL+7Zwwbqi9+ZdsMJj8/SEx0DpITFoVMlK+0n1korV rHS+d45u/6J4vpZGoSM0Vm4rEVvdRZH1pBj3eujCDcTUpQS8ql1/fRxEaC9ujA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779266087; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FGhjUk5TVMkk1YNe8VCbbfhXX5iV7ZDDcaVMBptsfFs=; b=Q/346sPMf4kU5gFvQjY8ft1uCXBJ8r1Y4neFJFBgP7TYabLuC/bR9J17NQu0ZjgIMACcM1 K12A/B6q3DfUmOAA== From: "tip-bot2 for Tim Chen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cache: Handle moving single tasks to/from their preferred LLC Cc: Chen Yu , Tim Chen , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C9b816d8c27fabf2a9c0e1f61a6b90afe8ec4ad52=2E1775065?= =?utf-8?q?312=2Egit=2Etim=2Ec=2Echen=40linux=2Eintel=2Ecom=3E?= References: =?utf-8?q?=3C9b816d8c27fabf2a9c0e1f61a6b90afe8ec4ad52=2E17750653?= =?utf-8?q?12=2Egit=2Etim=2Ec=2Echen=40linux=2Eintel=2Ecom=3E?= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926608579.711.15850542732021703090.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 714059f79ff0ba976cb75360064583c78bbc6f8e Gitweb: https://git.kernel.org/tip/714059f79ff0ba976cb75360064583c78= bbc6f8e Author: Tim Chen AuthorDate: Wed, 01 Apr 2026 14:52:26 -07:00 Committer: Peter Zijlstra CommitterDate: Thu, 09 Apr 2026 15:49:51 +02:00 sched/cache: Handle moving single tasks to/from their preferred LLC Cache aware scheduling mainly does two things: 1. Prevent task from migrating out of its preferred LLC if not nessasary. 2. Migrating task to their preferred LLC if nessasary. For 1: In the generic load balance, if the busiest runqueue has only one task, active balancing may be invoked to move it away. However, this migration might break LLC locality. Prevent regular load balance from migrating a task that prefers the current LLC. The load level and imbalance do not warrant breaking LLC preference per the can_migrate_llc() policy. Here, the benefit of LLC locality outweighs the power efficiency gained from migrating the only runnable task away. 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. For 2: 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. Co-developed-by: Chen Yu Signed-off-by: Chen Yu Signed-off-by: Tim Chen Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/9b816d8c27fabf2a9c0e1f61a6b90afe8ec4ad52.177= 5065312.git.tim.c.chen@linux.intel.com --- kernel/sched/fair.c | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 68032ef..bfb6c0c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10293,12 +10293,60 @@ static __maybe_unused enum llc_mig can_migrate_ll= c_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. The load level and + * imbalance do not warrant breaking LLC preference per + * the can_migrate_llc() policy. Here, the benefit of + * LLC locality outweighs the power efficiency gained from + * migrating the only runnable task away. + */ +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(not too imbalance); 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_runnabl= e) { + unsigned long util =3D 0; + struct task_struct *cur; + + if (env->src_rq->nr_running <=3D 1) + return true; + + cur =3D rcu_dereference_all(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? @@ -12698,6 +12746,9 @@ static int need_active_balance(struct lb_env *env) { struct sched_domain *sd =3D env->sd; =20 + if (alb_break_llc(env)) + return 0; + if (asym_active_balance(env)) return 1; =20 @@ -12717,7 +12768,8 @@ static int need_active_balance(struct lb_env *env) 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;