From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 57A9B345734 for ; Wed, 18 Feb 2026 17:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771437321; cv=none; b=F4vnZzix9sX1BP0Tq+4+IREreDi5F38aqG01NjhIqfX5kXFHH+QVaela9mw7UA8oqSqbC3uOZan6vi1suFXCTSkfU4TrxGHEqjKnFqsBb6iZc1PqhHPmWcIU13aMomET93dDMje+BMoSoKvOKhSAkryO3VBOhmdF3seXjGVEGTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771437321; c=relaxed/simple; bh=GycNILV+wqm26Q3EjlxH2CnpijWx9Ww8rwswmpUTJM4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oBV4a9jCl7zswyBfbgaWkoeD3ywR2s082loZVfI5gy9qpgyQrnIP0BkYU1J1K+miXl3Hsxo+2wTNNR76pFEtw1rIn9K4mMI4P5l/kxsFH333SAZFgx5HcS+8qSAbWoGbUb+XlRSgm4C+0Df1F1vWBYwQWP0oZCSA8FBn0UeDl5M= 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=e6J2HFn6; arc=none smtp.client-ip=148.163.158.5 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="e6J2HFn6" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61IAxtpE3299365; Wed, 18 Feb 2026 17:54:26 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=f8+EC9 p9CbFDBbl3HfeIUwFhUIzG5X/q8cWO21rMG9s=; b=e6J2HFn6/VSDrYuIcAkIYN ihLhdoHSV5XSeX4u2G+QppQANPQV9qt1+T3aNJig6GTenNkxKjijqPfGLt6rnkkq dDZkBbuJPiJN6JKLSl2wE70smCfBaI3g3p5HvyguzqMFNUTxTXfgWE3h3xtHeUpj 3ZkF7o4lzQnwhKdxZ3z8DIr54nRZsxFDTpWRAUVoF3YcZ33LYkbNslBUJOfx14nl 2Ap7lN3evokjqwuhm/aNTo2E+ssmKBpN93jpZOiX2cFc6RiZlEis+RODKhi+KnpL oM8BPp91fJnsjb3GchoWu2V3nQ9xBFXsOuuTkS1xfdTSenXtRfKh9RMzdo9S3jTA == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4caj649emb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Feb 2026 17:54:25 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 61IHg725011961; Wed, 18 Feb 2026 17:54:24 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ccb270xwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Feb 2026 17:54:24 +0000 Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61IHs2Ug18612782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Feb 2026 17:54:02 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E30345805B; Wed, 18 Feb 2026 17:54:22 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 210D458058; Wed, 18 Feb 2026 17:54:07 +0000 (GMT) Received: from [9.67.44.67] (unknown [9.67.44.67]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 18 Feb 2026 17:54:06 +0000 (GMT) Message-ID: Date: Wed, 18 Feb 2026 23:24:05 +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 15/21] sched/cache: Disable cache aware scheduling for processes with high thread counts To: Tim Chen Cc: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Chen Yu , 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 , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org, Madadi Vineeth Reddy References: Content-Language: en-US From: Madadi Vineeth Reddy In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: kVRWjCtMwPAFkNoqnhDzh-cgquvORUjq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjE4MDE1MSBTYWx0ZWRfX9Wfziv1TcsuU y5QfcGQwadzdNwt8rGOuaiS/XeTm7AIRltlRPPFcMfwEOzqswi+39jtiSF8TJjqsaUSVzwtd/62 WeiGEZg1hPdBvTJaffGjRw6olKIjS5u0yc4ZXAO8/5IrO222ZAFgQDiYDax+cDwCf48M+tjAbhU hIWOSfPZN1oNy5mBjsYmDYo8N9H5r2SXGeKMFXaXxe7CsSj34cNfXkl3TZSeTxm+yZq+K9NE8Qk OsT/b1ewOq5J/HhPoz4DE5WfHSCorC+Co00Pdpemh2cyIffnJ6SyTPmvWQZUVEaV/9cev0/Ia9+ RiKXZzI5SDU2Jeh52McdNstJ7Bzsu28vpk8gk6vzaf9XX3HPyicSvS10fiRjtO2KyBkkqGR3d5A SUysZVoPmhKmc6ETPrrFslrTIdFSot8msL+hp72OxkBKHwCBJ1Nw9xndOBueTEk+tZperW5AhCW d6wAVLFYYwJ79lWif8g== X-Proofpoint-GUID: q6PozHueSdORJ8cipVh886XlbsVVYNkF X-Authority-Analysis: v=2.4 cv=U+mfzOru c=1 sm=1 tr=0 ts=6995fcd1 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=QyXUC8HyAAAA:8 a=zd2uoN0lAAAA:8 a=968KyxNXAAAA:8 a=oBFdn3nMvb6cj5iG2noA:9 a=QEXdDO2ut3YA:10 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_03,2026-02-18_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602180151 On 11/02/26 03:48, Tim Chen wrote: > From: Chen Yu > > A performance regression was observed by Prateek when running hackbench > with many threads per process (high fd count). To avoid this, processes > with a large number of active threads are excluded from cache-aware > scheduling. > > With sched_cache enabled, record the number of active threads in each > process during the periodic task_cache_work(). While iterating over > CPUs, if the currently running task belongs to the same process as the > task that launched task_cache_work(), increment the active thread count. > > If the number of active threads within the process exceeds the number > of Cores(divided by SMTs number) in the LLC, do not enable cache-aware > scheduling. For users who wish to perform task aggregation regardless, > a debugfs knob is provided for tuning in a subsequent patch. > > Suggested-by: K Prateek Nayak > Suggested-by: Aaron Lu > Co-developed-by: Tim Chen > Signed-off-by: Tim Chen > Signed-off-by: Chen Yu > --- > > Notes: > v2->v3: > Put the calculating of nr_running_avg and the use of it into 1 patch. > (Peter Zijlstra) > > Use guard(rcu)() when calculating the number of active threads of the > process. > (Peter Zijlstra) > > Introduce update_avg_scale() rather than using update_avg() to fit > system with small LLC. > (Aaron Lu) > > include/linux/sched.h | 1 + > kernel/sched/fair.c | 59 ++++++++++++++++++++++++++++++++++++++++--- > 2 files changed, 57 insertions(+), 3 deletions(-) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index c98bd1c46088..511c9b263386 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2346,6 +2346,7 @@ struct sched_cache_stat { > struct sched_cache_time __percpu *pcpu_sched; > raw_spinlock_t lock; > unsigned long epoch; > + u64 nr_running_avg; > int cpu; > } ____cacheline_aligned_in_smp; > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index d1145997b88d..86b6b08e7e1e 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -1223,6 +1223,19 @@ static inline bool valid_llc_buf(struct sched_domain *sd, > return valid_llc_id(id); > } > > +static bool exceed_llc_nr(struct mm_struct *mm, int cpu) > +{ > + int smt_nr = 1; > + > +#ifdef CONFIG_SCHED_SMT > + if (sched_smt_active()) > + smt_nr = cpumask_weight(cpu_smt_mask(cpu)); > +#endif > + > + return !fits_capacity((mm->sc_stat.nr_running_avg * smt_nr), > + per_cpu(sd_llc_size, cpu)); On Power10/Power11 with SMT4 and LLC size of 4, this check effectively disables cache-aware scheduling for any process. I raised this point in v1 as well. Increasing the threshold doesn't seem like a viable solution either, as that would regress hackbench/ebizzy. Is there a way to make this useful for architectures with small LLC sizes? One possible approach we were exploring is to have LLC at a hemisphere level that comprise multiple SMT4 cores. Thanks, Vineeth > +} > + > static void account_llc_enqueue(struct rq *rq, struct task_struct *p) > { > struct sched_domain *sd; > @@ -1417,7 +1430,8 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) > */ > if (time_after(epoch, > READ_ONCE(mm->sc_stat.epoch) + EPOCH_LLC_AFFINITY_TIMEOUT) || > - get_nr_threads(p) <= 1) { > + get_nr_threads(p) <= 1 || > + exceed_llc_nr(mm, cpu_of(rq))) { > if (mm->sc_stat.cpu != -1) > mm->sc_stat.cpu = -1; > } > @@ -1458,13 +1472,31 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p) > } > } > > +static inline void update_avg_scale(u64 *avg, u64 sample) > +{ > + int factor = per_cpu(sd_llc_size, raw_smp_processor_id()); > + s64 diff = sample - *avg; > + u32 divisor; > + > + /* > + * Scale the divisor based on the number of CPUs contained > + * in the LLC. This scaling ensures smaller LLC domains use > + * a smaller divisor to achieve more precise sensitivity to > + * changes in nr_running, while larger LLC domains are capped > + * at a maximum divisor of 8 which is the default smoothing > + * factor of EWMA in update_avg(). > + */ > + divisor = clamp_t(u32, (factor >> 2), 2, 8); > + *avg += div64_s64(diff, divisor); > +} > + > static void task_cache_work(struct callback_head *work) > { > - struct task_struct *p = current; > + struct task_struct *p = current, *cur; > struct mm_struct *mm = p->mm; > unsigned long m_a_occ = 0; > unsigned long curr_m_a_occ = 0; > - int cpu, m_a_cpu = -1; > + int cpu, m_a_cpu = -1, nr_running = 0; > cpumask_var_t cpus; > > WARN_ON_ONCE(work != &p->cache_work); > @@ -1474,6 +1506,13 @@ static void task_cache_work(struct callback_head *work) > if (p->flags & PF_EXITING) > return; > > + if (get_nr_threads(p) <= 1) { > + if (mm->sc_stat.cpu != -1) > + mm->sc_stat.cpu = -1; > + > + return; > + } > + > if (!zalloc_cpumask_var(&cpus, GFP_KERNEL)) > return; > > @@ -1497,6 +1536,12 @@ static void task_cache_work(struct callback_head *work) > m_occ = occ; > m_cpu = i; > } > + scoped_guard (rcu) { > + cur = rcu_dereference(cpu_rq(i)->curr); > + if (cur && !(cur->flags & (PF_EXITING | PF_KTHREAD)) && > + cur->mm == mm) > + nr_running++; > + } > } > > /* > @@ -1540,6 +1585,7 @@ static void task_cache_work(struct callback_head *work) > mm->sc_stat.cpu = m_a_cpu; > } > > + update_avg_scale(&mm->sc_stat.nr_running_avg, nr_running); > free_cpumask_var(cpus); > } > > @@ -9988,6 +10034,13 @@ static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu, > if (cpu < 0 || cpus_share_cache(src_cpu, dst_cpu)) > return mig_unrestricted; > > + /* skip cache aware load balance for single/too many threads */ > + if (get_nr_threads(p) <= 1 || exceed_llc_nr(mm, dst_cpu)) { > + if (mm->sc_stat.cpu != -1) > + mm->sc_stat.cpu = -1; > + return mig_unrestricted; > + } > + > if (cpus_share_cache(dst_cpu, cpu)) > to_pref = true; > else if (cpus_share_cache(src_cpu, cpu))