Skip to content

Commit

Permalink
sbitmap: don't loop for find_next_zero_bit() for !round_robin
Browse files Browse the repository at this point in the history
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 <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Nov 29, 2018
1 parent b2c5d16 commit 27fae42
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/sbitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,29 @@ int sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint, bool round_robin)

index = SB_NR_TO_INDEX(sb, alloc_hint);

/*
* Unless we're doing round robin tag allocation, just use the
* alloc_hint to find the right word index. No point in looping
* twice in find_next_zero_bit() for that case.
*/
if (round_robin)
alloc_hint = SB_NR_TO_BIT(sb, alloc_hint);
else
alloc_hint = 0;

for (i = 0; i < sb->map_nr; i++) {
nr = __sbitmap_get_word(&sb->map[index].word,
sb->map[index].depth,
SB_NR_TO_BIT(sb, alloc_hint),
sb->map[index].depth, alloc_hint,
!round_robin);
if (nr != -1) {
nr += index << sb->shift;
break;
}

/* 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;
Expand Down

0 comments on commit 27fae42

Please sign in to comment.