From: "Michał Nazarewicz" <mina86@mina86.com>
To: Yi Sun <yi.sun@unisoc.com>, yury.norov@gmail.com
Cc: yi.sun@unisoc.com, 279644543@qq.com, akpm@linux-foundation.org,
akinobu.mita@gmail.com, linux-kernel@vger.kernel.org,
tjmercier@google.com, fvdl@google.com, tglx@kernel.org,
song@kernel.org, hch@lst.de, minchan@kernel.org,
jstultz@google.com
Subject: Re: [PATCH v7 2/2] lib: bitmap: optimize bitmap_find_next_zero_area_off()
Date: Mon, 22 Jun 2026 11:56:51 +0200 [thread overview]
Message-ID: <78yemtv2gix92wc9z7d08rfw@mina86.com> (raw)
In-Reply-To: <20260622030036.1744080-3-yi.sun@unisoc.com>
On Mon, Jun 22 2026, Yi Sun wrote:
> Finding a contiguous free region in a highly fragmented
> bitmap is not easy and may require many repeated attempts.
> Therefore, find_next_bit(map, end, index) is not the optimal choice.
> This is because there may be multiple scattered free regions
> within the range [index, end) and none of them will meet the length
> requirement of @nr.
> Instead, it's sufficient to directly find the last bit within
> the range [index, end), thus reducing unnecessary repeated calls.
[…]
> Co-developed-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Yi Sun <yi.sun@unisoc.com>
Acked-by: Michał Nazarewicz <mina86@mina86.com>
> ---
> lib/bitmap.c | 31 ++++++++++++++++---------------
> 1 file changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index b9bfa157e095..a00a71f2b7bb 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -432,22 +432,23 @@ unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
> unsigned long align_mask,
> unsigned long align_offset)
> {
[…]
> + unsigned long end, i, off;
> +
> + for_each_clear_bit_from(start, map, size) {
> + start = __ALIGN_MASK(start + align_offset, align_mask) - align_offset;
> + end = start + nr;
> + if (end > size)
> + break;
> +
> + off = round_down(start, BITS_PER_LONG);
> + i = find_last_bit(map + start / BITS_PER_LONG, end - off) + off;
> + if (i >= end || i < start)
> + return start;
> +
> + start = i;
Gotta be honest, I’m not a fan of `for_each_clear_bit_from` the way it’s
used here. It hides the `start++` that happens at end of each loop.
The code works either way, but I find the current form harder to read
than an infinite loop.
Having said that, Yury is the maintainer here so if he prefers that, I’m
obviously not gonna fight it.
> }
> - return index;
> +
> + return size;
> }
> EXPORT_SYMBOL(bitmap_find_next_zero_area_off);
--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴィツ
«If at first you don’t succeed, give up skydiving»
next prev parent reply other threads:[~2026-06-22 9:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 3:00 [PATCH v7 0/2] Improve the performance of bitmap_find_next_zero_area_off() Yi Sun
2026-06-22 3:00 ` [PATCH v7 1/2] lib: bitmap: add tests for bitmap_find_next_zero_area_off() Yi Sun
2026-06-22 10:05 ` Michał Nazarewicz
2026-06-22 12:39 ` 答复: " 孙毅 (Yi Sun)
2026-06-22 3:00 ` [PATCH v7 2/2] lib: bitmap: optimize bitmap_find_next_zero_area_off() Yi Sun
2026-06-22 9:56 ` Michał Nazarewicz [this message]
2026-06-30 20:52 ` Nathan Chancellor
2026-06-30 23:13 ` Yury Norov
2026-07-04 9:12 ` yi.sun
2026-07-04 22:03 ` Yury Norov
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=78yemtv2gix92wc9z7d08rfw@mina86.com \
--to=mina86@mina86.com \
--cc=279644543@qq.com \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=fvdl@google.com \
--cc=hch@lst.de \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=song@kernel.org \
--cc=tglx@kernel.org \
--cc=tjmercier@google.com \
--cc=yi.sun@unisoc.com \
--cc=yury.norov@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
all inboxes | Powered by JetHome®