From nobody Thu Apr 2 17:02:05 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 35F4733B6D3 for ; Tue, 10 Feb 2026 22:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761613; cv=none; b=lk5MdHYVwPvEAxRUxjjnLyU8eZm/aw1HrlY67y2jMliVs1TKRGvJNdrMex+/ou5rB8pWUDHYsOEWGCWWiqWm7Y36Brw1+YIF1O9rOlpSxbDYLTEp51CQ4Z8qpi5f5xbl3NQKQFkAA686/G7sg0QvG8Q/lMNlnHcvKGCTUsUpVe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761613; c=relaxed/simple; bh=Sp3CApwES6LZ8wznsuorYrIR44CICnE+yAXXfi436d0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pEZDNKCxmNotKlUXdwAQ+KzBiKf/Z7Y51298bvHQV3Gl2leBgy5SYxkpfoUbBEnBn1OfVeAdIXqNMN/4pQ38o9G1F8yzRTOd+lsVXk357BqC2n0dqWe4mxvMl/ylc+V35zjiMWuEVF6dwcvXYXTi9o7DJXnIEvFmgx2q+ksitVM= 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=dbU0w3sc; arc=none smtp.client-ip=192.198.163.9 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="dbU0w3sc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770761612; x=1802297612; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sp3CApwES6LZ8wznsuorYrIR44CICnE+yAXXfi436d0=; b=dbU0w3scI28x8xgP1OsFEnOnOSkfQgZFnBbG60v7xb6s0m5f0eRyYecS RLBKA33qal+fb+ImbzNSVaXDN151KwTXloCH0sM6hyHGthq9Qg4rmE3nP 5RgBeLIX8VQnD3EdYqxmmDP3eJ+RUx8CI0hdPD4fHDHRjQwMOalJ3eIMJ WceAvccOSNCRnkZ4dsKbT8e5fSbmVbN8pUhznZFHigqWvBtmoovhNXSOD RKqORiE1pARQqgI3OFX39acsOwGqjN+l3pIVKpAsNABgTsXssZgwu0Sjy Q7yWwbp9vFi0PLyDbssW/67XYMBcMbd7E0rdZro8wIiRGxTn7iF010bwl A==; X-CSE-ConnectionGUID: a+0EVXeTTqq5hO8JZ+Wxvg== X-CSE-MsgGUID: 1qYXTk7RSk+b8S3Pj2aNcA== X-IronPort-AV: E=McAfee;i="6800,10657,11697"; a="82631485" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="82631485" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2026 14:13:31 -0800 X-CSE-ConnectionGUID: XP3ymKcFRS2pztVOCTB5Hw== X-CSE-MsgGUID: GLjdOTeEQdu1Z++BmJyQSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="216373986" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by fmviesa004.fm.intel.com with ESMTP; 10 Feb 2026 14:13:30 -0800 From: Tim Chen To: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot Cc: Tim Chen , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , 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 Subject: [PATCH v3 13/21] sched/cache: Handle moving single tasks to/from their preferred LLC Date: Tue, 10 Feb 2026 14:18:53 -0800 Message-Id: <92fa33fc26f069d8044bac3b0efc3598f53131de.1770760558.git.tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. 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. 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 --- Notes: v2->v3: Remove redundant rcu read lock in break_llc_locality(). 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 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_runnabl= e) { + 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 *env) { 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 *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; --=20 2.32.0