From: Dennis Zhou <dennis@kernel.org>
To: Yuntao Wang <ytcoode@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] percpu: simplify the logic of pcpu_alloc_first_chunk()
Date: Tue, 23 Apr 2024 22:12:00 -0700 [thread overview]
Message-ID: <ZiiUoC5NokdpvDgN@snowbird> (raw)
In-Reply-To: <20240423135525.36872-1-ytcoode@gmail.com>
Hi Yuntao,
On Tue, Apr 23, 2024 at 09:55:25PM +0800, Yuntao Wang wrote:
> In the logic for hiding the end of the bitmap, there are several places
> where the same value 'region_bits - offset_bits' is calculated over and
> over again using different methods. Eliminate these redundant calculations
> to improve code readability.
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> mm/percpu.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/mm/percpu.c b/mm/percpu.c
> index 4e11fc1e6def..2a051f00f68d 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -1421,15 +1421,13 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
> if (chunk->end_offset) {
> /* hide the end of the bitmap */
> offset_bits = chunk->end_offset / PCPU_MIN_ALLOC_SIZE;
> - bitmap_set(chunk->alloc_map,
> - pcpu_chunk_map_bits(chunk) - offset_bits,
> - offset_bits);
> - set_bit((start_offset + map_size) / PCPU_MIN_ALLOC_SIZE,
> - chunk->bound_map);
> + start_offset = region_bits - offset_bits;
Generally I think this makes sense, but I'm less inclined to mix the
start_offset variable name in here.
A helper function might make this cleaner, consolidating the
start_offset and end_offset logic.
static void pcpu_chunk_hide_region(chunk, bit_off, bits);
Thanks,
Dennis
> +
> + bitmap_set(chunk->alloc_map, start_offset, offset_bits);
> + set_bit(start_offset, chunk->bound_map);
> set_bit(region_bits, chunk->bound_map);
>
> - pcpu_block_update_hint_alloc(chunk, pcpu_chunk_map_bits(chunk)
> - - offset_bits, offset_bits);
> + pcpu_block_update_hint_alloc(chunk, start_offset, offset_bits);
> }
>
> return chunk;
> --
> 2.44.0
>
next prev parent reply other threads:[~2024-04-24 5:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 13:55 Yuntao Wang
2024-04-24 5:12 ` Dennis Zhou [this message]
2024-04-24 8:27 ` [PATCH v2] " Yuntao Wang
2024-05-14 1:25 ` [PATCH] " Yuntao Wang
2024-05-14 1:30 ` 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=ZiiUoC5NokdpvDgN@snowbird \
--to=dennis@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tj@kernel.org \
--cc=ytcoode@gmail.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