@@ -243,6 +243,7 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
int nr = -1;
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++) {
again:
@@ -250,7 +251,7 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
min_t(unsigned int,
__map_depth(sb, index),
shallow_depth),
- SB_NR_TO_BIT(sb, alloc_hint), true);
+ alloc_hint, true);
if (nr != -1) {
nr += index << sb->shift;
break;
@@ -260,13 +261,9 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
goto again;
/* Jump to next index. */
- index++;
- alloc_hint = index << sb->shift;
-
- if (index >= sb->map_nr) {
+ alloc_hint = 0;
+ if (++index >= sb->map_nr)
index = 0;
- alloc_hint = 0;
- }
}
return nr;
We calculate allow_hint in next word as following: /* low sb->shift bit of alloc_hint will be 0 after this shift */ alloc_hint = index << sb->shift; /* get low sb->shift bit of alloc_hit */ SB_NR_TO_BIT(sb, alloc_hint) So alloc_hit in next word will always be zero. Simpfy alloc_hit calculation in __sbitmap_get_shallow according to the alloc_hit calculation in __sbitmap_get. Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> --- lib/sbitmap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)