Skip to content

Commit

Permalink
blk-mq: don't wait in blk_mq_queue_enter() if __GFP_WAIT isn't set
Browse files Browse the repository at this point in the history
Return -EBUSY if we're unable to enter a queue immediately when
allocating a blk-mq request without __GFP_WAIT.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Keith Busch authored and axboe committed Mar 13, 2015
1 parent b94ec29 commit bfd343a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx,
clear_bit(CTX_TO_BIT(hctx, ctx), &bm->word);
}

static int blk_mq_queue_enter(struct request_queue *q)
static int blk_mq_queue_enter(struct request_queue *q, gfp_t gfp)
{
while (true) {
int ret;

if (percpu_ref_tryget_live(&q->mq_usage_counter))
return 0;

if (!(gfp & __GFP_WAIT))
return -EBUSY;

ret = wait_event_interruptible(q->mq_freeze_wq,
!q->mq_freeze_depth || blk_queue_dying(q));
if (blk_queue_dying(q))
Expand Down Expand Up @@ -256,7 +259,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
struct blk_mq_alloc_data alloc_data;
int ret;

ret = blk_mq_queue_enter(q);
ret = blk_mq_queue_enter(q, gfp);
if (ret)
return ERR_PTR(ret);

Expand Down Expand Up @@ -1186,7 +1189,7 @@ static struct request *blk_mq_map_request(struct request_queue *q,
int rw = bio_data_dir(bio);
struct blk_mq_alloc_data alloc_data;

if (unlikely(blk_mq_queue_enter(q))) {
if (unlikely(blk_mq_queue_enter(q, GFP_KERNEL))) {
bio_endio(bio, -EIO);
return NULL;
}
Expand Down

0 comments on commit bfd343a

Please sign in to comment.