summaryrefslogtreecommitdiffstats
path: root/lib/sbitmap.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2018-11-29 14:35:16 -0500
committerJens Axboe <axboe@kernel.dk>2018-11-29 15:58:34 -0500
commit27fae429acee1e9418059e7fa545438075af5256 (patch)
tree9d1258df6416f59265bfca42b13c46576963bb9b /lib/sbitmap.c
parentb2c5d16b72df1116f05c9be16a630ac939d34101 (diff)
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 <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'lib/sbitmap.c')
-rw-r--r--lib/sbitmap.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index fdd1b8aa8ac6..45cab6bbc1c7 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -118,10 +118,19 @@ int sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint, bool round_robin)
118 118
119 index = SB_NR_TO_INDEX(sb, alloc_hint); 119 index = SB_NR_TO_INDEX(sb, alloc_hint);
120 120
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
121 for (i = 0; i < sb->map_nr; i++) { 131 for (i = 0; i < sb->map_nr; i++) {
122 nr = __sbitmap_get_word(&sb->map[index].word, 132 nr = __sbitmap_get_word(&sb->map[index].word,
123 sb->map[index].depth, 133 sb->map[index].depth, alloc_hint,
124 SB_NR_TO_BIT(sb, alloc_hint),
125 !round_robin); 134 !round_robin);
126 if (nr != -1) { 135 if (nr != -1) {
127 nr += index << sb->shift; 136 nr += index << sb->shift;
@@ -129,13 +138,9 @@ int sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint, bool round_robin)
129 } 138 }
130 139
131 /* Jump to next index. */ 140 /* Jump to next index. */
132 index++; 141 alloc_hint = 0;
133 alloc_hint = index << sb->shift; 142 if (++index >= sb->map_nr)
134
135 if (index >= sb->map_nr) {
136 index = 0; 143 index = 0;
137 alloc_hint = 0;
138 }
139 } 144 }
140 145
141 return nr; 146 return nr;