From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 6B60433A9DC for ; Wed, 18 Feb 2026 09:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771406147; cv=none; b=RHzsvwV6iB8j0OzK9Vrg+B5fXstDUdfShB9jvTBocdk6ymS7wiCQUv1F7Qo/1xDIqmfsP1iHQfiPWlNrx2YteIkOQQ5J97BzeuAYKLANzqW/gJalGC2WuVODarqtM4eysCaaSSBsAuq8D69L69HQCKhhHMM/tXkvkw/fuqi4lVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771406147; c=relaxed/simple; bh=MoSNqvbXPXLOY/vJKYKAZzhBiaX+VEVBHHyedSkDtJs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rLqHgt65sJPIhMktgM1FZq4sYbubrx1KglyOTZ4kw3cAXIy7k+9v5DzAnSqDacAg014SkppO9W+NRH7eZaVIbqVy7sdWwNQZDNGl//m7knSsRl8NX/ct3G7X8/JU3KNiO1snacWS10IEXfKoPNZcvYH0ZD8eGsnJWqg+kbpMV7Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=oap1PGoe; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="oap1PGoe" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61I4Z8xS3013565; Wed, 18 Feb 2026 09:14:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=U16L5y ojZux9bm8HJbcCtWN8SRN6F1xBa7A8gEY4xrM=; b=oap1PGoe5/eiL9wuRJcF8D /1gFvH0jf7qDkhuhn2u0vPD69pCtAIKzOIh5zDRSmsje6VWzddW97YQX04sY6onF NFKSK/gEZfan8zvxkX4rWFX15v0wW+VDxRofpJpUU4ITAim80my0lyeg8oESvX0A JrXLgJAL7Glu8sXcdrYrNKZSjr3KcVfrw+ybLK1MuKLbToSVmmNanLt80c5sfstF OFI45sd3S8+Hqt7KljQLGpKHtS2DB73nDVq72bWYxRwM5PCImlDxQGqi+Han/lK+ Z/zmWTmyQ5PSsGqIoyUc+xnBgxok5qDgcrfRjLcX2AIpaKqbRPRzTixbDY+Ij0zQ == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4cajcr0f9t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Feb 2026 09:14:51 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 61I8Xu2c015697; Wed, 18 Feb 2026 09:14:50 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ccb4576jc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Feb 2026 09:14:50 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61I9Emmj24445626 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Feb 2026 09:14:49 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9DF7858109; Wed, 18 Feb 2026 09:14:48 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 884835810B; Wed, 18 Feb 2026 09:14:38 +0000 (GMT) Received: from [9.98.110.226] (unknown [9.98.110.226]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 18 Feb 2026 09:14:38 +0000 (GMT) Message-ID: Date: Wed, 18 Feb 2026 14:44:37 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 14/21] sched/cache: Respect LLC preference in task migration and detach To: Tim Chen 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, Madadi Vineeth Reddy References: <82aeb78bbfb80cb6861b85e4db9d398f6c8e331b.1770760558.git.tim.c.chen@linux.intel.com> Content-Language: en-US From: Madadi Vineeth Reddy In-Reply-To: <82aeb78bbfb80cb6861b85e4db9d398f6c8e331b.1770760558.git.tim.c.chen@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: eINJuqC4wHQXJqeaolk7oa2gC9c6NXb6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjE4MDA4MCBTYWx0ZWRfX4kjb58nuySEL eNQxVTStcSJLnge9n4t1GgK9BHQ44TGMG+k7F/NUlws4FECKY7vqc4kBHCDRWEAD8syE5QW8lt9 q69VoVkQLza9jI3k0hAggwn0EVzwgGJdl3arXsHuJQqZQnhuvwFag1COqCMnEmNIqjhzaMPM//6 nZvHIwwgpy3R4diRtAzcLhpYBYlwJ0l11I4kOh460vrtQsvIdj+mJZtpCi8Ft4aLCW4lrVS1wbe Ibe/isTT1BtN3boRoJPkaROxL26oTXG/oNBBgEbQVgsJlBiUgqLAFWDOFeyMmcmSzYkmqQjd4B4 E9D0pqqvUTjYLzfCyMsFujiuCvtKmeuiWWcp4Ik46z+D2BTDbhZajP+xskOR0n77m8H5yyZhQJr GVmXTrZWs6fCA++8VNnc5e1mgc3L9lVTI2b33/8GH+yoO8Y62layjFkTN3BX8bAHM40dcTVARt0 iDlPXxFY5Y0JiDftkdg== X-Authority-Analysis: v=2.4 cv=UPXQ3Sfy c=1 sm=1 tr=0 ts=6995830c cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=JfrnYn6hAAAA:8 a=zd2uoN0lAAAA:8 a=QyXUC8HyAAAA:8 a=ZEPo9zYMe9biu-DGbl0A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=1CNFftbPRP8L7MoqJWF3:22 X-Proofpoint-ORIG-GUID: TTuL4i_yVV9w2qro5BmfYNuSYKEkPprg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-18_01,2026-02-16_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 phishscore=0 impostorscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602180080 On 11/02/26 03:48, Tim Chen wrote: > 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) > > 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 dst_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) > > 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 >= 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 == migrate_llc_task && > + task_llc(p) != llc_id(env->dst_cpu)) > + return true; `task_llc(p)` returns the LLC id of the CPU the task is currently running on, right? Wouldn’t we need to check the task’s *preferred* LLC instead? Am I missing something? Thanks, Vineeth > + > + if (can_migrate_llc_task(env->src_cpu, > + env->dst_cpu, p) != 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, struct lb_env *env) > return 1; > > degrades = 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 = task_hot(p, env); > - else > + } else { > hot = degrades > 0; > + } > > 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); > > +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: */ > > static inline bool sched_core_enabled(struct rq *rq) > @@ -1534,6 +1542,11 @@ static inline bool sched_group_cookie_match(struct rq *rq, > return true; > } > > +static inline bool task_has_sched_core(struct task_struct *p) > +{ > + return false; > +} > + > #endif /* !CONFIG_SCHED_CORE */ > > #ifdef CONFIG_RT_GROUP_SCHED