From: "孙毅 (Yi Sun)" <Yi.Sun@unisoc.com>
To: Yury Norov <ynorov@nvidia.com>
Cc: "yury.norov@gmail.com" <yury.norov@gmail.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mina86@mina86.com" <mina86@mina86.com>,
"akinobu.mita@gmail.com" <akinobu.mita@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"王皓 (Hao_hao Wang)" <Hao_hao.Wang@unisoc.com>,
"王科 (Ke Wang)" <Ke.Wang@unisoc.com>,
"Michał Nazarewicz" <mnazarewicz@gmail.com>
Subject: 答复: [PATCH 2/2] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off()
Date: Thu, 14 May 2026 03:02:02 +0000 [thread overview]
Message-ID: <cb4418d8199e49a9a111aeac031a323c@BJMBX02.spreadtrum.com> (raw)
In-Reply-To: <agNam-ydNHkWbQgA@yury>
> -----邮件原件-----
> 发件人: Yury Norov <ynorov@nvidia.com>
> 发送时间: 2026年5月13日 0:52
> 收件人: 孙毅 (Yi Sun) <Yi.Sun@unisoc.com>
> 抄送: yury.norov@gmail.com; akpm@linux-foundation.org;
> mina86@mina86.com; akinobu.mita@gmail.com; linux-kernel@vger.kernel.org
> 主题: Re: [PATCH 2/2] lib: bitmap: reduce the number of goto again in
> bitmap_find_next_zero_area_off()
>
>
> 注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链
> 接和附件。
> CAUTION: This email originated from outside of the organization. Do not click links
> or open attachments unless you recognize the sender and know the content is
> safe.
>
>
>
> On Tue, May 12, 2026 at 12:06:59PM +0800, 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 "goto again" calls.
> >
> > Signed-off-by: Yi Sun <yi.sun@unisoc.com>
> > ---
> > lib/bitmap.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/bitmap.c b/lib/bitmap.c
> > index b9bfa157e095..53961a7683a4 100644
> > --- a/lib/bitmap.c
> > +++ b/lib/bitmap.c
> > @@ -442,7 +442,7 @@ unsigned long
> bitmap_find_next_zero_area_off(unsigned long *map,
> > end = index + nr;
> > if (end > size)
> > return end;
> > - i = find_next_bit(map, end, index);
> > + i = find_last_bit_range(map, end, index);
> > if (i < end) {
> > start = i + 1;
> > goto again;
>
> If the only user of the API is in-house, I believe we can just move
> the 'map' pointer and decrease the 'end' accordingly:
>
> i = find_last_bit(map + BITS_TO_LONGS(index),
> end - round_down(index, BITS_PER_LONG));
>
> That way you'll be able to bail out earlier just as well.
That's true, but this makes the bitmap_find_next_zero_area_off() more complex.
I will submit the changes as PATCH v2.
find_last_bit_range() is only used here for now, but I believe it will be useful in the future.
Thanks to Michał Nazarewicz for his suggestions on optimizing find_last_bit_range().
I will submit the optimized code to PATCH v3.
>
> (Not tested, just an illustration)
>
> Thanks,
> Yury
next prev parent reply other threads:[~2026-05-14 3:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 4:06 [PATCH 0/2] Improve the performance of bitmap_find_next_zero_area_off() Yi Sun
2026-05-12 4:06 ` [PATCH 1/2] lib: bitmap: add find_last_bit_range() and _find_last_bit_range() Yi Sun
2026-05-12 11:31 ` Michał Nazarewicz
2026-05-12 16:46 ` Yury Norov
2026-05-12 4:06 ` [PATCH 2/2] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off() Yi Sun
2026-05-12 11:32 ` Michał Nazarewicz
2026-05-12 16:51 ` Yury Norov
2026-05-14 3:02 ` 孙毅 (Yi Sun) [this message]
2026-05-12 16:34 ` [PATCH 0/2] Improve the performance of bitmap_find_next_zero_area_off() 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=cb4418d8199e49a9a111aeac031a323c@BJMBX02.spreadtrum.com \
--to=yi.sun@unisoc.com \
--cc=Hao_hao.Wang@unisoc.com \
--cc=Ke.Wang@unisoc.com \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mina86@mina86.com \
--cc=mnazarewicz@gmail.com \
--cc=ynorov@nvidia.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®