* [PATCH v2 0/1] Improve the performance of bitmap_find_next_zero_area_off()
@ 2026-05-14 3:56 Yi Sun
2026-05-14 3:56 ` [PATCH v2 1/1] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off() Yi Sun
0 siblings, 1 reply; 2+ messages in thread
From: Yi Sun @ 2026-05-14 3:56 UTC (permalink / raw)
To: yury.norov, mnazarewicz; +Cc: akpm, mina86, akinobu.mita, linux-kernel, yi.sun
Instead of introducing new function
like find_last_bit_range/off/from(),
the existing find_last_bit() is used,
achieving the same effect as PATCH v1.
---
v1: https://lore.kernel.org/all/20260512040659.2992142-1-yi.sun@unisoc.com
Yi Sun (1):
lib: bitmap: reduce the number of goto again in
bitmap_find_next_zero_area_off()
lib/bitmap.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 1/1] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off()
2026-05-14 3:56 [PATCH v2 0/1] Improve the performance of bitmap_find_next_zero_area_off() Yi Sun
@ 2026-05-14 3:56 ` Yi Sun
0 siblings, 0 replies; 2+ messages in thread
From: Yi Sun @ 2026-05-14 3:56 UTC (permalink / raw)
To: yury.norov, mnazarewicz; +Cc: akpm, mina86, akinobu.mita, linux-kernel, yi.sun
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 | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index b9bfa157e095..7d0fbcbe6973 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -432,7 +432,7 @@ unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
unsigned long align_mask,
unsigned long align_offset)
{
- unsigned long index, end, i;
+ unsigned long index, end, i, index_bits_align, index_idx;
again:
index = find_next_zero_bit(map, size, start);
@@ -442,8 +442,12 @@ 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);
- if (i < end) {
+
+ index_bits_align = round_down(index, BITS_PER_LONG);
+ index_idx = index / BITS_PER_LONG;
+
+ i = find_last_bit(map + index_idx, end - index_bits_align) + index_bits_align;
+ if (i > index && i < end) {
start = i + 1;
goto again;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-14 3:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14 3:56 [PATCH v2 0/1] Improve the performance of bitmap_find_next_zero_area_off() Yi Sun
2026-05-14 3:56 ` [PATCH v2 1/1] lib: bitmap: reduce the number of goto again in bitmap_find_next_zero_area_off() Yi Sun
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.