Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sbitmap: rewrite sbitmap_find_bit_in_index to reduce repeat code

Rewrite sbitmap_find_bit_in_index as following:
1. Rename sbitmap_find_bit_in_index to sbitmap_find_bit_in_word
2. Accept "struct sbitmap_word *" directly instead of accepting
"struct sbitmap *" and "int index" to get "struct sbitmap_word *".
3. Accept depth/shallow_depth and wrap for __sbitmap_get_word from caller
to support need of both __sbitmap_get_shallow and __sbitmap_get.

With helper function sbitmap_find_bit_in_word, we can remove repeat
code in __sbitmap_get_shallow to find bit considring deferred clear.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Link: https://lore.kernel.org/r/20230116205059.3821738-4-shikemeng@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Kemeng Shi and committed by
Jens Axboe
08470a98 903e86f3

+15 -15
+15 -15
lib/sbitmap.c
··· 167 167 return nr; 168 168 } 169 169 170 - static int sbitmap_find_bit_in_index(struct sbitmap *sb, int index, 171 - unsigned int alloc_hint) 170 + static int sbitmap_find_bit_in_word(struct sbitmap_word *map, 171 + unsigned int depth, 172 + unsigned int alloc_hint, 173 + bool wrap) 172 174 { 173 - struct sbitmap_word *map = &sb->map[index]; 174 175 int nr; 175 176 176 177 do { 177 - nr = __sbitmap_get_word(&map->word, __map_depth(sb, index), 178 - alloc_hint, !sb->round_robin); 178 + nr = __sbitmap_get_word(&map->word, depth, 179 + alloc_hint, wrap); 179 180 if (nr != -1) 180 181 break; 181 182 if (!sbitmap_deferred_clear(map)) ··· 204 203 alloc_hint = 0; 205 204 206 205 for (i = 0; i < sb->map_nr; i++) { 207 - nr = sbitmap_find_bit_in_index(sb, index, alloc_hint); 206 + nr = sbitmap_find_bit_in_word(&sb->map[index], 207 + __map_depth(sb, index), 208 + alloc_hint, !sb->round_robin); 208 209 if (nr != -1) { 209 210 nr += index << sb->shift; 210 211 break; ··· 249 246 alloc_hint = SB_NR_TO_BIT(sb, alloc_hint); 250 247 251 248 for (i = 0; i < sb->map_nr; i++) { 252 - again: 253 - nr = __sbitmap_get_word(&sb->map[index].word, 254 - min_t(unsigned int, 255 - __map_depth(sb, index), 256 - shallow_depth), 257 - alloc_hint, true); 249 + nr = sbitmap_find_bit_in_word(&sb->map[index], 250 + min_t(unsigned int, 251 + __map_depth(sb, index), 252 + shallow_depth), 253 + alloc_hint, true); 254 + 258 255 if (nr != -1) { 259 256 nr += index << sb->shift; 260 257 break; 261 258 } 262 - 263 - if (sbitmap_deferred_clear(&sb->map[index])) 264 - goto again; 265 259 266 260 /* Jump to next index. */ 267 261 alloc_hint = 0;