linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hyunmin Lee <hyunminrlee@gmail.com>
To: linux-mm@kvack.org
Cc: Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@gentwo.org>
Subject: [PATCH] percpu: reduce the time complexity of mapping units and cpus
Date: Fri, 13 Jun 2025 13:21:38 +0900	[thread overview]
Message-ID: <20250613042138.10083-1-hyunminrlee@gmail.com> (raw)

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



             reply	other threads:[~2025-06-13  4:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-13  4:21 Hyunmin Lee [this message]
2025-06-19  1:50 ` Dennis Zhou

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=20250613042138.10083-1-hyunminrlee@gmail.com \
    --to=hyunminrlee@gmail.com \
    --cc=cl@gentwo.org \
    --cc=dennis@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tj@kernel.org \
    /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