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 30A3C1DF273 for ; Sat, 14 Feb 2026 18:38:03 +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=1771094285; cv=none; b=OWEbLkzCruPDVEoefTf+8unfzr2Vp5KyRHtgtf/agTAA1dHkaIHPrn5TRC99e8AmO6RD+t2HFw6oAPAHiF9bjZo2k7ecJLF8C8JxWfPNRHVCpuPBlxSAkwJcCJYwrWPSHQBYXMWQOPhuV4I1umfLLfojyzMJsJsCh/xBT9id1Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771094285; c=relaxed/simple; bh=bno6dsIszWKv5Zx+9OF9LvtrLHqamv6JkxLhAJaeBqM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WLPK5WDaZUkk2BFo+P0bFx0hCA7WiR7Ucv5HEFB/UgowpOGJk5A25AgIZ58mkICMI2Q9q8hWHdZS1UlNxpapP9WtefTo0//zZoVSB31SfVYRvnBICC/WqOBy/glF4YZp4l2FeXWuWOPS3/NDMYoHF0lcCZvBbXyfqPau23h6xi4= 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=PlECBHap; 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="PlECBHap" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61ECG7DW3987907; Sat, 14 Feb 2026 18:37:11 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=+8iHFh FFOhEcZFo+dOZWQBmiGWUAG/EyVKiCJ5p2NiY=; b=PlECBHap0V976uMqs9tZS3 VFnIYdHZwFSwf02uTmpKTvSSbHw1jbPvKIpW6PS/hjXNAaxP2wr1gXHcj+VZnbi4 /tYvfP6fDx2wVDA4NIssZJmWAuS2K91Qj7OLzmjoM3dB+dRS9GefcRbriOQy7TBS Zh5qCHdymZeKAbliTqdtra9Ve6xXD6Y/sCEnwVSCoZSYNgNkEvlthio3FNjigvT9 EUsI5BrXIQHcTz+gKwxt99omXodx6PG/mIG3NaTsxiO+lZnuYlPepQX3qBz1z+BC RDGTTTWAnwn7hsNYxfqynJ60mIUg+skqUJW4J88G3LrtSJn7g1QFn8YA/XeW98rQ == 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 4caj6u9kfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Feb 2026 18:37:10 +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 61EGXwYn008400; Sat, 14 Feb 2026 18:37:09 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4c6g3yumcs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Feb 2026 18:37:09 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61EIb7da32506518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 14 Feb 2026 18:37:08 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BDD4958058; Sat, 14 Feb 2026 18:37:07 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5FF158057; Sat, 14 Feb 2026 18:36:50 +0000 (GMT) Received: from [9.67.107.13] (unknown [9.67.107.13]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Sat, 14 Feb 2026 18:36:50 +0000 (GMT) Message-ID: <40508142-4a0c-4c00-839e-5807352071ee@linux.ibm.com> Date: Sun, 15 Feb 2026 00:06:48 +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 05/21] sched/cache: Assign preferred LLC ID to processes 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: <4a92b93edb669845e3bdca24c3ae3354b317c3eb.1770760558.git.tim.c.chen@linux.intel.com> Content-Language: en-US From: Madadi Vineeth Reddy In-Reply-To: <4a92b93edb669845e3bdca24c3ae3354b317c3eb.1770760558.git.tim.c.chen@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=E+/AZKdl c=1 sm=1 tr=0 ts=6990c0d7 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=QyXUC8HyAAAA:8 a=ezvxUTRpk5kXBi5b6HQA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjE0MDE1MSBTYWx0ZWRfX65MBbK5nl4AA EbD04h9lp0gi1TZob/P1Tq00AmkQhZuzgNtgcRlX3Kk3fOYPzZhLX/rqtrRmrDzUlwliKY5bRfm pU0TCkNoMByjYjJUmyOj9WmCBGqnnNnmXiiT5xXttg+dxk42/h7EIms2mqbOjLqyqq+JGzh/hlX iAuQcm5qJk7div2EQjk8/fWobw2TAFh6ww4puFIJ4N0ESbW4NcceKU2dXlsIi32QzDPdgi2Jwov oQ7X1kFxqkIihbM/F8MAiylPKLmH4Yfkk2brD4JWrB9wddLaud9KMtm8ZI1dtK+4jSb9E2Ig5aN n3o9XkUsdxsbOIyklb68y5gTVyEeY3H2pcoMs+vDfoEwbuBE/CpUcJonekc++y4XS0flh5DMKpm jyyUrs+86SeQNY//H0Lm50iDacnWnJ1d887PAnmCzGGtt29EGf2UHYYYg7ZXZmRXCUiuCBJjm1t pcrqN8zMeu580/LJ6yw== X-Proofpoint-ORIG-GUID: e7_LLxUQ--3xP5agIKKVGeJ-QB3PIDrK X-Proofpoint-GUID: MGkhL-2UfM3BFeOOabM9CFWTM68fDUuQ 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-14_02,2026-02-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 clxscore=1015 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602140151 On 11/02/26 03:48, Tim Chen wrote: > With cache-aware scheduling enabled, each task is assigned a > preferred LLC ID. This allows quick identification of the LLC domain > where the task prefers to run, similar to numa_preferred_nid in > NUMA balancing. > > Signed-off-by: Tim Chen > --- > > Notes: > v2->v3: > Add comments around code handling NUMA balance conflict with cache aware > scheduling. (Peter Zijlstra) > > Check if NUMA balancing is disabled before checking numa_preferred_nid > (Jianyong Wu) > > include/linux/sched.h | 1 + > init/init_task.c | 3 +++ > kernel/sched/fair.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 46 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 2817a21ee055..c98bd1c46088 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1411,6 +1411,7 @@ struct task_struct { > > #ifdef CONFIG_SCHED_CACHE > struct callback_head cache_work; > + int preferred_llc; > #endif > > struct rseq_data rseq; > diff --git a/init/init_task.c b/init/init_task.c > index 49b13d7c3985..baa420de2644 100644 > --- a/init/init_task.c > +++ b/init/init_task.c > @@ -218,6 +218,9 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = { > .numa_group = NULL, > .numa_faults = NULL, > #endif > +#ifdef CONFIG_SCHED_CACHE > + .preferred_llc = -1, > +#endif > #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) > .kasan_depth = 1, > #endif > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index bf5f39a01017..0b4ed0f2809d 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -1273,11 +1273,43 @@ static unsigned long fraction_mm_sched(struct rq *rq, > return div64_u64(NICE_0_LOAD * pcpu_sched->runtime, rq->cpu_runtime + 1); > } > > +static int get_pref_llc(struct task_struct *p, struct mm_struct *mm) > +{ > + int mm_sched_llc = -1; > + > + if (!mm) > + return -1; > + > + if (mm->sc_stat.cpu != -1) { > + mm_sched_llc = llc_id(mm->sc_stat.cpu); > + > +#ifdef CONFIG_NUMA_BALANCING > + /* > + * Don't assign preferred LLC if it > + * conflicts with NUMA balancing. > + * This can happen when sched_setnuma() gets > + * called, however it is not much of an issue > + * because we expect account_mm_sched() to get > + * called fairly regularly -- at a higher rate > + * than sched_setnuma() at least -- and thus the > + * conflict only exists for a short period of time. > + */ > + if (static_branch_likely(&sched_numa_balancing) && > + p->numa_preferred_nid >= 0 && > + cpu_to_node(mm->sc_stat.cpu) != p->numa_preferred_nid) > + mm_sched_llc = -1; > +#endif > + } > + > + return mm_sched_llc; > +} > + > static inline > void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) > { > struct sched_cache_time *pcpu_sched; > struct mm_struct *mm = p->mm; > + int mm_sched_llc = -1; > unsigned long epoch; > > if (!sched_cache_enabled()) > @@ -1311,6 +1343,11 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) > if (mm->sc_stat.cpu != -1) > mm->sc_stat.cpu = -1; > } > + > + mm_sched_llc = get_pref_llc(p, mm); > + > + if (p->preferred_llc != mm_sched_llc) > + p->preferred_llc = mm_sched_llc; This writes to p->preferred_llc without using WRITE_ONCE(). If later patches read p->preferred_llc from load balancing or migration paths on other CPUs, wouldn't this create a data race? For example: CPU 0: Task is running, account_mm_sched() writes p->preferred_llc CPU 1: Load balancer reads p->preferred_llc to make migration decisions Should this use WRITE_ONCE() and READ_ONCE() at the read sites, unless all accesses are guaranteed to be under rq->lock? Thanks, Vineeth > } > > static void task_tick_cache(struct rq *rq, struct task_struct *p) > @@ -1440,6 +1477,11 @@ void init_sched_mm(struct task_struct *p) { } > > static void task_tick_cache(struct rq *rq, struct task_struct *p) { } > > +static inline int get_pref_llc(struct task_struct *p, > + struct mm_struct *mm) > +{ > + return -1; > +} > #endif > > /*