OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: ptikhomirov@virtuozzo.com, alexander.ivanov@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 4/7] drivers/md/dm-qcow2: add per-qio work infrastructure
Date: Thu, 29 Oct 2026 17:03:43 +0300	[thread overview]
Message-ID: <20261029140346.465768-5-andrey.zhadchenko@virtuozzo.com> (raw)
In-Reply-To: <20261029140346.465768-1-andrey.zhadchenko@virtuozzo.com>

dm-qcow2 was created to run non-concurrently, so qio never had
per work struct field. Let's add one and use it to queue first
dm-qcow2 pipeline step: qio preparation. It requires no metadata,
so everything is simple here.
We would later move more pipeline steps into qio.

https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c | 60 ++++++++++++++++++++++++++++-----------
 drivers/md/dm-qcow2.h     |  6 ++++
 2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index c5d68b6b21f12..7afaba0afec14 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -362,6 +362,8 @@ struct qio *qcow2_alloc_qio(mempool_t *pool, bool zero)
 }
 ALLOW_ERROR_INJECTION(qcow2_alloc_qio, NULL);
 
+static void do_qio_work(struct work_struct *ws);
+
 void qcow2_init_qio(struct qio *qio, unsigned int bi_op, struct qcow2 *qcow2)
 {
 	qio->qcow2 = qcow2;
@@ -372,7 +374,9 @@ void qcow2_init_qio(struct qio *qio, unsigned int bi_op, struct qcow2 *qcow2)
 	qio->bi_io_vec = NULL;
 	qio->flags = 0;
 	qio->ref_index = REF_INDEX_INVALID;
+	qio->state = QIO_STATE_START;
 	atomic_set(&qio->remaining, 1);
+	INIT_WORK(&qio->worker, do_qio_work);
 
 	/*
 	 * Initially set into BLK_STS_OK, while aio complete,
@@ -3770,10 +3774,10 @@ static void qio_init_iter_from_rq(struct qio *qio, struct request *rq)
 	qio->bi_iter.bi_bvec_done = 0;
 }
 
-static void prepare_one_embedded_qio(struct qcow2 *qcow2, struct qio *qio,
-				     struct list_head *deferred_qios)
+static void prepare_one_embedded_qio(struct qio *qio, struct list_head *deferred_qios)
 {
 	struct qcow2_rq *qrq = qio->endio_cb_data;
+	struct qcow2 *qcow2 = qio->qcow2;
 	struct request *rq = qrq->rq;
 	struct bio_vec *bvec = NULL;
 	LIST_HEAD(list);
@@ -3818,15 +3822,6 @@ static void prepare_one_embedded_qio(struct qcow2 *qcow2, struct qio *qio,
 	qio_endio(qio);
 }
 
-static void process_embedded_qios(struct qcow2 *qcow2, struct list_head *qios,
-				  struct list_head *deferred_qios)
-{
-	struct qio *qio;
-
-	while ((qio = qio_list_pop(qios)))
-		prepare_one_embedded_qio(qcow2, qio, deferred_qios);
-}
-
 static void process_deferred_qios(struct qcow2 *qcow2, struct list_head *qios)
 {
 	struct qio *qio;
@@ -4343,7 +4338,6 @@ static void process_seek_qios(struct qcow2 *qcow, struct list_head *qios)
 void do_qcow2_work(struct work_struct *ws)
 {
 	struct qcow2 *qcow2 = container_of(ws, struct qcow2, worker);
-	LIST_HEAD(embedded_qios);
 	LIST_HEAD(deferred_qios);
 	LIST_HEAD(zread_qios);
 	LIST_HEAD(bwrite_qios);
@@ -4356,7 +4350,6 @@ void do_qcow2_work(struct work_struct *ws)
 
 	current->flags |= PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO;
 	spin_lock_irq(&qcow2->deferred_lock);
-	list_splice_init(&qcow2->qios[QLIST_EMBEDDED], &embedded_qios);
 	list_splice_init(&qcow2->qios[QLIST_DEFERRED], &deferred_qios);
 	list_splice_init(&qcow2->qios[QLIST_ZREAD], &zread_qios);
 	list_splice_init(&qcow2->qios[QLIST_BMERGE_WRITE], &bwrite_qios);
@@ -4367,7 +4360,6 @@ void do_qcow2_work(struct work_struct *ws)
 	list_splice_init(&qcow2->qios[QLIST_SEEK], &seek_qios);
 	spin_unlock_irq(&qcow2->deferred_lock);
 
-	process_embedded_qios(qcow2, &embedded_qios, &deferred_qios);
 	process_deferred_qios(qcow2, &deferred_qios);
 	process_compressed_read(&zread_qios, &cow_data_qios);
 	process_backward_merge_write(qcow2, &bwrite_qios);
@@ -4491,7 +4483,7 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio)
 
 	if (blk_rq_bytes(rq)) {
 		queue_list_id = QLIST_EMBEDDED;
-		worker = &qcow2->worker;
+		worker = &qio->worker;
 	} else {
 		WARN_ON_ONCE(qio->bi_op != REQ_OP_FLUSH);
 		queue_list_id = QLIST_FLUSH;
@@ -4507,7 +4499,10 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio)
 		qio->qcow2 = qcow2;
 		qio->queue_list_id = queue_list_id;
 		qio->ref_index = ref_index;
-		list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]);
+		if (queue_list_id == QLIST_EMBEDDED)
+			qio->state = QIO_STATE_START;
+		else
+			list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]);
 	}
 	spin_unlock_irqrestore(&qcow2->deferred_lock, flags);
 
@@ -4599,6 +4594,39 @@ static void handle_cleanup_mask(struct qio *qio)
 	}
 }
 
+static void do_qio_work(struct work_struct *ws)
+{
+	struct qio *qio = container_of(ws, struct qio, worker);
+	struct qcow2 *qcow2 = qio->qcow2;
+	struct qcow2_target *tgt = qcow2->tgt;
+	unsigned int pflags = current->flags;
+
+	current->flags |= PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO;
+
+	switch (qio->state) {
+	case QIO_STATE_START: {
+		LIST_HEAD(deferred_qios);
+
+		prepare_one_embedded_qio(qio, &deferred_qios);
+		if (list_empty(&deferred_qios))
+			break;
+
+		spin_lock_irq(&qcow2->deferred_lock);
+		list_splice_tail(&deferred_qios, &qcow2->qios[QLIST_DEFERRED]);
+		spin_unlock_irq(&qcow2->deferred_lock);
+		queue_work(tgt->wq, &qcow2->worker);
+		break;
+	}
+
+	default:
+		qio->bi_status = BLK_STS_IOERR;
+		qio_endio(qio);
+		break;
+	}
+
+	current_restore_flags(pflags, PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO);
+}
+
 struct qio_data_llseek_hole {
 	struct completion compl;
 	struct qio *higher;
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index d9b8c38e093f5..003e01a4d3ec9 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -236,6 +236,10 @@ enum {
 	QLIST_INVALID = QLIST_COUNT,
 };
 
+enum {
+	QIO_STATE_START = 0,
+};
+
 struct qcow2 {
 	struct qcow2_target *tgt;
 	struct file *file;
@@ -369,6 +373,8 @@ struct qio {
 	struct qcow2 *qcow2;
 	qcow2_endio_t endio_cb;
 	void *endio_cb_data;
+	struct work_struct worker;
+	int state;
 };
 
 #define CLU_OFF(qcow2, pos) (pos & (qcow2->clu_size - 1))
-- 
2.43.5

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-29 14:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 14:03 [Devel] [PATCH 0/7] drivers/md/dm-qcow2: per-qio fast path Andrey Zhadchenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 1/7] drivers/md/dm-qcow2: repeat md page lookup if it was inserted in parallel Andrey Zhadchenko
2026-10-29 14:13   ` no-reply
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 2/7] drivers/md/dm-qcow2: check MD_DIRTY and md->wbd under lock in perform_rw_mapped() Andrey Zhadchenko
2026-10-29 14:13   ` no-reply
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 3/7] drivers/md/dm-qcow2: prepare process_one_qio() for fastpath Andrey Zhadchenko
2026-10-29 14:16   ` no-reply
2026-11-02 17:28   ` Alexander Ivanov
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` Andrey Zhadchenko [this message]
2026-10-29 14:18   ` [Devel] [PATCH hci-8.1 4/7] drivers/md/dm-qcow2: add per-qio work infrastructure no-reply
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 5/7] drivers/md/dm-qcow2: implement per-qio fast processing Andrey Zhadchenko
2026-10-29 14:22   ` no-reply
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 6/7] drivers/md/dm-qcow2: declare DM_TARGET_NOWAIT Andrey Zhadchenko
2026-10-29 14:19   ` no-reply
2026-11-03  8:33   ` Alexander Ivanov
2026-11-04 21:35   ` Konstantin Khorenko
2026-10-29 14:03 ` [Devel] [PATCH hci-8.1 7/7] drivers/md/dm-qcow2: process fast path qios in per-cpu batches on a workqueue Andrey Zhadchenko
2026-10-29 14:22   ` no-reply
2026-11-02 10:49     ` Andrey Zhadchenko
2026-11-04 21:35   ` Konstantin Khorenko
2026-11-03  9:36 ` [Devel] [PATCH 0/7] drivers/md/dm-qcow2: per-qio fast path Alexander Ivanov
2026-11-04 21:35 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029140346.465768-5-andrey.zhadchenko@virtuozzo.com \
    --to=andrey.zhadchenko@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=ptikhomirov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox