linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dennis Zhou <dennis@kernel.org>
To: Hyunmin Lee <hyunminrlee@gmail.com>
Cc: linux-mm@kvack.org, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@gentwo.org>
Subject: Re: [PATCH] percpu: reduce the time complexity of mapping units and cpus
Date: Wed, 18 Jun 2025 18:50:34 -0700	[thread overview]
Message-ID: <aFNs6go-7BOhDaWv@snowbird> (raw)
In-Reply-To: <20250613042138.10083-1-hyunminrlee@gmail.com>

Hello,

On Fri, Jun 13, 2025 at 01:21:38PM +0900, Hyunmin Lee wrote:
> 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.
> 

Idk. For any single socket machine, it's even money. For large machines
with say 4+ numa nodes, you're not really going to notice the
microseconds the extra for loop is going to take.

I'm neutral but inclined to prefer what's already there.

> 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;
> +	}
> +

Nit: the struct declaration goes at the top in the block.

for_each_possible_cpu(cpu) {
    struct pcpu_group_info *gi;

    group = group_map[cpu];
    gi = &ai->groups[group];

    gi->cpu_map[gi->nr_units++] = cpu;
}

Or condense it into a single line:

for_each_possible_cpu(cpu) {
    struct pcpu_group_info *gi = &ai->groups[group_map[cpu]];

    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
> 

Thanks,
Dennis


      reply	other threads:[~2025-06-19  1:50 UTC|newest]

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

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=aFNs6go-7BOhDaWv@snowbird \
    --to=dennis@kernel.org \
    --cc=cl@gentwo.org \
    --cc=hyunminrlee@gmail.com \
    --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