Re: [PATCH 2/2] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off()

From: Michał Nazarewicz

Date: Tue May 12 2026 - 07:32:56 EST


On Tue, May 12 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 "goto again" calls.
>
> Signed-off-by: Yi Sun <yi.sun@xxxxxxxxxx>

Acked-by: Michał Nazarewicz <mina86@xxxxxxxxxx>

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

--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴィツ
«If at first you don’t succeed, give up skydiving»