Skip to content

Commit cc29e1b

Browse files
lostjeffleaxboe
authored andcommitted
block: disable iopoll for split bio
iopoll is initially for small size, latency sensitive IO. It doesn't work well for big IO, especially when it needs to be split to multiple bios. In this case, the returned cookie of __submit_bio_noacct_mq() is indeed the cookie of the last split bio. The completion of *this* last split bio done by iopoll doesn't mean the whole original bio has completed. Callers of iopoll still need to wait for completion of other split bios. Besides bio splitting may cause more trouble for iopoll which isn't supposed to be used in case of big IO. iopoll for split bio may cause potential race if CPU migration happens during bio submission. Since the returned cookie is that of the last split bio, polling on the corresponding hardware queue doesn't help complete other split bios, if these split bios are enqueued into different hardware queues. Since interrupts are disabled for polling queues, the completion of these other split bios depends on timeout mechanism, thus causing a potential hang. iopoll for split bio may also cause hang for sync polling. Currently both the blkdev and iomap-based fs (ext4/xfs, etc) support sync polling in direct IO routine. These routines will submit bio without REQ_NOWAIT flag set, and then start sync polling in current process context. The process may hang in blk_mq_get_tag() if the submitted bio has to be split into multiple bios and can rapidly exhaust the queue depth. The process are waiting for the completion of the previously allocated requests, which should be reaped by the following polling, and thus causing a deadlock. To avoid these subtle trouble described above, just disable iopoll for split bio and return BLK_QC_T_NONE in this case. The side effect is that non-HIPRI IO also returns BLK_QC_T_NONE now. It should be acceptable since the returned cookie is never used for non-HIPRI IO. Suggested-by: Ming Lei <[email protected]> Signed-off-by: Jeffle Xu <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2afdeb2 commit cc29e1b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

block/blk-merge.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
279279
return NULL;
280280
split:
281281
*segs = nsegs;
282+
283+
/*
284+
* Bio splitting may cause subtle trouble such as hang when doing sync
285+
* iopoll in direct IO routine. Given performance gain of iopoll for
286+
* big IO can be trival, disable iopoll when split needed.
287+
*/
288+
bio->bi_opf &= ~REQ_HIPRI;
289+
282290
return bio_split(bio, sectors, GFP_NOIO, bs);
283291
}
284292

block/blk-mq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,7 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio)
21592159
unsigned int nr_segs;
21602160
blk_qc_t cookie;
21612161
blk_status_t ret;
2162+
bool hipri;
21622163

21632164
blk_queue_bounce(q, &bio);
21642165
__blk_queue_split(&bio, &nr_segs);
@@ -2175,6 +2176,8 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio)
21752176

21762177
rq_qos_throttle(q, bio);
21772178

2179+
hipri = bio->bi_opf & REQ_HIPRI;
2180+
21782181
data.cmd_flags = bio->bi_opf;
21792182
rq = __blk_mq_alloc_request(&data);
21802183
if (unlikely(!rq)) {
@@ -2267,6 +2270,8 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio)
22672270
blk_mq_sched_insert_request(rq, false, true, true);
22682271
}
22692272

2273+
if (!hipri)
2274+
return BLK_QC_T_NONE;
22702275
return cookie;
22712276
queue_exit:
22722277
blk_queue_exit(q);

0 commit comments

Comments
 (0)