Skip to content

Commit 27fae42

Browse files
committed
sbitmap: don't loop for find_next_zero_bit() for !round_robin
If we aren't forced to do round robin tag allocation, just use the allocation hint to find the index for the tag word, don't use it for the offset inside the word. This avoids a potential extra round trip in the bit looping, and since we're fetching this cacheline, we may as well check the whole word from the start. Reviewed-by: Omar Sandoval <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b2c5d16 commit 27fae42

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/sbitmap.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,29 @@ int sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint, bool round_robin)
118118

119119
index = SB_NR_TO_INDEX(sb, alloc_hint);
120120

121+
/*
122+
* Unless we're doing round robin tag allocation, just use the
123+
* alloc_hint to find the right word index. No point in looping
124+
* twice in find_next_zero_bit() for that case.
125+
*/
126+
if (round_robin)
127+
alloc_hint = SB_NR_TO_BIT(sb, alloc_hint);
128+
else
129+
alloc_hint = 0;
130+
121131
for (i = 0; i < sb->map_nr; i++) {
122132
nr = __sbitmap_get_word(&sb->map[index].word,
123-
sb->map[index].depth,
124-
SB_NR_TO_BIT(sb, alloc_hint),
133+
sb->map[index].depth, alloc_hint,
125134
!round_robin);
126135
if (nr != -1) {
127136
nr += index << sb->shift;
128137
break;
129138
}
130139

131140
/* Jump to next index. */
132-
index++;
133-
alloc_hint = index << sb->shift;
134-
135-
if (index >= sb->map_nr) {
141+
alloc_hint = 0;
142+
if (++index >= sb->map_nr)
136143
index = 0;
137-
alloc_hint = 0;
138-
}
139144
}
140145

141146
return nr;

0 commit comments

Comments
 (0)