Skip to content

Commit 0809e3a

Browse files
JeffMoyeraxboe
authored andcommitted
block: fix plug list flushing for nomerge queues
Request queues with merging disabled will not flush the plug list after BLK_MAX_REQUEST_COUNT requests have been queued, since the code relies on blk_attempt_plug_merge to compute the request_count. Fix this by computing the number of queued requests even for nomerge queues. Signed-off-by: Jeff Moyer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3380f45 commit 0809e3a

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

block/blk-core.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,30 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
15941594
return ret;
15951595
}
15961596

1597+
unsigned int blk_plug_queued_count(struct request_queue *q)
1598+
{
1599+
struct blk_plug *plug;
1600+
struct request *rq;
1601+
struct list_head *plug_list;
1602+
unsigned int ret = 0;
1603+
1604+
plug = current->plug;
1605+
if (!plug)
1606+
goto out;
1607+
1608+
if (q->mq_ops)
1609+
plug_list = &plug->mq_list;
1610+
else
1611+
plug_list = &plug->list;
1612+
1613+
list_for_each_entry(rq, plug_list, queuelist) {
1614+
if (rq->q == q)
1615+
ret++;
1616+
}
1617+
out:
1618+
return ret;
1619+
}
1620+
15971621
void init_request_from_bio(struct request *req, struct bio *bio)
15981622
{
15991623
req->cmd_type = REQ_TYPE_FS;
@@ -1641,9 +1665,11 @@ static void blk_queue_bio(struct request_queue *q, struct bio *bio)
16411665
* Check if we can merge with the plugged list before grabbing
16421666
* any locks.
16431667
*/
1644-
if (!blk_queue_nomerges(q) &&
1645-
blk_attempt_plug_merge(q, bio, &request_count, NULL))
1646-
return;
1668+
if (!blk_queue_nomerges(q)) {
1669+
if (blk_attempt_plug_merge(q, bio, &request_count, NULL))
1670+
return;
1671+
} else
1672+
request_count = blk_plug_queued_count(q);
16471673

16481674
spin_lock_irq(q->queue_lock);
16491675

block/blk-mq.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,12 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
12681268

12691269
blk_queue_split(q, &bio, q->bio_split);
12701270

1271-
if (!is_flush_fua && !blk_queue_nomerges(q) &&
1272-
blk_attempt_plug_merge(q, bio, &request_count, &same_queue_rq))
1273-
return;
1271+
if (!is_flush_fua && !blk_queue_nomerges(q)) {
1272+
if (blk_attempt_plug_merge(q, bio, &request_count,
1273+
&same_queue_rq))
1274+
return;
1275+
} else
1276+
request_count = blk_plug_queued_count(q);
12741277

12751278
rq = blk_mq_map_request(q, bio, &data);
12761279
if (unlikely(!rq))

block/blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,
8686
bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
8787
unsigned int *request_count,
8888
struct request **same_queue_rq);
89+
unsigned int blk_plug_queued_count(struct request_queue *q);
8990

9091
void blk_account_io_start(struct request *req, bool new_io);
9192
void blk_account_io_completion(struct request *req, unsigned int bytes);

0 commit comments

Comments
 (0)