All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: andrey.zhadchenko@virtuozzo.com, alexander.ivanov@virtuozzo.com,
	vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock
Date: Wed, 25 Nov 2026 02:25:21 +0100	[thread overview]
Message-ID: <20261125012525.681662-6-den@openvz.org> (raw)
In-Reply-To: <20261125012525.681662-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

qcow2_submit_embedded_qio() takes deferred_lock for every request only
to check pause_submitting_qios: an embedded qio is put on no list under
the lock, it goes to the per-cpu fast path list. With metadata parsing
off md_pages_lock, this is the next lock all submitting CPUs share.

Check the pause without the lock. A submitter holds an inflight_ref
reference before it looks at the flag:
- one that misses a pause holds a reference of the old index, which
  set_backward_merge_in_process() waits for in
  qcow2_inflight_ref_switch(). qcow2_ref_inc() takes it inside
  rcu_read_lock(), so it either lands before the grace period of
  percpu_ref_kill() ends and is waited for, or the tryget fails and
  the submitter retries on the new index;
- one that gets a reference of the new index must see the pause, so
  order the flag before the index switch with smp_wmb(), paired with
  the smp_rmb() in qcow2_ref_inc();
- one that sees the pause cleared must see the new
  backward_merge_in_process, so clear it with release semantics and
  read it with acquire.
A paused or flush qio still takes the lock and the old path.

https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 drivers/md/dm-qcow2-cmd.c | 10 ++++++++--
 drivers/md/dm-qcow2-map.c | 36 +++++++++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 00b33ccaab10..02c0e0d8104e 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -160,15 +160,21 @@ static void set_backward_merge_in_process(struct qcow2_target *tgt,
 	 * qios of the top one, so stop the top image even then.
 	 */
 	spin_lock_irq(&top->deferred_lock);
-	top->pause_submitting_qios = true;
+	WRITE_ONCE(top->pause_submitting_qios, true);
 	spin_unlock_irq(&top->deferred_lock);
+	/*
+	 * A submitter that gets a reference of the new inflight_ref index
+	 * must see the pause. Pairs with smp_rmb() in qcow2_ref_inc().
+	 */
+	smp_wmb();
 	qcow2_inflight_ref_switch(tgt);
 
 	/* queue is stopped */
 	spin_lock_irq(&top->deferred_lock);
 	WARN_ON_ONCE(qcow2->backward_merge_in_process == set);
 	qcow2->backward_merge_in_process = set;
-	top->pause_submitting_qios = false;
+	/* A submitter that sees the pause gone sees the new merge state */
+	smp_store_release(&top->pause_submitting_qios, false);
 	list_splice_init(&top->paused_qios, &list);
 	spin_unlock_irq(&top->deferred_lock);
 
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 9d68d713ec3b..17487f52c33e 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -266,7 +266,11 @@ struct qcow2 *qcow2_ref_inc(struct qcow2_target *tgt, u8 *ref_index)
 	rcu_read_lock();
 	do {
 		*ref_index = tgt->inflight_ref_index;
-		smp_rmb(); /* Pairs with qcow2_merge_backward() */
+		/*
+		 * Pairs with qcow2_merge_backward_complete() and
+		 * set_backward_merge_in_process()
+		 */
+		smp_rmb();
 		qcow2 = tgt->top;
 		ref = &tgt->inflight_ref[*ref_index];
 	} while (unlikely(!percpu_ref_tryget(ref)));
@@ -4849,6 +4853,16 @@ static void init_qrq_and_embedded_qio(struct qcow2_target *tgt, struct request *
 	qio->endio_cb_data = qrq;
 }
 
+static void prepare_submitted_qio(struct qio *qio, struct qcow2 *qcow2,
+				  u8 queue_list_id, u8 ref_index)
+{
+	qio->qcow2 = qcow2;
+	qio->queue_list_id = queue_list_id;
+	qio->ref_index = ref_index;
+	if (queue_list_id == QLIST_EMBEDDED)
+		qio->state = QIO_STATE_START;
+}
+
 static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio)
 {
 	struct qcow2_rq *qrq = qio->endio_cb_data;
@@ -4870,18 +4884,26 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio)
 		worker = &qcow2->fsync_worker;
 	}
 
+	/*
+	 * A submitter that misses a concurrent pause holds a reference of
+	 * the old inflight_ref index, which the pause waits for. Pairs with
+	 * smp_store_release() in set_backward_merge_in_process().
+	 */
+	if (queue_list_id == QLIST_EMBEDDED &&
+	    likely(!smp_load_acquire(&qcow2->pause_submitting_qios))) {
+		prepare_submitted_qio(qio, qcow2, queue_list_id, ref_index);
+		qcow2_fast_submit(tgt, qio);
+		return;
+	}
+
 	spin_lock_irqsave(&qcow2->deferred_lock, flags);
 	if (unlikely(qcow2->pause_submitting_qios)) {
 		qcow2_ref_dec(tgt, ref_index);
 		list_add_tail(&qio->link, &qcow2->paused_qios);
 		queue = false;
 	} else {
-		qio->qcow2 = qcow2;
-		qio->queue_list_id = queue_list_id;
-		qio->ref_index = ref_index;
-		if (queue_list_id == QLIST_EMBEDDED)
-			qio->state = QIO_STATE_START;
-		else
+		prepare_submitted_qio(qio, qcow2, queue_list_id, ref_index);
+		if (queue_list_id != QLIST_EMBEDDED)
 			list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]);
 	}
 	spin_unlock_irqrestore(&qcow2->deferred_lock, flags);
-- 
2.55.0

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

  parent reply	other threads:[~2026-11-25  1:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:25 [Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, no I/O scheduler Denis V. Lunev
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 1/9] dm-qcow2: move md_pages_lock off the deferred_lock cache line Denis V. Lunev
2026-12-01  0:05   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 2/9] dm-qcow2: free md pages after an RCU grace period Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:06   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 3/9] dm-qcow2: map fast path reads without md_pages_lock Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:17   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes " Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:25   ` no-reply
2026-11-25  1:25 ` Denis V. Lunev [this message]
2026-12-01  0:27   ` [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:35   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 7/9] dm-qcow2: requeue requests when the request pool is empty Denis V. Lunev
2026-12-01  0:37   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 8/9] dm-ploop: " Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:38   ` no-reply
2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 9/9] dm: default dm-qcow2 devices to no I/O scheduler Denis V. Lunev
2026-11-25 11:19   ` Konstantin Khorenko
2026-12-01  0:39   ` no-reply
2026-11-25 11:19 ` [Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, " Konstantin Khorenko
2026-11-26 13:58 ` Andrey Zhadchenko

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=20261125012525.681662-6-den@openvz.org \
    --to=den@openvz.org \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=vasileios.almpanis@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.