[Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context
Denis V. Lunev
den at openvz.org
Wed Nov 25 04:25:22 MSK 2026
From: Denis V. Lunev <den at openvz.org>
dm-qcow2 ends a request through dm_complete_request(), which calls
blk_mq_complete_request(). Request-based dm has one hardware queue by
default, so this raises BLOCK_SOFTIRQ. The completion handler usually
runs in task context, either in a target worker or when the backing
store completes image I/O from a task (brd, FUSE, unwritten extent
conversion). Raising the softirq from a task wakes ksoftirqd, and the
completions wait for it to be scheduled, which costs IOPS and tail
latency as the request rate grows.
Add dm_complete_request_direct(), which in task context runs
dm_softirq_done() in the caller via blk_mq_complete_request_direct(),
and use it in qrq_endio(). This deliberately skips the IPI to the
submitter's cache domain under the default rq_affinity=1 policy. Keep
blk_mq_complete_request() for rq_affinity=2 to honour the submitting CPU
preference, and for callers outside task context. Fault-injected
timeouts still suppress completion.
Only the target knows which locks it holds when the original request's
bio end_io runs on its stack. dm-qcow2 calls its handler with no lock
held. dm-multipath completes from end_clone_request() in whatever
context the lower driver ends the clone, which is rarely a task, so it
would gain little from switching helpers.
The request may now end before the target handler returns. That could
already happen when the raised softirq ran on an interrupt exit or in a
ksoftirqd that preempted the handler.
https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
drivers/md/dm-qcow2-map.c | 2 +-
drivers/md/dm-rq.c | 20 ++++++++++++++++++++
drivers/md/dm-rq.h | 1 +
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 17487f52c33e..d1dec85236b8 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4834,7 +4834,7 @@ static void qrq_endio(struct qcow2_target *tgt, struct qio *qio,
}
mempool_free(qrq, tgt->qrq_pool);
- dm_complete_request(rq, bi_status);
+ dm_complete_request_direct(rq, bi_status);
}
static void init_qrq(struct qcow2_rq *qrq, struct request *rq)
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 5a8cd59ec257..0d31fcf84aed 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -294,6 +294,26 @@ void dm_complete_request(struct request *rq, blk_status_t error)
}
EXPORT_SYMBOL(dm_complete_request);
+/*
+ * Raising BLOCK_SOFTIRQ from a task wakes ksoftirqd. Complete inline
+ * if affinity permits. The caller must not hold a lock that completion
+ * of the original request may take.
+ */
+void dm_complete_request_direct(struct request *rq, blk_status_t error)
+{
+ struct dm_rq_target_io *tio = tio_from_request(rq);
+
+ tio->error = error;
+ if (unlikely(blk_should_fake_timeout(rq->q)))
+ return;
+
+ if (in_task() && !test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
+ blk_mq_complete_request_direct(rq, dm_softirq_done);
+ else
+ blk_mq_complete_request(rq);
+}
+EXPORT_SYMBOL(dm_complete_request_direct);
+
/*
* Complete the not-mapped clone and the original request with the error status
* through softirq context.
diff --git a/drivers/md/dm-rq.h b/drivers/md/dm-rq.h
index 53abc3cf9aee..d4d2460ee107 100644
--- a/drivers/md/dm-rq.h
+++ b/drivers/md/dm-rq.h
@@ -46,6 +46,7 @@ ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md,
const char *buf, size_t count);
void dm_complete_request(struct request *rq, blk_status_t error);
+void dm_complete_request_direct(struct request *rq, blk_status_t error);
void dm_requeue_original_rq(struct request *rq);
#endif
--
2.55.0
More information about the Devel
mailing list