[PATCH v8 0/2] Improve the performance of bitmap_find_next_zero_area_off()

From: Yi Sun

Date: Mon Jun 22 2026 - 09:11:57 EST


Use lib/find_bit_benchmark.c for testing.
Test results showed a 40% improvement in dense cases,
and almost no change in sparse cases.

Performance test results on my hardware:
before(ns) after(ns) change p-value
dense 1211 688 -43.2% 8.3e-11
sparse 13.3 13.4 0.8% 0.27

Version 8 improve test code.
When original bitmap_find_next_zero_area_off() fails,
it returns end, where end is greater than size.
Therefore, patch1 should use >.
expect_eq_uint(1,
bitmap_find_next_zero_area_off(bmap, 192, 0, 33, 0, 0) > 192);

When new bitmap_find_next_zero_area_off() fails, it returns size.
Therefore, patch2 should be changed to =.
expect_eq_uint(192,
bitmap_find_next_zero_area_off(bmap, 192, 0, 33, 0, 0));

---
v7: https://lore.kernel.org/all/20260622030036.1744080-1-yi.sun@xxxxxxxxxx
- Only changed the alignment format of the test code.

v6: https://lore.kernel.org/all/20260618133518.4079981-1-yi.sun@xxxxxxxxxx
- Improve test code.
- Change infinite for loop to for_each_clear_bit_from.

v5: https://lore.kernel.org/all/20260618015252.3601554-1-yi.sun@xxxxxxxxxx
- Improve test code.
- Change the "goto again" code structure to a for loop.

v4: https://lore.kernel.org/all/20260601094234.103863-1-yi.sun@xxxxxxxxxx
- Test code has been added to PATCH v2.

v3: https://lore.kernel.org/all/20260514090607.231387-1-yi.sun@xxxxxxxxxx
- Code optimization was performed on PATCH v1.

v2: https://lore.kernel.org/all/20260514035644.4118050-1-yi.sun@xxxxxxxxxx
- Do not introduce find_last_bit_from().

v1: https://lore.kernel.org/all/20260512040659.2992142-1-yi.sun@xxxxxxxxxx


Yi Sun (2):
lib: bitmap: add tests for bitmap_find_next_zero_area_off()
lib: bitmap: optimize bitmap_find_next_zero_area_off()

lib/bitmap.c | 31 ++++++++++++++++---------------
lib/find_bit_benchmark.c | 17 +++++++++++++++++
lib/test_bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 15 deletions(-)

--
2.34.1