Skip to content

Commit cadcdd7

Browse files
committed
sbitmap: rewrite sbitmap_find_bit_in_index to reduce repeat code
jira LE-4066 Rebuild_History Non-Buildable kernel-4.18.0-553.72.1.el8_10 commit-author Kemeng Shi <shikemeng@huaweicloud.com> commit 08470a9 Rewrite sbitmap_find_bit_in_index as following: 1. Rename sbitmap_find_bit_in_index to sbitmap_find_bit_in_word 2. Accept "struct sbitmap_word *" directly instead of accepting "struct sbitmap *" and "int index" to get "struct sbitmap_word *". 3. Accept depth/shallow_depth and wrap for __sbitmap_get_word from caller to support need of both __sbitmap_get_shallow and __sbitmap_get. With helper function sbitmap_find_bit_in_word, we can remove repeat code in __sbitmap_get_shallow to find bit considring deferred clear. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> Link: https://lore.kernel.org/r/20230116205059.3821738-4-shikemeng@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit 08470a9) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent f3b461b commit cadcdd7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/sbitmap.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,16 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
187187
return nr;
188188
}
189189

190-
static int sbitmap_find_bit_in_index(struct sbitmap *sb, int index,
191-
unsigned int alloc_hint)
190+
static int sbitmap_find_bit_in_word(struct sbitmap_word *map,
191+
unsigned int depth,
192+
unsigned int alloc_hint,
193+
bool wrap)
192194
{
193-
struct sbitmap_word *map = &sb->map[index];
194195
int nr;
195196

196197
do {
197-
nr = __sbitmap_get_word(&map->word, __map_depth(sb, index),
198-
alloc_hint, !sb->round_robin);
198+
nr = __sbitmap_get_word(&map->word, depth,
199+
alloc_hint, wrap);
199200
if (nr != -1)
200201
break;
201202
if (!sbitmap_deferred_clear(map))
@@ -223,7 +224,9 @@ static int __sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint)
223224
alloc_hint = 0;
224225

225226
for (i = 0; i < sb->map_nr; i++) {
226-
nr = sbitmap_find_bit_in_index(sb, index, alloc_hint);
227+
nr = sbitmap_find_bit_in_word(&sb->map[index],
228+
__map_depth(sb, index),
229+
alloc_hint, !sb->round_robin);
227230
if (nr != -1) {
228231
nr += index << sb->shift;
229232
break;
@@ -267,20 +270,17 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
267270
alloc_hint = SB_NR_TO_BIT(sb, alloc_hint);
268271

269272
for (i = 0; i < sb->map_nr; i++) {
270-
again:
271-
nr = __sbitmap_get_word(&sb->map[index].word,
272-
min_t(unsigned int,
273-
__map_depth(sb, index),
274-
shallow_depth),
275-
alloc_hint, true);
273+
nr = sbitmap_find_bit_in_word(&sb->map[index],
274+
min_t(unsigned int,
275+
__map_depth(sb, index),
276+
shallow_depth),
277+
alloc_hint, true);
278+
276279
if (nr != -1) {
277280
nr += index << sb->shift;
278281
break;
279282
}
280283

281-
if (sbitmap_deferred_clear(&sb->map[index]))
282-
goto again;
283-
284284
/* Jump to next index. */
285285
alloc_hint = 0;
286286
if (++index >= sb->map_nr)

0 commit comments

Comments
 (0)