Skip to content

Commit f1b49fd

Browse files
John Garryaxboe
authored andcommitted
blk-mq: Record active_queues_shared_sbitmap per tag_set for when using shared sbitmap
For when using a shared sbitmap, no longer should the number of active request queues per hctx be relied on for when judging how to share the tag bitmap. Instead maintain the number of active request queues per tag_set, and make the judgement based on that. Originally-from: Kashyap Desai <kashyap.desai@broadcom.com> Signed-off-by: John Garry <john.garry@huawei.com> Tested-by: Don Brace<don.brace@microsemi.com> #SCSI resv cmds patches used Tested-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bccf5e2 commit f1b49fd

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

block/blk-mq-tag.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@
2323
*/
2424
bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
2525
{
26-
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state) &&
27-
!test_and_set_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
28-
atomic_inc(&hctx->tags->active_queues);
26+
if (blk_mq_is_sbitmap_shared(hctx->flags)) {
27+
struct request_queue *q = hctx->queue;
28+
struct blk_mq_tag_set *set = q->tag_set;
29+
30+
if (!test_bit(QUEUE_FLAG_HCTX_ACTIVE, &q->queue_flags) &&
31+
!test_and_set_bit(QUEUE_FLAG_HCTX_ACTIVE, &q->queue_flags))
32+
atomic_inc(&set->active_queues_shared_sbitmap);
33+
} else {
34+
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state) &&
35+
!test_and_set_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
36+
atomic_inc(&hctx->tags->active_queues);
37+
}
2938

3039
return true;
3140
}
@@ -47,11 +56,19 @@ void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool include_reserve)
4756
void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
4857
{
4958
struct blk_mq_tags *tags = hctx->tags;
50-
51-
if (!test_and_clear_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
52-
return;
53-
54-
atomic_dec(&tags->active_queues);
59+
struct request_queue *q = hctx->queue;
60+
struct blk_mq_tag_set *set = q->tag_set;
61+
62+
if (blk_mq_is_sbitmap_shared(hctx->flags)) {
63+
if (!test_and_clear_bit(QUEUE_FLAG_HCTX_ACTIVE,
64+
&q->queue_flags))
65+
return;
66+
atomic_dec(&set->active_queues_shared_sbitmap);
67+
} else {
68+
if (!test_and_clear_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
69+
return;
70+
atomic_dec(&tags->active_queues);
71+
}
5572

5673
blk_mq_tag_wakeup_all(tags, false);
5774
}

block/blk-mq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,8 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
34423442
goto out_free_mq_map;
34433443

34443444
if (blk_mq_is_sbitmap_shared(set->flags)) {
3445+
atomic_set(&set->active_queues_shared_sbitmap, 0);
3446+
34453447
if (blk_mq_init_shared_sbitmap(set, set->flags)) {
34463448
ret = -ENOMEM;
34473449
goto out_free_mq_rq_maps;

block/blk-mq.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,26 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
292292

293293
if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED))
294294
return true;
295-
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
296-
return true;
297295

298296
/*
299297
* Don't try dividing an ant
300298
*/
301299
if (bt->sb.depth == 1)
302300
return true;
303301

304-
users = atomic_read(&hctx->tags->active_queues);
302+
if (blk_mq_is_sbitmap_shared(hctx->flags)) {
303+
struct request_queue *q = hctx->queue;
304+
struct blk_mq_tag_set *set = q->tag_set;
305+
306+
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &q->queue_flags))
307+
return true;
308+
users = atomic_read(&set->active_queues_shared_sbitmap);
309+
} else {
310+
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
311+
return true;
312+
users = atomic_read(&hctx->tags->active_queues);
313+
}
314+
305315
if (!users)
306316
return true;
307317

include/linux/blk-mq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ struct blk_mq_tag_set {
252252
unsigned int timeout;
253253
unsigned int flags;
254254
void *driver_data;
255+
atomic_t active_queues_shared_sbitmap;
255256

256257
struct sbitmap_queue __bitmap_tags;
257258
struct sbitmap_queue __breserved_tags;

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ struct request_queue {
618618
#define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */
619619
#define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */
620620
#define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */
621+
#define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */
621622

622623
#define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
623624
(1 << QUEUE_FLAG_SAME_COMP))

0 commit comments

Comments
 (0)