diff mbox series

[2/4] sbitmap: mask out top bits that can't be used

Message ID 20191230181442.4460-3-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series blk-mq: per-ctx tag caching | expand

Commit Message

Jens Axboe Dec. 30, 2019, 6:14 p.m. UTC
If the tag depth isn't a multiple of the bits_per_word we selected,
we'll have dead bits at the top. Ensure that they are set. This
doesn't matter for the bit finding as we limit it to the depth of
the individual map, but it'll matter for when we try and grab
batches of tags off one map.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 lib/sbitmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index c13a9623e9b5..a6c6c104b063 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -46,7 +46,13 @@  int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
 		return -ENOMEM;
 
 	for (i = 0; i < sb->map_nr; i++) {
-		sb->map[i].depth = min(depth, bits_per_word);
+		if (depth >= bits_per_word) {
+			sb->map[i].depth = bits_per_word;
+		} else {
+			sb->map[i].depth = depth;
+			/* mask off top unused bits, can never get allocated */
+			sb->map[i].word = ~((1UL << depth) - 1);
+		}
 		depth -= sb->map[i].depth;
 	}
 	return 0;