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 <jack@suse.cz>
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Link: https://lore.kernel.org/r/20230116205059.3821738-2-shikemeng@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Kemeng Shi 2023-01-17 04:50:55 +08:00 committed by Jens Axboe
parent f1c006f1c6
commit f1591a8bb3

View File

@ -243,6 +243,7 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
int nr = -1; int nr = -1;
index = SB_NR_TO_INDEX(sb, alloc_hint); index = SB_NR_TO_INDEX(sb, alloc_hint);
alloc_hint = SB_NR_TO_BIT(sb, alloc_hint);
for (i = 0; i < sb->map_nr; i++) { for (i = 0; i < sb->map_nr; i++) {
again: again:
@ -250,7 +251,7 @@ again:
min_t(unsigned int, min_t(unsigned int,
__map_depth(sb, index), __map_depth(sb, index),
shallow_depth), shallow_depth),
SB_NR_TO_BIT(sb, alloc_hint), true); alloc_hint, true);
if (nr != -1) { if (nr != -1) {
nr += index << sb->shift; nr += index << sb->shift;
break; break;
@ -260,13 +261,9 @@ again:
goto again; goto again;
/* Jump to next index. */ /* Jump to next index. */
index++; alloc_hint = 0;
alloc_hint = index << sb->shift; if (++index >= sb->map_nr)
if (index >= sb->map_nr) {
index = 0; index = 0;
alloc_hint = 0;
}
} }
return nr; return nr;