linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] percpu: reduce the time complexity of mapping units and cpus
@ 2025-06-13  4:21 Hyunmin Lee
  2025-06-19  1:50 ` Dennis Zhou
  0 siblings, 1 reply; 2+ messages in thread
From: Hyunmin Lee @ 2025-06-13  4:21 UTC (permalink / raw)
  To: linux-mm; +Cc: Dennis Zhou, Tejun Heo, Christoph Lameter

For mapping units and CPUs belonging to groups, it can be inefficient to
iterate through all CPUs by each group to find what CPUs belong to that
group.

Since group_map already has the information on which CPUs belong to which
group, CPUs can be directly mapped to a unit in the group to which the CPU
belongs.

Signed-off-by: Hyunmin Lee <hyunminrlee@gmail.com>
---
 mm/percpu.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index b35494c8ede2..968aa0ace482 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -2906,6 +2906,13 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
 	ai->atom_size = atom_size;
 	ai->alloc_size = alloc_size;
 
+	for_each_possible_cpu(cpu) {
+		group = group_map[cpu];
+		struct pcpu_group_info *gi = &ai->groups[group];
+
+		gi->cpu_map[gi->nr_units++] = cpu;
+	}
+
 	for (group = 0, unit = 0; group < nr_groups; group++) {
 		struct pcpu_group_info *gi = &ai->groups[group];
 
@@ -2916,9 +2923,6 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
 		 */
 		gi->base_offset = unit * ai->unit_size;
 
-		for_each_possible_cpu(cpu)
-			if (group_map[cpu] == group)
-				gi->cpu_map[gi->nr_units++] = cpu;
 		gi->nr_units = roundup(gi->nr_units, upa);
 		unit += gi->nr_units;
 	}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-19  1:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13  4:21 [PATCH] percpu: reduce the time complexity of mapping units and cpus Hyunmin Lee
2025-06-19  1:50 ` Dennis Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).