Skip to content

Commit c27d53f

Browse files
KAGA-KOKOaxboe
authored andcommitted
blk-mq: Reduce the number of if-statements in blk_mq_mark_tag_wait()
This patch does not change any functionality but makes the blk_mq_mark_tag_wait() code slightly easier to read. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Omar Sandoval <osandov@fb.com> Cc: Hannes Reinecke <hare@suse.de> Cc: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 33f782c commit c27d53f

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

block/blk-mq.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,58 +1104,59 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx **hctx,
11041104
struct request *rq)
11051105
{
11061106
struct blk_mq_hw_ctx *this_hctx = *hctx;
1107-
bool shared_tags = (this_hctx->flags & BLK_MQ_F_TAG_SHARED) != 0;
11081107
struct sbq_wait_state *ws;
11091108
wait_queue_entry_t *wait;
11101109
bool ret;
11111110

1112-
if (!shared_tags) {
1111+
if (!(this_hctx->flags & BLK_MQ_F_TAG_SHARED)) {
11131112
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &this_hctx->state))
11141113
set_bit(BLK_MQ_S_SCHED_RESTART, &this_hctx->state);
1115-
} else {
1116-
wait = &this_hctx->dispatch_wait;
1117-
if (!list_empty_careful(&wait->entry))
1118-
return false;
11191114

1120-
spin_lock(&this_hctx->lock);
1121-
if (!list_empty(&wait->entry)) {
1122-
spin_unlock(&this_hctx->lock);
1123-
return false;
1124-
}
1115+
/*
1116+
* It's possible that a tag was freed in the window between the
1117+
* allocation failure and adding the hardware queue to the wait
1118+
* queue.
1119+
*
1120+
* Don't clear RESTART here, someone else could have set it.
1121+
* At most this will cost an extra queue run.
1122+
*/
1123+
return blk_mq_get_driver_tag(rq, hctx, false);
1124+
}
1125+
1126+
wait = &this_hctx->dispatch_wait;
1127+
if (!list_empty_careful(&wait->entry))
1128+
return false;
11251129

1126-
ws = bt_wait_ptr(&this_hctx->tags->bitmap_tags, this_hctx);
1127-
add_wait_queue(&ws->wait, wait);
1130+
spin_lock(&this_hctx->lock);
1131+
if (!list_empty(&wait->entry)) {
1132+
spin_unlock(&this_hctx->lock);
1133+
return false;
11281134
}
11291135

1136+
ws = bt_wait_ptr(&this_hctx->tags->bitmap_tags, this_hctx);
1137+
add_wait_queue(&ws->wait, wait);
1138+
11301139
/*
11311140
* It's possible that a tag was freed in the window between the
11321141
* allocation failure and adding the hardware queue to the wait
11331142
* queue.
11341143
*/
11351144
ret = blk_mq_get_driver_tag(rq, hctx, false);
1136-
1137-
if (!shared_tags) {
1138-
/*
1139-
* Don't clear RESTART here, someone else could have set it.
1140-
* At most this will cost an extra queue run.
1141-
*/
1142-
return ret;
1143-
} else {
1144-
if (!ret) {
1145-
spin_unlock(&this_hctx->lock);
1146-
return false;
1147-
}
1148-
1149-
/*
1150-
* We got a tag, remove ourselves from the wait queue to ensure
1151-
* someone else gets the wakeup.
1152-
*/
1153-
spin_lock_irq(&ws->wait.lock);
1154-
list_del_init(&wait->entry);
1155-
spin_unlock_irq(&ws->wait.lock);
1145+
if (!ret) {
11561146
spin_unlock(&this_hctx->lock);
1157-
return true;
1147+
return false;
11581148
}
1149+
1150+
/*
1151+
* We got a tag, remove ourselves from the wait queue to ensure
1152+
* someone else gets the wakeup.
1153+
*/
1154+
spin_lock_irq(&ws->wait.lock);
1155+
list_del_init(&wait->entry);
1156+
spin_unlock_irq(&ws->wait.lock);
1157+
spin_unlock(&this_hctx->lock);
1158+
1159+
return true;
11591160
}
11601161

11611162
bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,

0 commit comments

Comments
 (0)