From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
<linux-kernel@vger.kernel.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Chen Yu <yu.c.chen@intel.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
K Prateek Nayak <kprateek.nayak@amd.com>
Subject: [PATCH v3 2/8] sched/topology: Allocate per-CPU sched_domain_shared in s_data
Date: Tue, 20 Jan 2026 11:32:40 +0000 [thread overview]
Message-ID: <20260120113246.27987-3-kprateek.nayak@amd.com> (raw)
In-Reply-To: <20260120113246.27987-1-kprateek.nayak@amd.com>
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.
Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
Changelog rfc v2..v3:
o Broke off from a single large patch. Previously
https://lore.kernel.org/lkml/20251208092744.32737-3-kprateek.nayak@amd.com/
---
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 649674bb6c3c..623e8835d322 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -776,6 +776,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
}
struct s_data {
+ struct sched_domain_shared * __percpu *sds;
struct sched_domain * __percpu *sd;
struct root_domain *rd;
};
@@ -783,6 +784,7 @@ struct s_data {
enum s_alloc {
sa_rootdomain,
sa_sd,
+ sa_sd_shared,
sa_sd_storage,
sa_none,
};
@@ -1529,6 +1531,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);
+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)
{
@@ -1540,6 +1545,9 @@ static void __free_domain_allocs(struct s_data *d, enum 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;
@@ -1555,9 +1563,11 @@ __visit_domain_allocation_hell(struct s_data *d, const struct cpumask *cpu_map)
if (__sdt_alloc(cpu_map))
return sa_sd_storage;
+ if (__sds_alloc(d, cpu_map))
+ return sa_sd_shared;
d->sd = alloc_percpu(struct sched_domain *);
if (!d->sd)
- return sa_sd_storage;
+ return sa_sd_shared;
d->rd = alloc_rootdomain();
if (!d->rd)
return sa_sd;
@@ -2458,6 +2468,42 @@ static void __sdt_free(const struct cpumask *cpu_map)
}
}
+static int __sds_alloc(struct s_data *d, const struct cpumask *cpu_map)
+{
+ int j;
+
+ d->sds = alloc_percpu(struct sched_domain_shared *);
+ if (!d->sds)
+ return -ENOMEM;
+
+ for_each_cpu(j, cpu_map) {
+ struct sched_domain_shared *sds;
+
+ sds = kzalloc_node(sizeof(struct sched_domain_shared),
+ GFP_KERNEL, cpu_to_node(j));
+ if (!sds)
+ return -ENOMEM;
+
+ *per_cpu_ptr(d->sds, j) = 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 = NULL;
+}
+
static struct sched_domain *build_sched_domain(struct sched_domain_topology_level *tl,
const struct cpumask *cpu_map, struct sched_domain_attr *attr,
struct sched_domain *child, int cpu)
--
2.34.1
next prev parent reply other threads:[~2026-01-20 11:33 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 11:32 [PATCH v3 0/8] sched/topology: Optimize sd->shared allocation K Prateek Nayak
2026-01-20 11:32 ` [PATCH v3 1/8] sched/topology: Compute sd_weight considering cpuset partitions K Prateek Nayak
2026-01-21 14:45 ` Chen, Yu C
2026-01-21 15:42 ` Shrikanth Hegde
2026-01-22 2:51 ` K Prateek Nayak
2026-02-05 16:53 ` Valentin Schneider
2026-01-20 11:32 ` K Prateek Nayak [this message]
2026-01-21 15:17 ` [PATCH v3 2/8] sched/topology: Allocate per-CPU sched_domain_shared in s_data Chen, Yu C
2026-02-05 16:53 ` Valentin Schneider
2026-01-20 11:32 ` [PATCH v3 3/8] sched/topology: Switch to assigning "sd->shared" from s_data K Prateek Nayak
2026-01-21 15:26 ` Chen, Yu C
2026-01-22 2:49 ` K Prateek Nayak
2026-01-22 8:12 ` Shrikanth Hegde
2026-01-22 8:36 ` K Prateek Nayak
2026-01-23 4:08 ` Shrikanth Hegde
2026-01-23 4:53 ` K Prateek Nayak
2026-02-05 16:53 ` Valentin Schneider
2026-02-06 5:20 ` K Prateek Nayak
2026-02-06 9:38 ` Valentin Schneider
2026-02-14 3:04 ` Chen, Yu C
2026-02-16 3:50 ` K Prateek Nayak
2026-02-14 2:59 ` Chen, Yu C
2026-01-20 11:32 ` [PATCH v3 4/8] sched/topology: Remove sched_domain_shared allocation with sd_data K Prateek Nayak
2026-02-05 16:53 ` Valentin Schneider
2026-01-20 11:32 ` [PATCH v3 5/8] sched/core: Check for rcu_read_lock_any_held() in idle_get_state() K Prateek Nayak
2026-01-20 11:32 ` [PATCH v3 6/8] sched/fair: Remove superfluous rcu_read_lock() in the wakeup path K Prateek Nayak
2026-01-20 11:32 ` [PATCH v3 7/8] sched/fair: Simplify the entry condition for update_idle_cpu_scan() K Prateek Nayak
2026-02-14 15:41 ` Chen, Yu C
2026-01-20 11:32 ` [PATCH v3 8/8] sched/fair: Simplify SIS_UTIL handling in select_idle_cpu() K Prateek Nayak
2026-01-23 6:06 ` Shrikanth Hegde
2026-01-23 6:27 ` K Prateek Nayak
2026-01-23 7:14 ` Shrikanth Hegde
2026-02-14 15:56 ` Chen, Yu C
2026-01-21 16:16 ` [PATCH v3 0/8] sched/topology: Optimize sd->shared allocation Peter Zijlstra
2026-01-22 2:56 ` K Prateek Nayak
2026-01-23 9:54 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260120113246.27987-3-kprateek.nayak@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sshegde@linux.ibm.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yu.c.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®