From nobody Thu Apr 2 16:58:53 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 85041355033 for ; Tue, 10 Feb 2026 22:13:34 +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=1770761615; cv=none; b=b3o1n/cP++SPpH1qPMo3bQFAeO6/e6kbkxVHNMSobSKYN+7XCULzztII746yVSbYCaIZjFBXxLFRkqs9AwzLXdC3bMuFRMr8/82YtorIf1VaZVjjkLA+bNqIUbKzysC4oGbSAVW1R9AkSst6KoGO4YhWnzpXCMglkcEDoP4lYWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761615; c=relaxed/simple; bh=tYv2iHyag5NKSPeYQKd4k8stcZ7hWz9Pzz005OH/eMI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GQOCk2B67DTBvv6LH6XV7tzB4uO80JvzPDDFSv9PW+MJSC3Kse9eVIdC3YN+QCQ1PfzAqmYxOFbHqUe1VkdQLcVYuNO1plkmqd9B5B1rIl7baQHTDAyJvQETGWLgiaEZvkvRf/Gj2TSS9LIm3gkLLOQX3M8ugBczbmhbuHFNutc= 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=Dn4F0W/w; 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="Dn4F0W/w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770761614; x=1802297614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tYv2iHyag5NKSPeYQKd4k8stcZ7hWz9Pzz005OH/eMI=; b=Dn4F0W/wxOycB1W3oNIstnIL1NK3/w/hG1+9QHEu2iG1mJJxUuSY4qC8 oCHXEAg8R/8bGRmqk5KMmWVOlpsF13dnelPUcQgpy5lHeKWHa1yzHoO4p 5zc4rVi6Lj1j1+K1FfSbcloy+Y/EbF/f81OZtTanFlI95LHi9mPZOdK8u ThkbMMWLMuZ1lfH9f9gE7gbe3DIFbBGOwdfyft3Fvmz9+jDGJ04UdEzDF 9y64emCRuwTyW4kLf9cu1eEMRBLyri/5aLg7kIm7UEzX9C5R10WFKEoPR eKDWgJLU4Phi39hIsoy6GoqucyWEnkNeq1EWJAn7dacDgqrYbYu6acCub Q==; X-CSE-ConnectionGUID: KAZJi8v8Qxavym9c30i3aw== X-CSE-MsgGUID: GvzSXcoJSQGz74f+BBWbLQ== X-IronPort-AV: E=McAfee;i="6800,10657,11697"; a="82631505" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="82631505" 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:34 -0800 X-CSE-ConnectionGUID: ADAxB+eRTjKPH1xcLvfBDQ== X-CSE-MsgGUID: JDVcTB7EQw2uF/CBovIwBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="216374007" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by fmviesa004.fm.intel.com with ESMTP; 10 Feb 2026 14:13:32 -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 14/21] sched/cache: Respect LLC preference in task migration and detach Date: Tue, 10 Feb 2026 14:18:54 -0800 Message-Id: <82aeb78bbfb80cb6861b85e4db9d398f6c8e331b.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" During the final step of load balancing, can_migrate_task() now considers a task's LLC preference before moving it out of its preferred LLC. Suggested-by: Peter Zijlstra (Intel) Suggested-by: K Prateek Nayak Co-developed-by: Chen Yu Signed-off-by: Chen Yu Signed-off-by: Tim Chen --- Notes: v2->v3: Use the similar mechanism as NUMA balancing, which skips over the tasks that would degrade locality in can_migrate_task(); and only if nr_balanced_failed is high enough do we ignore that. (Peter Zijlstra) =20 Let migrate_degrade_locality() take precedence over migrate_degrades_llc(), which aims to migrate towards the preferred NUMA node. (Peter Zijlstra) kernel/sched/fair.c | 64 +++++++++++++++++++++++++++++++++++++++++--- kernel/sched/sched.h | 13 +++++++++ 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 03959a701514..d1145997b88d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9973,8 +9973,8 @@ static enum llc_mig can_migrate_llc(int src_cpu, int = dst_cpu, * Check if task p can migrate from source LLC to * destination LLC in terms of cache aware load balance. */ -static __maybe_unused enum llc_mig can_migrate_llc_task(int src_cpu, int d= st_cpu, - struct task_struct *p) +static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu, + struct task_struct *p) { struct mm_struct *mm; bool to_pref; @@ -10041,6 +10041,47 @@ alb_break_llc(struct lb_env *env) =20 return false; } + +/* + * Check if migrating task p from env->src_cpu to + * env->dst_cpu breaks LLC localiy. + */ +static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env) +{ + if (!sched_cache_enabled()) + return false; + + if (task_has_sched_core(p)) + return false; + /* + * Skip over tasks that would degrade LLC locality; + * only when nr_balanced_failed is sufficiently high do we + * ignore this constraint. + * + * Threshold of cache_nice_tries is set to 1 higher + * than nr_balance_failed to avoid excessive task + * migration at the same time. Refer to comments around + * llc_balance(). + */ + if (env->sd->nr_balance_failed >=3D env->sd->cache_nice_tries + 1) + return false; + + /* + * We know the env->src_cpu has some tasks prefer to + * run on env->dst_cpu, skip the tasks do not prefer + * env->dst_cpu, and find the one that prefers. + */ + if (env->migration_type =3D=3D migrate_llc_task && + task_llc(p) !=3D llc_id(env->dst_cpu)) + return true; + + if (can_migrate_llc_task(env->src_cpu, + env->dst_cpu, p) !=3D mig_forbid) + return false; + + return true; +} + #else static inline bool get_llc_stats(int cpu, unsigned long *util, unsigned long *cap) @@ -10053,6 +10094,12 @@ alb_break_llc(struct lb_env *env) { return false; } + +static inline bool +migrate_degrades_llc(struct task_struct *p, struct lb_env *env) +{ + return false; +} #endif /* * can_migrate_task - may task p from runqueue rq be migrated to this_cpu? @@ -10150,10 +10197,19 @@ int can_migrate_task(struct task_struct *p, struc= t lb_env *env) return 1; =20 degrades =3D migrate_degrades_locality(p, env); - if (!degrades) + if (!degrades) { + /* + * If the NUMA locality is not broken, + * further check if migration would hurt + * LLC locality. + */ + if (migrate_degrades_llc(p, env)) + return 0; + hot =3D task_hot(p, env); - else + } else { hot =3D degrades > 0; + } =20 if (!hot || env->sd->nr_balance_failed > env->sd->cache_nice_tries) { if (hot) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index ac8c7ac1ac0d..c18e59f320a6 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1495,6 +1495,14 @@ extern void sched_core_dequeue(struct rq *rq, struct= task_struct *p, int flags); extern void sched_core_get(void); extern void sched_core_put(void); =20 +static inline bool task_has_sched_core(struct task_struct *p) +{ + if (sched_core_disabled()) + return false; + + return !!p->core_cookie; +} + #else /* !CONFIG_SCHED_CORE: */ =20 static inline bool sched_core_enabled(struct rq *rq) @@ -1534,6 +1542,11 @@ static inline bool sched_group_cookie_match(struct r= q *rq, return true; } =20 +static inline bool task_has_sched_core(struct task_struct *p) +{ + return false; +} + #endif /* !CONFIG_SCHED_CORE */ =20 #ifdef CONFIG_RT_GROUP_SCHED --=20 2.32.0