Skip to content

Commit 524346e

Browse files
Ming Leiaxboe
authored andcommitted
ublk: build batch from IOs in same io_ring_ctx and io task
ublk_queue_cmd_list() dispatches the whole batch list by scheduling task work via the tail request's io_uring_cmd, this way is fine even though more than one io_ring_ctx are involved for this batch since it is just one running context. However, the task work handler ublk_cmd_list_tw_cb() takes `issue_flags` of tail uring_cmd's io_ring_ctx for completing all commands. This way is wrong if any uring_cmd is issued from different io_ring_ctx. Fixes it by always building batch IOs from same io_ring_ctx and io task because ublk_dispatch_req() does validate task context, and IO needs to be aborted in case of running from fallback task work context. For typical per-queue or per-io daemon implementation, this way shouldn't make difference from performance viewpoint, because single io_ring_ctx is taken in each daemon for normal use case. Fixes: d796cea ("ublk: implement ->queue_rqs()") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 8c84728 commit 524346e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/block/ublk_drv.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,14 @@ static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
14161416
return BLK_STS_OK;
14171417
}
14181418

1419+
static inline bool ublk_belong_to_same_batch(const struct ublk_io *io,
1420+
const struct ublk_io *io2)
1421+
{
1422+
return (io_uring_cmd_ctx_handle(io->cmd) ==
1423+
io_uring_cmd_ctx_handle(io2->cmd)) &&
1424+
(io->task == io2->task);
1425+
}
1426+
14191427
static void ublk_queue_rqs(struct rq_list *rqlist)
14201428
{
14211429
struct rq_list requeue_list = { };
@@ -1427,7 +1435,8 @@ static void ublk_queue_rqs(struct rq_list *rqlist)
14271435
struct ublk_queue *this_q = req->mq_hctx->driver_data;
14281436
struct ublk_io *this_io = &this_q->ios[req->tag];
14291437

1430-
if (io && io->task != this_io->task && !rq_list_empty(&submit_list))
1438+
if (io && !ublk_belong_to_same_batch(io, this_io) &&
1439+
!rq_list_empty(&submit_list))
14311440
ublk_queue_cmd_list(io, &submit_list);
14321441
io = this_io;
14331442

0 commit comments

Comments
 (0)