From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013060.outbound.protection.outlook.com [40.107.201.60]) (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 7692D8C1F for ; Fri, 19 Jun 2026 06:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.60 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781852088; cv=fail; b=mVVByUWcID9wcQAqVCpfIDmiGV7i55zo68+ula2YOtR4Nzo+4kihoEC9/fJwJLASwoqO+nvQwOTcsY40Ur04+a/+jpEbOpmKknPHck6fdc8AZiyTBZM/yx8KFTc8KzkiTjIup4MV9FMcLxNzmYZ70vzN/k1WJ75qc3VSE9XxNnk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781852088; c=relaxed/simple; bh=iFjQe+Ew6Bw0OKFJQu/roUbMFr5NsXdM2GUF5KN310w=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=JLzQn8Bb5MhmCDSqN/iiQfSzqUBCH8AhnQMLHKOrBouKFxvymdl00gHRw1xyp2Uv+FV6CnkDHO0mL5pKwdCdbAbZ5wnbHKjx+39I+OeMWn6NyPRlAtGtQugmajZWmTs6ZwvUGuM4tGPnjY1Bce/e5JznCq4BDl/Qm+qtS088Ygg= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=mXp3ptAg; arc=fail smtp.client-ip=40.107.201.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="mXp3ptAg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mAoc0FWU+SunAHRP/lSUBci/9ntOKYlkLyQNRTdicjSAMT8u86+tWX/0GOe8IsNUx1RV/AGNjDIHmYgcq2RjB9CyRbW+FyC3iGhq3qU+gap9zORM5zuu60ammVEkhQ+UyrIFvEbvfe7gUMU8cA1uT4Smfo1pgx7A0+Bxg85g9J2vA/cCBalOZAMM1sm7ak3oJWiD8hRpZeXrhHr0jd5HrQSQj5ua+JTfIXFDWcFP2TpJj44QAB4s1sdfI5N1W6gvSb5a1Hw0n9vqTXiCbiDdsb6XmTZ5iCjQhejxddmR+lF1il0cL5KrIRsGkDUPnl23/aJpLO8cWD44/vTr+CM5zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XB454WP8+UrNEzg9pewCgtlECKMhoZoj65SgrLJt1bg=; b=Y2OmuTlcJkCsj6M9+rjz7/BOWfqnrcMBuWI1CL8CCehyyBkwUawSkku7cIGjDCW/HK4YcSOj8Twa9L7LFL8PXlPX3VWQqfUfzVmV86gTJ5f9B8eWoxlE0qkPw4WbJDvd19iFsU1A/HGJf4rtwWRwaG9oM81Y0EPTwpMSHqA3tnY46AuuBcCp2xNy2koVsa3zIvo+hL/it5MwVdHcWD93amaFKZ+E1IJES/2GubFJAcs2AZXl7VPXbRi54Onhevt+zAcE5JnoeP00cK6Xn6bBiYnCogOtclr8VMJqb69lZV8pXUeUefpOeM8WsH0ViBkbpBVxwpS2hm47Oj6GUgLG7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=huawei.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XB454WP8+UrNEzg9pewCgtlECKMhoZoj65SgrLJt1bg=; b=mXp3ptAgKATXHb4ZZmR9RyeraUedUVKR6aPaUE43nve1S+KDC0rA7EojwP1g4K7K47SjIACdnuz34gUSubucvhWVVw8SC+ErT+Nn05vSiJanZC2f1FX4ePX0ziIhyU/1q+2bV5cNl4zflteVdo77njaXjR3V/aONtiSGJlLfGs0= Received: from PH7P221CA0020.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:32a::6) by CH0PR12MB8552.namprd12.prod.outlook.com (2603:10b6:610:18e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.139.11; Fri, 19 Jun 2026 06:54:40 +0000 Received: from SA2PEPF000015C7.namprd03.prod.outlook.com (2603:10b6:510:32a:cafe::82) by PH7P221CA0020.outlook.office365.com (2603:10b6:510:32a::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.139.14 via Frontend Transport; Fri, 19 Jun 2026 06:54:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF000015C7.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.139.8 via Frontend Transport; Fri, 19 Jun 2026 06:54:39 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Fri, 19 Jun 2026 01:54:37 -0500 Received: from [10.136.46.240] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Fri, 19 Jun 2026 01:54:33 -0500 Message-ID: Date: Fri, 19 Jun 2026 12:24:32 +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 v4 1/2] sched/cache: Reduce the overhead of task_cache_work by only scan the visisted cpus To: Luo Gengkun , , , , , , CC: , , , , , References: <20260618064300.80072-1-luogengkun2@huawei.com> <20260618064300.80072-2-luogengkun2@huawei.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260618064300.80072-2-luogengkun2@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C7:EE_|CH0PR12MB8552:EE_ X-MS-Office365-Filtering-Correlation-Id: 8246a5ec-0202-486b-cc94-08decdcfa217 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|7416014|376014|82310400026|23010399003|1800799024|3023799007|18002099003|22082099003|56012099006|11063799006|4143699003; X-Microsoft-Antispam-Message-Info: aKrcZQh134Y5Do4KJh3P7YWdn8/bk5qTygerO+BSCMa4eU0Vb6OtQ4G+x1nlg3smmNEBdSDrZ5WDIfO8KN5VXRonnUQHYLbnvyPaFSuBypDWOD0q2YoUjRloDSnPo8pPG6lcVrozrkQvHwSSLUOictSREct/RzDsqAa3PB1bbjeah9Msjy+QtQjO2RAtc/1w/5sk75K1RFloya+s/TLWa2g4QBROgqlkC/vqKFj9tGnLuzfo8EMb1EN2AZRVewplxJBe84IySKfzQIULN/8svgYpXDudKC7o1UZnKlC1eVZSNds21ShY7dg+L9pukhCc0ccFsIYSia+QK0qJMbk5mEiDrUfMhXdiuYLcwEeuiY7Sn3UGZp0s2P9FZiuB5nWxYpzMxTege8/8TQZ2Pxa06TsoEvsB/HpgkHRpgKxoIWp9vgBiR/d7gxJESSu0lakVGiZBvcEaDCx7S710qs+qgmeKBao571+77TEzpy1jTwRYIg1ISDcINYtf0E1jTqd7v0yxBVr4XdCOZGW9oKI6YD/LNpMRPdGAKA6hDiJs20CVqz0/MNnQLxaYmASunAUpXIP6biJQRkVGInklMKmEhIeVIX8tS+3cgUidhwNnPXc6a8f/ZC7u+r4dbY5GATAkWwvBh2UJDpeaddygiklZbbMKRyfI3bzJ4JpHcLJvQN6cuYyY04wZtz1OQdkcGBrnF+Te3ULMV0ulk73+lbgFlQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(7416014)(376014)(82310400026)(23010399003)(1800799024)(3023799007)(18002099003)(22082099003)(56012099006)(11063799006)(4143699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o+JzHWBBEndrdE4hb2YSeWQ5KHHs/xDxVm2Qj/7eUhuEefADMYDlyKyK1McC0a1LhuTGYzSZvqXc5NOsQ/jLckT39hRw2EufEKWl4DQG2LohCwS/X19M5zzIm8Zg+K+wg3ERfEBdjM0jMjWxjWtvfBvZZUGFWIfUG3R0oev0xsNDQNmW0DCcQAsQ8K9x0k+qufo8JRPTRarXw02f+hqIXXlXS7lEFUjEQs5gsB3lmkOThzz0RMlaJaZu9DceqP13nIZuf1UPuzwycC6ukFwrLg/SXcMdyKlfb/Jh0EjTCd49cjXrYOZ4pq0cksWkE9wA82QMlZQq7JR/VcSHQpeHbPfliPObSjxGW3zhPyL0Tpo0qsQh8PXw1cR+j4WNX8YFkN4EF+cIH/ZmbyUHf8zogNyRObj/PsdtG007UqI07YF64Jb71r2Arw8wSsYw+qUE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2026 06:54:39.3932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8246a5ec-0202-486b-cc94-08decdcfa217 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015C7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8552 Hello Luo, On 6/18/2026 12:12 PM, Luo Gengkun wrote: > The overhead of task_cache_work() is high, especially in multi-NUMA > systems. Currently, task_cache_work() tries to find the pref_llc by > scanning all CPUs in the system. However, most of these scans are > meaningless, such as those for CPUs that have never been visited or were > accessed a long time ago. > > To address this problem, introduce visited_cpus to track the visited CPUs > and evict them once they have not been accessed for a duration exceeding > llc_epoch_affinity_timeout. With this patch, get_scan_cpumasks() is no > longer need and is therefore removed. Please include performance numbers here. I'm not convinced by the amount of benefits this brings. For hackbench, the only stable improvement I can see from the cover letter is: threads 1 4 | 27.758 (1.64%) | 25.711 (1.32%) | 7.37% | IMPROVED Since you mention Redis may benefit from this, do you actually have numbers for Redis, or any other real world workload on your system? [..snip..] > @@ -1635,11 +1637,21 @@ static inline void __update_mm_sched(struct rq *rq, > } > } > > -static unsigned long fraction_mm_sched(struct rq *rq, > - struct sched_cache_time *pcpu_sched) > +static unsigned long fraction_mm_sched(int cpu, > + struct mm_struct *mm) > { > + struct sched_cache_time *pcpu_sched = > + per_cpu_ptr(mm->sc_stat.pcpu_sched, cpu); > + struct rq *rq = cpu_rq(cpu); > + > guard(raw_spinlock_irqsave)(&rq->cpu_epoch_lock); > > + /* Skip the rq that has not been hit for a long time */ > + if ((rq->cpu_epoch - pcpu_sched->epoch_timeout) > llc_epoch_affinity_timeout) { > + cpumask_clear_cpu(cpu, &mm->sc_stat.visited_cpus); This makes me think your issue is more with pcpu_sched->runtime not decaying fast enough? If you haven't run in 50us, the pcpu_sched->runtime would already be decayed by >> 5 but that is not enough? > + return 0; > + } > + > __update_mm_sched(rq, pcpu_sched); > > /* > static inline void update_avg_scale(u64 *avg, u64 sample) > { > int factor = per_cpu(sd_llc_size, raw_smp_processor_id()); > @@ -1866,7 +1836,7 @@ static void task_cache_work(struct callback_head *work) > scoped_guard (cpus_read_lock) { > guard(rcu)(); > > - get_scan_cpumasks(cpus, p); > + cpumask_and(cpus, cpu_online_mask, &mm->sc_stat.visited_cpus); Doesn't this violate NUMA_BALANCING constraints? That was the whole point of get_scan_cpumasks() > > for_each_cpu(cpu, cpus) { > /* XXX sched_cluster_active */ > @@ -1878,18 +1848,21 @@ static void task_cache_work(struct callback_head *work) > continue; > > for_each_cpu(i, sched_domain_span(sd)) { What does your system topology look like? We visit all CPUs of LLC here so even if a single CPU of LLC is set in visited, you'll still visit all CPUs of LLC here ... > - occ = fraction_mm_sched(cpu_rq(i), > - per_cpu_ptr(mm->sc_stat.pcpu_sched, i)); > + cur = rcu_dereference_all(cpu_rq(i)->curr); > + if (cur && !(cur->flags & (PF_EXITING | PF_KTHREAD)) && > + cur->mm == mm) > + nr_running++; > + > + occ = fraction_mm_sched(i, mm); ... and all this does is return 0 if the mm hasn't run on that CPU for over 50us. All this is pointing to more aggressive decay maybe somehow helping you. > + if (occ == 0) > + continue; > + -- Thanks and Regards, Prateek