Skip to content

Commit c797b40

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: don't grab rq's refcount in blk_mq_check_expired()
Inside blk_mq_queue_tag_busy_iter() we already grabbed request's refcount before calling ->fn(), so needn't to grab it one more time in blk_mq_check_expired(). Meantime remove extra request expire check in blk_mq_check_expired(). Cc: Keith Busch <[email protected]> Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent cddce01 commit c797b40

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

block/blk-mq.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -923,34 +923,14 @@ static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
923923
unsigned long *next = priv;
924924

925925
/*
926-
* Just do a quick check if it is expired before locking the request in
927-
* so we're not unnecessarilly synchronizing across CPUs.
928-
*/
929-
if (!blk_mq_req_expired(rq, next))
930-
return true;
931-
932-
/*
933-
* We have reason to believe the request may be expired. Take a
934-
* reference on the request to lock this request lifetime into its
935-
* currently allocated context to prevent it from being reallocated in
936-
* the event the completion by-passes this timeout handler.
937-
*
938-
* If the reference was already released, then the driver beat the
939-
* timeout handler to posting a natural completion.
940-
*/
941-
if (!refcount_inc_not_zero(&rq->ref))
942-
return true;
943-
944-
/*
945-
* The request is now locked and cannot be reallocated underneath the
946-
* timeout handler's processing. Re-verify this exact request is truly
947-
* expired; if it is not expired, then the request was completed and
948-
* reallocated as a new request.
926+
* blk_mq_queue_tag_busy_iter() has locked the request, so it cannot
927+
* be reallocated underneath the timeout handler's processing, then
928+
* the expire check is reliable. If the request is not expired, then
929+
* it was completed and reallocated as a new request after returning
930+
* from blk_mq_check_expired().
949931
*/
950932
if (blk_mq_req_expired(rq, next))
951933
blk_mq_rq_timed_out(rq, reserved);
952-
953-
blk_mq_put_rq_ref(rq);
954934
return true;
955935
}
956936

0 commit comments

Comments
 (0)