Skip to content

Commit 97889f9

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: remove synchronize_rcu() from blk_mq_del_queue_tag_set()
We have to remove synchronize_rcu() from blk_queue_cleanup(), otherwise long delay can be caused during lun probe. For removing it, we have to avoid to iterate the set->tag_list in IO path, eg, blk_mq_sched_restart(). This patch reverts 5b79413946d (Revert "blk-mq: don't handle TAG_SHARED in restart"). Given we have fixed enough IO hang issue, and there isn't any reason to restart all queues in one tags any more, see the following reasons: 1) blk-mq core can deal with shared-tags case well via blk_mq_get_driver_tag(), which can wake up queues waiting for driver tag. 2) SCSI is a bit special because it may return BLK_STS_RESOURCE if queue, target or host is ready, but SCSI built-in restart can cover all these well, see scsi_end_request(), queue will be rerun after any request initiated from this host/target is completed. In my test on scsi_debug(8 luns), this patch may improve IOPS by 20% ~ 30% when running I/O on these 8 luns concurrently. Fixes: 705cda9 ("blk-mq: Make it safe to use RCU to iterate over blk_mq_tag_set.tag_list") Cc: Omar Sandoval <osandov@fb.com> Cc: Bart Van Assche <bart.vanassche@wdc.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: linux-scsi@vger.kernel.org Reported-by: Andrew Jones <drjones@redhat.com> Tested-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5815839 commit 97889f9

3 files changed

Lines changed: 7 additions & 90 deletions

File tree

‎block/blk-mq-sched.c‎

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,16 @@ static void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
5959
if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
6060
return;
6161

62-
if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
63-
struct request_queue *q = hctx->queue;
64-
65-
if (!test_and_set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
66-
atomic_inc(&q->shared_hctx_restart);
67-
} else
68-
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
62+
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
6963
}
7064

71-
static bool blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
65+
void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
7266
{
7367
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
74-
return false;
75-
76-
if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
77-
struct request_queue *q = hctx->queue;
78-
79-
if (test_and_clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
80-
atomic_dec(&q->shared_hctx_restart);
81-
} else
82-
clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
68+
return;
69+
clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
8370

84-
return blk_mq_run_hw_queue(hctx, true);
71+
blk_mq_run_hw_queue(hctx, true);
8572
}
8673

8774
/*
@@ -380,68 +367,6 @@ static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
380367
return false;
381368
}
382369

383-
/**
384-
* list_for_each_entry_rcu_rr - iterate in a round-robin fashion over rcu list
385-
* @pos: loop cursor.
386-
* @skip: the list element that will not be examined. Iteration starts at
387-
* @skip->next.
388-
* @head: head of the list to examine. This list must have at least one
389-
* element, namely @skip.
390-
* @member: name of the list_head structure within typeof(*pos).
391-
*/
392-
#define list_for_each_entry_rcu_rr(pos, skip, head, member) \
393-
for ((pos) = (skip); \
394-
(pos = (pos)->member.next != (head) ? list_entry_rcu( \
395-
(pos)->member.next, typeof(*pos), member) : \
396-
list_entry_rcu((pos)->member.next->next, typeof(*pos), member)), \
397-
(pos) != (skip); )
398-
399-
/*
400-
* Called after a driver tag has been freed to check whether a hctx needs to
401-
* be restarted. Restarts @hctx if its tag set is not shared. Restarts hardware
402-
* queues in a round-robin fashion if the tag set of @hctx is shared with other
403-
* hardware queues.
404-
*/
405-
void blk_mq_sched_restart(struct blk_mq_hw_ctx *const hctx)
406-
{
407-
struct blk_mq_tags *const tags = hctx->tags;
408-
struct blk_mq_tag_set *const set = hctx->queue->tag_set;
409-
struct request_queue *const queue = hctx->queue, *q;
410-
struct blk_mq_hw_ctx *hctx2;
411-
unsigned int i, j;
412-
413-
if (set->flags & BLK_MQ_F_TAG_SHARED) {
414-
/*
415-
* If this is 0, then we know that no hardware queues
416-
* have RESTART marked. We're done.
417-
*/
418-
if (!atomic_read(&queue->shared_hctx_restart))
419-
return;
420-
421-
rcu_read_lock();
422-
list_for_each_entry_rcu_rr(q, queue, &set->tag_list,
423-
tag_set_list) {
424-
queue_for_each_hw_ctx(q, hctx2, i)
425-
if (hctx2->tags == tags &&
426-
blk_mq_sched_restart_hctx(hctx2))
427-
goto done;
428-
}
429-
j = hctx->queue_num + 1;
430-
for (i = 0; i < queue->nr_hw_queues; i++, j++) {
431-
if (j == queue->nr_hw_queues)
432-
j = 0;
433-
hctx2 = queue->queue_hw_ctx[j];
434-
if (hctx2->tags == tags &&
435-
blk_mq_sched_restart_hctx(hctx2))
436-
break;
437-
}
438-
done:
439-
rcu_read_unlock();
440-
} else {
441-
blk_mq_sched_restart_hctx(hctx);
442-
}
443-
}
444-
445370
void blk_mq_sched_insert_request(struct request *rq, bool at_head,
446371
bool run_queue, bool async)
447372
{

‎block/blk-mq.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,15 +2335,10 @@ static void queue_set_hctx_shared(struct request_queue *q, bool shared)
23352335
int i;
23362336

23372337
queue_for_each_hw_ctx(q, hctx, i) {
2338-
if (shared) {
2339-
if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
2340-
atomic_inc(&q->shared_hctx_restart);
2338+
if (shared)
23412339
hctx->flags |= BLK_MQ_F_TAG_SHARED;
2342-
} else {
2343-
if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
2344-
atomic_dec(&q->shared_hctx_restart);
2340+
else
23452341
hctx->flags &= ~BLK_MQ_F_TAG_SHARED;
2346-
}
23472342
}
23482343
}
23492344

@@ -2374,7 +2369,6 @@ static void blk_mq_del_queue_tag_set(struct request_queue *q)
23742369
blk_mq_update_tag_set_depth(set, false);
23752370
}
23762371
mutex_unlock(&set->tag_list_lock);
2377-
synchronize_rcu();
23782372
INIT_LIST_HEAD(&q->tag_set_list);
23792373
}
23802374

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ struct request_queue {
442442
int nr_rqs[2]; /* # allocated [a]sync rqs */
443443
int nr_rqs_elvpriv; /* # allocated rqs w/ elvpriv */
444444

445-
atomic_t shared_hctx_restart;
446-
447445
struct blk_queue_stats *stats;
448446
struct rq_wb *rq_wb;
449447

0 commit comments

Comments
 (0)