diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 60c9d4a93fe4..2e38cd118c1d 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -143,7 +143,6 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx, static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag) { int tag, org_last_tag, end; - bool wrap = last_tag != 0; org_last_tag = last_tag; end = bm->depth; @@ -155,15 +154,16 @@ restart: * We started with an offset, start from 0 to * exhaust the map. */ - if (wrap) { - wrap = false; + if (org_last_tag) { end = org_last_tag; - last_tag = 0; + last_tag = org_last_tag = 0; goto restart; } return -1; } last_tag = tag + 1; + if (last_tag >= bm->depth - 1) + last_tag = 0; } while (test_and_set_bit(tag, &bm->word)); return tag; @@ -199,9 +199,13 @@ static int __bt_get(struct blk_mq_hw_ctx *hctx, struct blk_mq_bitmap_tags *bt, goto done; } - last_tag = 0; - if (++index >= bt->map_nr) + index++; + last_tag = (index << bt->bits_per_word); + + if (index >= bt->map_nr) { index = 0; + last_tag = 0; + } } *tag_cache = 0;