答复: [PATCH v7 1/2] lib: bitmap: add tests for bitmap_find_next_zero_area_off()
From: 孙毅 (Yi Sun)
Date: Mon Jun 22 2026 - 08:40:23 EST
> -----邮件原件-----
> 发件人: Michał Nazarewicz <mnazarewicz@xxxxxxxxx> 代表 Micha?
> Nazarewicz
> 发送时间: 2026年6月22日 18:06
> 收件人: 孙毅 (Yi Sun) <Yi.Sun@xxxxxxxxxx>; yury.norov@xxxxxxxxx
> 抄送: 孙毅 (Yi Sun) <Yi.Sun@xxxxxxxxxx>; 279644543@xxxxxx; akpm@linux-
> foundation.org; akinobu.mita@xxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> tjmercier@xxxxxxxxxx; fvdl@xxxxxxxxxx; tglx@xxxxxxxxxx; song@xxxxxxxxxx;
> hch@xxxxxx; minchan@xxxxxxxxxx; jstultz@xxxxxxxxxx
> 主题: Re: [PATCH v7 1/2] lib: bitmap: add tests for
> 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 Mon, Jun 22 2026, Yi Sun wrote:
> > Add functional and performance tests
> > for bitmap_find_next_zero_area_off().
> >
> > performance tests partial output:
> > Start testing find_bit() with random-filled bitmap
> > [ 0.310073] bitmap_find_next_zero_area_off: 852731 ns, 1154 iterations
> > [ 0.311435] find_next_bit: 1356654 ns, 163975 iterations
> > Start testing find_bit() with sparse bitmap
> > [ 0.316267] bitmap_find_next_zero_area_off:4426808 ns, 322479 iterations
> > [ 0.316292] find_next_bit: 15154 ns, 656 iterations
> >
> > Signed-off-by: Yi Sun <yi.sun@xxxxxxxxxx>
>
> Acked-by: Michał Nazarewicz <mina86@xxxxxxxxxx>
>
> > ---
> > lib/find_bit_benchmark.c | 17 +++++++++++++++++
> > lib/test_bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 55 insertions(+)
> >
> > diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c
> > index 00d9dc61cd46..05305e655f99 100644
> > --- a/lib/find_bit_benchmark.c
> > +++ b/lib/find_bit_benchmark.c
> > @@ -149,6 +149,21 @@ static int __init test_find_next_and_bit(const void
> *bitmap,
> > return 0;
> > }
> >
> > +static int __init
> > +test_bitmap_find_next_zero_area_off(unsigned long *bitmap, unsigned long
> len)
> > +{
> > + unsigned long i, cnt;
> > + ktime_t time;
> > +
> > + time = ktime_get();
> > + for (cnt = i = 0; i < BITMAP_LEN; cnt++)
> > + i = bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN, i, 8, 0, 0) + 1;
> > + time = ktime_get() - time;
> > + pr_err("bitmap_find_next_zero_area_off:%7llu ns, %6ld iterations\n", time,
> cnt);
> > +
> > + return 0;
> > +}
> > +
> > static int __init find_bit_test(void)
> > {
> > unsigned long nbits = BITMAP_LEN / SPARSE;
> > @@ -158,6 +173,7 @@ static int __init find_bit_test(void)
> > get_random_bytes(bitmap, sizeof(bitmap));
> > get_random_bytes(bitmap2, sizeof(bitmap2));
> >
> > + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN);
> > test_find_next_bit(bitmap, BITMAP_LEN);
> > test_find_next_zero_bit(bitmap, BITMAP_LEN);
> > test_find_last_bit(bitmap, BITMAP_LEN);
> > @@ -181,6 +197,7 @@ static int __init find_bit_test(void)
> > __set_bit(get_random_u32_below(BITMAP_LEN), bitmap2);
> > }
> >
> > + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN);
> > test_find_next_bit(bitmap, BITMAP_LEN);
> > test_find_next_zero_bit(bitmap, BITMAP_LEN);
> > test_find_last_bit(bitmap, BITMAP_LEN);
> > diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> > index 69813c10e6c0..8665df77c960 100644
> > --- a/lib/test_bitmap.c
> > +++ b/lib/test_bitmap.c
> > @@ -234,6 +234,43 @@ static void __init test_find_nth_bit(void)
> > }
> > }
> >
> > +static void __init
> > +test_bitmap_find_next_zero_area_off(void)
> > +{
> > + DECLARE_BITMAP(bmap, 192);
> > +
> > + bitmap_set(bmap, 0, 192);
> > +
> > + bitmap_clear(bmap, 0, 8);
> > + __clear_bit(50, bmap);
> > + bitmap_clear(bmap, 60, 18);
> > + __set_bit(69, bmap);
> > + __clear_bit(80, bmap);
> > + bitmap_clear(bmap, 100, 10);
> > + __clear_bit(120, bmap);
> > + bitmap_clear(bmap, 145, 8);
> > + bitmap_clear(bmap, 160, 32);
> > +
> > + expect_eq_uint(0,
> > + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 0, 0));
> > + expect_eq_uint(0,
> > + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 0));
> > + expect_eq_uint(163,
> > + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 1));
> > + expect_eq_uint(60,
> > + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 0, 0));
> > + expect_eq_uint(160,
> > + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 0));
> > + expect_eq_uint(60,
> > + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 4));
> > + expect_eq_uint(100,
> > + bitmap_find_next_zero_area_off(bmap, 192, 0, 10, 0, 0));
> > + expect_eq_uint(160,
> > + bitmap_find_next_zero_area_off(bmap, 192, 0, 32, 0, 0));
> > + expect_eq_uint(1,
> > + !!(bitmap_find_next_zero_area_off(bmap, 192, 0, 33, 0, 0) >= 192));
>
> In C `x >= y` yields 0 or 1. There’s no need for `!!`.
>
> About `>` vs `>=`, the original code returns `> 192` (because it returns
> `end` when it exceeds `size`). The new code returns `192` (because it
> returns `size` if loop fails to find an area). If that’s the case, this
> patch, PATCH 1/2, should have `>` and PATCH 2/2 should change it to
> `expect_eq_uint(192, …)` to reflect change in the API.
>
Very helpful feedback.
I will make changes in v8.
> > +}
> > +
> > static void __init test_fill_set(void)
> > {
> > DECLARE_BITMAP(bmap, 1024);
> > @@ -1559,6 +1596,7 @@ static void __init selftest(void)
> > test_for_each_clear_bitrange_from();
> > test_for_each_set_clump8();
> > test_for_each_set_bit_wrap();
> > + test_bitmap_find_next_zero_area_off();
> > }
> >
> > KSTM_MODULE_LOADERS(test_bitmap);
>
> --
> Best regards
> ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴィツ
> «If at first you don’t succeed, give up skydiving»