Skip to content

Commit 2f9c296

Browse files
committed
block: disable iopoll for split bio
to #31739384 commit cc29e1bf0d63f728a5bd60ef22638bbf77369552 upstream. 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 <ming.lei@redhat.com> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
1 parent a6b7a72 commit 2f9c296

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

block/blk-merge.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
167167
*segs = nsegs;
168168

169169
if (do_split) {
170+
/*
171+
* Bio splitting may cause subtle trouble such as hang when doing sync
172+
* iopoll in direct IO routine. Given performance gain of iopoll for
173+
* big IO can be trival, disable iopoll when split needed.
174+
*/
175+
bio->bi_opf &= ~REQ_HIPRI;
176+
170177
new = bio_split(bio, sectors, GFP_NOIO, bs);
171178
if (new)
172179
bio = new;

block/blk-mq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
19751975
struct blk_plug *plug;
19761976
struct request *same_queue_rq = NULL;
19771977
blk_qc_t cookie;
1978+
bool hipri;
19781979

19791980
blk_queue_bounce(q, &bio);
19801981

@@ -1992,6 +1993,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
19921993

19931994
rq_qos_throttle(q, bio, NULL);
19941995

1996+
hipri = bio->bi_opf & REQ_HIPRI;
1997+
19951998
data.cmd_flags = bio->bi_opf;
19961999
rq = blk_mq_get_request(q, bio, &data);
19972000
if (unlikely(!rq)) {
@@ -2074,6 +2077,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
20742077
blk_mq_sched_insert_request(rq, false, true, true);
20752078
}
20762079

2080+
if (!hipri)
2081+
return BLK_QC_T_NONE;
20772082
return cookie;
20782083
}
20792084

0 commit comments

Comments
 (0)