From nobody Tue Apr 7 20:08:13 2026 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012063.outbound.protection.outlook.com [52.101.48.63]) (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 4D2F6258EC2 for ; Thu, 12 Mar 2026 04:45:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773290748; cv=fail; b=ecHYV3l8Xk7QATwt5ZexFah8RNTaL3h3o4U3EtJB+1rRiE95FLjEwpR3+5WdHbyB66OvOMX1bANRfEo0XAVH//FbAGRIJgtmiqHVD6agNHt6fsMfEYus40eXw9CxgypLQnK08nlb8qPz8pFx4irbX2pP+YDmoyJpnETNq6LSIRk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773290748; c=relaxed/simple; bh=aOmwBif/DGTbfASibfq5vRLTbnip82u0RYKm4BbNA34=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h4Xg9Xf28aCcPgsQpkOnWaJcM+o+WC5xNAz1rB70Jpjh9EgE8cidIZY61TtPkLIAlyTrdzzPwe7XKqvz4kd3bz4olOM4uQL/AAXg0DOyHsylr0tlCUUWdwril5AW0HlEIENsKoSBH7Fhq3s5nRTUIy1GcNCQJUcLSvlrmBO9H18= 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=ysMVuCqU; arc=fail smtp.client-ip=52.101.48.63 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="ysMVuCqU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WidsOc9TUvMlQ5Qjenz1lZlDR/U7HHMNMCB+mdhPXo78fu72mET/n0M2mOBxjqQbpCFxZSMIUYBvt3NOwO8c367LKIMgk77B1iBWMTglzWxUd4xgkBIaWc4hvOgoT/HK4joJHKW5wpG64mVjHudycPyFDgKzYnjQnEGcnkpAEDwwsJaQ5BB0CQONVZ/mv6vCNeIP4n8t2de/ExFdvF/3YJqyJl1obFx6t3ehwkJMSMdzkMUGmK3KO/RBrieTTuTAZu4LAoWwVyeYh/zeI+OvQ3e5pqCqFOHGplNPi0tAvDkxgHlYC5A+pqMMYWmf08Lb+yvn5srCtH3AWlUjbsequw== 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=1EIHRon7Ebi++wu9JMXzmPoiJVPvd3G3OWpRiQ6UUkw=; b=XY+se+5vsbmE1OvB2a5M7q/vn7r3WSJd99lBn9Su8p6z8Hvy57K590V2I+bClZkjJU9X0wauaLgsUfJB94yLk5wrDW8zWrkKjRQP2JV9yk2L7ogxpc2PboImumj8oVgvze3mXhCx3EbFvY4De88l5RyBzy6IhpXogPEz3zHd7hTdJBQxkvur/+r1wAj3z+z9qawJoM7lNc23IooaCSW5wwagtXnb16vviM8yQo3wj89lgPlAsgNqBPui3uHdD4dXSLVTM7zlN8TrXqf5UBjl77cMPib+Z8kJ4PTEudaiDTdG8m93m0RZV0EYVan2P27VoXUqZ8GPHTP8kQD2kCo4sQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.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=1EIHRon7Ebi++wu9JMXzmPoiJVPvd3G3OWpRiQ6UUkw=; b=ysMVuCqUdENA/TmcotsOzKiOzcShRt1w1Sy/9FvWnrw7eUtFepSLU0LAuAVty8bh//OKMawSiNskM4EEld3Sh8dtVB7fTCHq15/2gkDlh4RxYsqxdM2kTq4j+aFL7S6kRX7R75KysSQ+wHYatVCgxYq8hMjfc/J6bdmJ88UykpY= Received: from BY3PR05CA0015.namprd05.prod.outlook.com (2603:10b6:a03:254::20) by SAWPR12MB999142.namprd12.prod.outlook.com (2603:10b6:806:4e1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.6; Thu, 12 Mar 2026 04:45:44 +0000 Received: from MWH0EPF000C6188.namprd02.prod.outlook.com (2603:10b6:a03:254:cafe::5c) by BY3PR05CA0015.outlook.office365.com (2603:10b6:a03:254::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9678.23 via Frontend Transport; Thu, 12 Mar 2026 04:45:44 +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 MWH0EPF000C6188.mail.protection.outlook.com (10.167.249.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9678.18 via Frontend Transport; Thu, 12 Mar 2026 04:45:44 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) 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.17; Wed, 11 Mar 2026 23:45:39 -0500 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Valentin Schneider , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Chen Yu , Shrikanth Hegde , Li Chen , "Gautham R. Shenoy" , K Prateek Nayak Subject: [PATCH v4 3/9] sched/topology: Allocate per-CPU sched_domain_shared in s_data Date: Thu, 12 Mar 2026 04:44:28 +0000 Message-ID: <20260312044434.1974-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260312044434.1974-1-kprateek.nayak@amd.com> References: <20260312044434.1974-1-kprateek.nayak@amd.com> 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 X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000C6188:EE_|SAWPR12MB999142:EE_ X-MS-Office365-Filtering-Correlation-Id: 93eb87c7-3bf3-40a3-87d5-08de7ff238bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700016|82310400026|7416014|376014|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: hjZUraF/D2Hbfz5zShuuTPsQNr3ooTXRu26YMCY9GVfPPJjs5V3xtgbVZ6jeIbK2iqQAd3fa1en5s2u/uyY+8LsGRws5RX0/bkJh+nJqUbKuIwjn38xFeksjG7kQc37gf7Iq30WYj7pnDV3a660RiQ2WKKf+6++DI8D5pc/cgSLWpQv/6pU7ZR/Rek+UbRFP65j4mYIeDc3PQNoWjPZsni9XKcTDOH1GAjCWbPJKiFkoHzozfc01E97HzC24K+wrzG4eG3QcIRumP68tqypbkeHljNy/GyeKzY5+WGeOWimDrvqgwu5CxVhJ1/+P8pkYg0B+JZ2fb6mwyfp6R5CGi3xnwzQbKDP31+0PsAgiEvbCEy+23SCXWEN/rYIRMPtAnZRoJs8vZAK+AeGZHZbH5joNItILugQkn2tS+lNj7MeIcg1H/gP5IMNRTw4fZV+cr9jh1pA4htIY4EFKt79dB3piI3Y8UVWmxxa7plZbyKCDZdTxB6gQ3fpDPXaUF5cnGbWtnykwKbq64WDfR5cOi1C6rj55HUF2hXCQrKJlU+Cjjmt0fdHB9zh0xwMSMqDSPSrnWupmk5zGHGeP+AGoN4haLsP2fMuEIcJRJBkVne2E9CyaFvtmF1OkSYC6CUt2Nl9Rfc8Iq8CjIUnkiXnx7wNswh4sa0EeC42zNCeSSvpVdu4FcTlBes4ObkzFl62iW5bYhec5GyjaEJwJzpe3XUGdwR2pWYC9i7VlAfPKV/Dsl4N0tSer+aAEZde/yldR5nf9HpXwPKT4xmpekW7GMA== 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)(1800799024)(36860700016)(82310400026)(7416014)(376014)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cz2aDHOAZ+inwG1xIDG8y4gYsett6ZVDr873fucC68PrXPG1pmXJzPxXy+dOjzZo5/YPLjVa5y2GsrdOkOGIQB5klybGXZII2niTgzZ4VJE/DhsgOwmbEumlRDqLFQfQTzAz9SipgBEmkFWD9uJ2oXh1IZEtXMK9HYe4oIb5+9tBR2A5UQd45HkuG+9nupQe6Ax083XsGhthEst+nF4GhcIh0/Ht6Q5nFgbX9SsQOo0KIpKEJObGPjO/3hlzk3oaThy5oeD+4a78RHj0wcp82e//4HrfMd6EtfXWc57MS9BWDjyVHy+sh6QxWKmCVMDB+0+wzYSC0Hpfbz0eFoFtWE9LjsPvcU6gIdrm1Gzl/iTxh0On+mMpcwPCcBYVG94DhCJyuS93ECcZ7mrIRWMQvz77ErUgsLA32Hd0dIoOBMmgUms2y0bi5O52rxYgUEVZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2026 04:45:44.3213 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93eb87c7-3bf3-40a3-87d5-08de7ff238bd 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: MWH0EPF000C6188.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SAWPR12MB999142 Content-Type: text/plain; charset="utf-8" The "sched_domain_shared" object is allocated for every topology level in __sdt_alloc() and is freed post sched domain rebuild if they aren't assigned during sd_init(). "sd->shared" is only assigned for SD_SHARE_LLC domains and out of all the assigned objects, only "sd_llc_shared" is ever used by the scheduler. Since only "sd_llc_shared" is ever used, and since SD_SHARE_LLC domains never overlap, allocate only a single range of per-CPU "sched_domain_shared" object with s_data instead of doing it per topology level. The subsequent commit uses the degeneration path to correctly assign the "sd->shared" to the topmost SD_SHARE_LLC domain. No functional changes are expected at this point. Reviewed-by: Valentin Schneider Reviewed-by: Chen Yu Signed-off-by: K Prateek Nayak --- Changelog v3..v4: o Collected tags from Valentin, and Chenyu. (Thanks a ton!) --- kernel/sched/topology.c | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 7f25c784c038..f0541c6511fa 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -782,6 +782,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_= domain *rd, int cpu) } =20 struct s_data { + struct sched_domain_shared * __percpu *sds; struct sched_domain * __percpu *sd; struct root_domain *rd; }; @@ -789,6 +790,7 @@ struct s_data { enum s_alloc { sa_rootdomain, sa_sd, + sa_sd_shared, sa_sd_storage, sa_none, }; @@ -1535,6 +1537,9 @@ static void set_domain_attribute(struct sched_domain = *sd, static void __sdt_free(const struct cpumask *cpu_map); static int __sdt_alloc(const struct cpumask *cpu_map); =20 +static void __sds_free(struct s_data *d, const struct cpumask *cpu_map); +static int __sds_alloc(struct s_data *d, const struct cpumask *cpu_map); + static void __free_domain_allocs(struct s_data *d, enum s_alloc what, const struct cpumask *cpu_map) { @@ -1546,6 +1551,9 @@ static void __free_domain_allocs(struct s_data *d, en= um s_alloc what, case sa_sd: free_percpu(d->sd); fallthrough; + case sa_sd_shared: + __sds_free(d, cpu_map); + fallthrough; case sa_sd_storage: __sdt_free(cpu_map); fallthrough; @@ -1561,9 +1569,11 @@ __visit_domain_allocation_hell(struct s_data *d, con= st struct cpumask *cpu_map) =20 if (__sdt_alloc(cpu_map)) return sa_sd_storage; + if (__sds_alloc(d, cpu_map)) + return sa_sd_shared; d->sd =3D alloc_percpu(struct sched_domain *); if (!d->sd) - return sa_sd_storage; + return sa_sd_shared; d->rd =3D alloc_rootdomain(); if (!d->rd) return sa_sd; @@ -2466,6 +2476,42 @@ static void __sdt_free(const struct cpumask *cpu_map) } } =20 +static int __sds_alloc(struct s_data *d, const struct cpumask *cpu_map) +{ + int j; + + d->sds =3D alloc_percpu(struct sched_domain_shared *); + if (!d->sds) + return -ENOMEM; + + for_each_cpu(j, cpu_map) { + struct sched_domain_shared *sds; + + sds =3D kzalloc_node(sizeof(struct sched_domain_shared), + GFP_KERNEL, cpu_to_node(j)); + if (!sds) + return -ENOMEM; + + *per_cpu_ptr(d->sds, j) =3D sds; + } + + return 0; +} + +static void __sds_free(struct s_data *d, const struct cpumask *cpu_map) +{ + int j; + + if (!d->sds) + return; + + for_each_cpu(j, cpu_map) + kfree(*per_cpu_ptr(d->sds, j)); + + free_percpu(d->sds); + d->sds =3D NULL; +} + static struct sched_domain *build_sched_domain(struct sched_domain_topolog= y_level *tl, const struct cpumask *cpu_map, struct sched_domain_attr *attr, struct sched_domain *child, int cpu) --=20 2.34.1