Skip to content

Commit f1591a8

Browse files
Kemeng Shiaxboe
authored andcommitted
sbitmap: remove unnecessary calculation of alloc_hint in __sbitmap_get_shallow
Updates to alloc_hint in the loop in __sbitmap_get_shallow() are mostly pointless and equivalent to setting alloc_hint to zero (because SB_NR_TO_BIT() considers only low sb->shift bits from alloc_hint). So simplify the logic. Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Kemeng Shi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f1c006f commit f1591a8

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/sbitmap.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,15 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
243243
int nr = -1;
244244

245245
index = SB_NR_TO_INDEX(sb, alloc_hint);
246+
alloc_hint = SB_NR_TO_BIT(sb, alloc_hint);
246247

247248
for (i = 0; i < sb->map_nr; i++) {
248249
again:
249250
nr = __sbitmap_get_word(&sb->map[index].word,
250251
min_t(unsigned int,
251252
__map_depth(sb, index),
252253
shallow_depth),
253-
SB_NR_TO_BIT(sb, alloc_hint), true);
254+
alloc_hint, true);
254255
if (nr != -1) {
255256
nr += index << sb->shift;
256257
break;
@@ -260,13 +261,9 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
260261
goto again;
261262

262263
/* Jump to next index. */
263-
index++;
264-
alloc_hint = index << sb->shift;
265-
266-
if (index >= sb->map_nr) {
264+
alloc_hint = 0;
265+
if (++index >= sb->map_nr)
267266
index = 0;
268-
alloc_hint = 0;
269-
}
270267
}
271268

272269
return nr;

0 commit comments

Comments
 (0)