Re: [PATCH v2 1/2] lib/sbitmap: convert shallow_depth from one word to the whole sbitmap

From: Yu Kuai
Date: Wed Jul 30 2025 - 14:24:57 EST


hi, Jan!

在 2025/7/30 21:03, Jan Kara 写道:
I think having two APIs will be even more confusing than the current state.
But as I wrote I think you can have API to specify shallow depth in total
size and in sbitmap_queue_get_shallow() do:

shallow_per_word = (shallow_depth << sb->shift) / sb->depth;
rounding_index = shallow_depth - shallow_per_word * sb->depth;

and allow depth shallow_per_word + 1 if current index < rounding_index and
exactly shallow_per_word if current index >= rounding_index. This will
still evenly distribute shallow depth among words and I don't think the
additional overhead of the several arithmetic operations will be visible.
Yes, you're right, I did not get your idea before. Thanks for the explanation
and the suggestion :) Will follow this idea in the next version.

Thanks