答复: [PATCH v3 2/2] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off()
From: 孙毅 (Yi Sun)
Date: Wed May 27 2026 - 05:27:14 EST
> -----邮件原件-----
> 发件人: Yury Norov <ynorov@xxxxxxxxxx>
> 发送时间: 2026年5月15日 1:19
> 收件人: 孙毅 (Yi Sun) <Yi.Sun@xxxxxxxxxx>
> 抄送: yury.norov@xxxxxxxxx; mnazarewicz@xxxxxxxxx; akpm@linux-
> foundation.org; mina86@xxxxxxxxxx; akinobu.mita@xxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx
> 主题: Re: [PATCH v3 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 Thu, May 14, 2026 at 05:06:07PM +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.
>
> This is the good place to put your perf numbers. Does it have a real
> impact, other than the micro-benchmark?
It might benefit cma_alloc(), but I haven't tested it.
>
> > Signed-off-by: Yi Sun <yi.sun@xxxxxxxxxx>
>
> There is a for_each_set_bit_range() iterators family. They are similar
> to the bitmap_find_next_zero_area_off(), and may also benefit from the
> rework.
>
> I think the most questionable part of this work is that you switch a
> single function to the new API. Can you check the above and other
> possible candidates please, before we move forward?
I haven't found a second place where I can use the new API.
>
> Thanks,
> Yury
>
> > ---
> > lib/bitmap.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/bitmap.c b/lib/bitmap.c
> > index b9bfa157e095..9b589643f72a 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_from(map, end, index);
> > if (i < end) {
> > start = i + 1;
> > goto again;
> > --
> > 2.34.1