All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, no I/O scheduler
@ 2026-11-25  1:25 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
                   ` (10 more replies)
  0 siblings, 11 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

On top of Andrey's "dm-qcow2: per-qio fast path" v3 [1] the fast path still
serializes on md_pages_lock and deferred_lock, every request completes
through BLOCK_SOFTIRQ (usually in ksoftirqd), and the device runs under
mq-deadline. This series maps fast path reads and overwrites without
md_pages_lock (a per md page generation counter, md pages freed after an
RCU grace period), submits without deferred_lock, completes dm-qcow2
requests directly in the worker, and makes dm-qcow2 default to no I/O
scheduler. dm-qcow2 and dm-ploop now requeue a request instead of
failing it when the request pool is empty, since without mq-deadline
the queue is deeper than the pools were sized for.

The series applies on top of v3 [1] rebased to hci-8.2.

The scheduler default is the largest single step. mq-deadline caps a
device at 256 requests in flight (2 * min(depth, BLKDEV_DEFAULT_RQ)), so a
guest disk with several virtqueues is throttled to that regardless of its
queue sizes, and its dispatch lock serializes all submitters: v3 under
mq-deadline does fewer IOPS with 24 jobs than with 8. dm-qcow2 does not
reorder or merge anything the elevator could help with, the backing file's
own queue still has its scheduler, and IO limits (blk-throttle) act on bios
before the elevator. What is lost is I/O priority class arbitration on the
dm device; mq-deadline can still be selected through sysfs.

4K random I/O, iodepth 32 per job, brd-backed ext4, 1M clusters, fio jobs
one per core across all NUMA nodes, the same patches on the hci-8.1
kernel, kIOPS / p99 us:

                       v3              v3            this series
                   (mq-deadline)     (none)          (none, default)
  read,   8 jobs     550 /  848     1554 /  578       1836 /  191
  read,  24 jobs     384 / 2040     1690 / 1401       4308 /  214
  write,  8 jobs     547 /  971     1353 /  627       1663 /  177

  raw file on the same ext4: read 8 jobs 2162, 24 jobs 5377, write 8 jobs 1859

One job, same columns. QD1 as kIOPS / us per request (1 / IOPS) / p99 us,
QD32 as kIOPS / p99 us:

  read,  QD1       80 / 12.5 / 11   87 / 11.5 / 11   105 /  9.5 /  8
  write, QD1       78 / 12.8 / 11   83 / 12.0 / 11    99 / 10.1 /  9
  read,  QD32         258 / 171        320 / 114         359 / 102
  write, QD32         256 / 167        304 / 129         339 / 107

  raw file: QD1 read 3.5 us, write 3.8 us per request

Tested on hci-8.2 (26.4) in a VM: ploop-pytest for the qcow2 and ploop
formats, data verification under concurrent read/write/discard. The
same checks passed on hci-8.1.

https://virtuozzo.atlassian.net/browse/VSTOR-95494

[1] http://lore.virtuozzo.com/kernel/20261113111126.793039-1-andrey.zhadchenko@virtuozzo.com/

Denis V. Lunev (9):
  dm-qcow2: move md_pages_lock off the deferred_lock cache line
  dm-qcow2: free md pages after an RCU grace period
  dm-qcow2: map fast path reads without md_pages_lock
  dm-qcow2: map fast path writes without md_pages_lock
  dm-qcow2: submit fast path qios without deferred_lock
  dm-rq: complete dm-qcow2 requests directly in task context
  dm-qcow2: requeue requests when the request pool is empty
  dm-ploop: requeue requests when the request pool is empty
  dm: default dm-qcow2 devices to no I/O scheduler

 drivers/md/dm-ploop-map.c     |   2 +-
 drivers/md/dm-ploop.h         |   3 +-
 drivers/md/dm-qcow2-cmd.c     |  10 +-
 drivers/md/dm-qcow2-map.c     | 182 ++++++++++++++++++++++++++++------
 drivers/md/dm-qcow2-target.c  |  43 ++++++--
 drivers/md/dm-qcow2.h         |  33 +++++-
 drivers/md/dm-rq.c            |  22 ++++
 drivers/md/dm-rq.h            |   1 +
 drivers/md/dm-zero-rq.c       |   2 +-
 include/linux/device-mapper.h |   5 +
 10 files changed, 260 insertions(+), 43 deletions(-)

-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 1/9] dm-qcow2: move md_pages_lock off the deferred_lock cache line
  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 ` 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
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

Every request submitted to the device takes deferred_lock in
qcow2_submit_embedded_qio(), and every metadata parse takes
md_pages_lock in parse_metadata(). With the fast path both run on all
submitting CPUs at once. The two locks share a cache line, so each
one's traffic bounces the line under the other one's holders, and the
cost grows with the number of submitting CPUs.

Give md_pages_lock a cache line of its own and keep each lock next to
the lists it protects: the qio queues with deferred_lock, the discard
wait list and the writeback batch lists with md_pages_lock.

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.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 6c5d3e932691..1647ffa363aa 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -286,11 +286,11 @@ struct qcow2 {
 	u32 fault_injection; /* In 1%/QCOW2_FAULT_RATIO */
 
 	spinlock_t deferred_lock ____cacheline_aligned;
-	spinlock_t md_pages_lock;
-
 	struct list_head qios[QLIST_COUNT];
 	struct list_head resubmit_qios;
 	struct list_head paused_qios; /* For pause_submitting_qios */
+
+	spinlock_t md_pages_lock ____cacheline_aligned;
 	struct list_head discard_wait_list;
 
 	/* For batching md update: */
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 2/9] dm-qcow2: free md pages after an RCU grace period
  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-11-25  1:25 ` 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
                   ` (8 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

Metadata lookups are going to walk the md_pages tree without
md_pages_lock. Such a walk may still be on a node that is erased and
freed at the same time, e.g. by do_md_page_read_complete() on a failed
read.

Free md pages from an RCU callback and link new nodes with
rb_link_node_rcu(), so a lookup under rcu_read_lock() never touches
freed memory. rb_find_rcu() tolerates concurrent rotations with a
false negative at worst. The rotations of rb_insert_color() may store
a pointer to the new node again, so order its initialization before
them too. Wait for pending callbacks with rcu_barrier() on module
exit.

qcow2_md_page_renumber() erases and relinks a node in place without a
grace period. A walker on it can only miss, and it only moves R1
pages, which lockless lookups never accept.

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-target.c | 17 ++++++++++++++---
 drivers/md/dm-qcow2.h        |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index b7754f6ca9c4..478e8cdf6d90 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -8,6 +8,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/error-injection.h>
+#include <linux/rcupdate.h>
 
 #include "dm.h"
 #include "dm-qcow2.h"
@@ -148,13 +149,20 @@ void qcow2_call_rw_iter(struct qcow2 *qcow2, loff_t pos, unsigned int rw,
 		iocb->ki_complete(iocb, ret);
 }
 
-void qcow2_free_md_page(struct md_page *md)
+static void qcow2_free_md_page_rcu(struct rcu_head *head)
 {
-	WARN_ON_ONCE(md->wbd || md->lockd);
+	struct md_page *md = container_of(head, struct md_page, rcu);
+
 	put_page(md->page);
 	kfree(md);
 }
 
+void qcow2_free_md_page(struct md_page *md)
+{
+	WARN_ON_ONCE(md->wbd || md->lockd);
+	call_rcu(&md->rcu, qcow2_free_md_page_rcu);
+}
+
 static void qcow2_free_md_pages_tree(struct rb_root *root)
 {
 	struct rb_node *node;
@@ -350,7 +358,9 @@ static int md_page_try_insert(struct qcow2 *qcow2, struct md_page *new_md)
 			return -EEXIST;
 	}
 
-	rb_link_node(&new_md->node, parent, node);
+	rb_link_node_rcu(&new_md->node, parent, node);
+	/* Rotations may publish the node again, after its initialization */
+	smp_wmb();
 	rb_insert_color(&new_md->node, root);
 	return 0;
 }
@@ -1280,6 +1290,7 @@ static int __init dm_qcow2_init(void)
 static void __exit dm_qcow2_exit(void)
 {
 	dm_unregister_target(&qcow2_target);
+	rcu_barrier();
 	kmem_cache_destroy(qrq_cache);
 }
 
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 1647ffa363aa..2107499ea947 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -130,6 +130,7 @@ struct lock_desc {
 
 struct md_page {
 	struct rb_node node;
+	struct rcu_head rcu;
 	u64 id; /* Number of this page starting from hdr */
 #define MD_UPTODATE	(1U << 0) /* Page was read from disk */
 #define MD_DIRTY	(1U << 1) /* Page contains changes and wants writeback */
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 3/9] dm-qcow2: map fast path reads without md_pages_lock
  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-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  1:25 ` 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
                   ` (7 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

Every fast path read takes md_pages_lock in parse_metadata() to look
up the L1 and L2 pages and read their entries. The lock is global for
the device, so reads from all submitting CPUs serialize on it, and
adding submitters makes each read more expensive instead of adding
throughput.

Map the common read without the lock: both pages cached and clean, no
index of them locked, and the cluster mapped exactly once, not
compressed and not all-zeroes. Anything else falls back to the locked
parse. The pages are found with rb_find_rcu(), which the RCU freeing
of md pages makes safe. L1 and L2 pages stay cached once they are
uptodate, so the pointers stay valid after rcu_read_unlock() as they
do after the lock.

An L1 or L2 entry changes only while its page is dirty, or under
writeback when a failed writeback is reverted. A qio on a locked
index waits for the unlock, so a page with a locked index is refused
as well. qcow2_md_page_change() publishes md->gen with release
semantics after MD_DIRTY or the lock bit is set and before an entry
changes, in qcow2_md_make_dirty(), md_index_set_locked() and
revert_l_entries_update(). The reader samples md->gen with
smp_load_acquire() before it checks the page. After reading the entries,
it uses smp_rmb() followed by READ_ONCE() to order the entry reads before
the second sample:
- a reader that sees the new md->gen sees the page dirty, locked or
  under writeback, or a later status;
- a reader that sees a new entry, or one word of an extended entry,
  sees the new md->gen.
MD_UPTODATE and the clean status after writeback are stored with
release, so a reader that sees them sees the page contents and the
reverted entries. md->status, md->wbd, md->lockd and the entries are
written with WRITE_ONCE() and read with READ_ONCE() or acquire.

As with the locked parse, nothing pins the cluster once the read is
mapped, so a discard racing with the read may let it return data of a
reused cluster. That race is VSTOR-154939, accepted as Won't Fix.

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-map.c    | 116 ++++++++++++++++++++++++++++++-----
 drivers/md/dm-qcow2-target.c |  23 ++++++-
 drivers/md/dm-qcow2.h        |  25 ++++++++
 3 files changed, 147 insertions(+), 17 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 1aabadfae763..b22cb5c90918 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -232,7 +232,7 @@ static u64 get_u64_from_page(struct page *page, int index_in_page)
 	u64 *indexes, val;
 
 	indexes = kmap_atomic(page);
-	val = indexes[index_in_page];
+	val = READ_ONCE(indexes[index_in_page]);
 	kunmap_atomic(indexes);
 
 	return val;
@@ -248,7 +248,8 @@ static void set_u64_to_page(struct page *page, int index_in_page, u64 val)
 	u64 *indexes;
 
 	indexes = kmap_atomic(page);
-	indexes[index_in_page] = val;
+	/* L1/L2 entries are read without md_pages_lock */
+	WRITE_ONCE(indexes[index_in_page], val);
 	kunmap_atomic(indexes);
 }
 
@@ -1042,7 +1043,7 @@ static bool qcow2_md_make_dirty(struct qcow2 *qcow2, struct md_page *md, bool is
 	lockdep_assert_held(&qcow2->md_pages_lock);
 
 	if (!(md->status & MD_DIRTY)) {
-		md->status |= MD_DIRTY;
+		WRITE_ONCE(md->status, md->status | MD_DIRTY);
 		list_add_tail(&md->wb_link, head);
 		new = true;
 
@@ -1052,6 +1053,7 @@ static bool qcow2_md_make_dirty(struct qcow2 *qcow2, struct md_page *md, bool is
 		/* Sanity: 1)only L1L2 have wbd, 2)only R1R2 allow redirtying */
 		WARN_ON(md->wbd && ((md->status & MD_WRITEBACK) || is_refs));
 	}
+	qcow2_md_page_change(qcow2, md);
 	return new;
 }
 
@@ -1314,6 +1316,7 @@ static void md_index_set_locked(struct qcow2 *qcow2, struct md_page *md,
 	WARN_ON_ONCE(test_bit(index_in_page, md->lockd->indexes));
 	set_bit(index_in_page, md->lockd->indexes);
 	md->lockd->nr++;
+	qcow2_md_page_change(qcow2, md);
 }
 
 static bool delay_if_locked(struct qcow2 *qcow2, struct md_page *md,
@@ -1428,7 +1431,7 @@ static void do_md_page_read_complete(int ret, struct qcow2 *qcow2,
 	if (ret < 0)
 		qcow2_md_page_erase(qcow2, md);
 	else
-		md->status |= MD_UPTODATE;
+		qcow2_md_set_uptodate(qcow2, md);
 
 	list_splice_tail_init(&md->wait_list, &wait_list);
 	spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
@@ -1449,6 +1452,7 @@ static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd)
 	int i;
 
 	lockdep_assert_held(&qcow2->md_pages_lock);
+	qcow2_md_page_change(qcow2, wbd->md);
 	for_each_set_bit(i, wbd->changed_indexes, LX_INDEXES_PER_PAGE) {
 		/* Here we restore prealloced and compressed clu mappings */
 		old = pe_page ? get_u64_from_be_page(pe_page, i) : 0;
@@ -1462,14 +1466,16 @@ static void clear_writeback_status(struct qcow2 *qcow2, struct md_page *md,
 {
 	lockdep_assert_held(&qcow2->md_pages_lock);
 
-	md->status &= ~(MD_WRITEBACK|MD_WRITEBACK_ERROR);
+	/* Reverted entries before a clean status, see md_page_stable() */
+	smp_store_release(&md->status,
+			  md->status & ~(MD_WRITEBACK|MD_WRITEBACK_ERROR));
 	list_splice_init(&md->wait_list, wait_list);
 	if (ret && !md->wbd) {
 		/*
 		 * L1L2 updates can do safe revert,
 		 * so here we care about R1R2 only.
 		 */
-		md->status |= MD_WRITEBACK_ERROR;
+		WRITE_ONCE(md->status, md->status | MD_WRITEBACK_ERROR);
 		if (ret == -ENOSPC && !READ_ONCE(qcow2->md_wb_no_retry))
 			qcow2_md_make_dirty(qcow2, md, true);
 	}
@@ -1478,7 +1484,7 @@ static void clear_writeback_status(struct qcow2 *qcow2, struct md_page *md,
 			list_splice_init(&md->wbd->dependent_list, wait_list);
 		else
 			list_splice_init(&md->wbd->dependent_list, end_list);
-		md->wbd = NULL;
+		WRITE_ONCE(md->wbd, NULL);
 	}
 }
 
@@ -2110,6 +2116,80 @@ static int qcow2_handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio **
  */
 #define QIO_NEEDS_MAIN_KWORK	2
 
+static bool md_page_stable(struct md_page *md, unsigned int *gen)
+{
+	unsigned int status;
+
+	/* Pairs with qcow2_md_page_change() */
+	*gen = smp_load_acquire(&md->gen);
+	/* Pairs with qcow2_md_set_uptodate(), clear_writeback_status() */
+	status = smp_load_acquire(&md->status);
+	return (status & (MD_UPTODATE | MD_DIRTY | MD_WRITEBACK |
+			  MD_WRITEBACK_ERROR)) == MD_UPTODATE &&
+	       !READ_ONCE(md->wbd) && !READ_ONCE(md->lockd);
+}
+
+/*
+ * Map a read of an allocated cluster without md_pages_lock. Both L1 and
+ * L2 pages must be cached and clean, and the cluster mapped exactly once,
+ * not compressed and not all-zeroes. A page change seen through md->gen,
+ * or any other case, returns false, and the caller parses under the lock.
+ */
+static bool parse_metadata_lockless(struct qcow2 *qcow2, struct qio *qio,
+				    struct qcow2_map *map, u64 *ret_pos)
+{
+	unsigned int l1_gen, l2_gen;
+	struct md_page *l1, *l2;
+	u64 entry, pos, ext_l2 = 0;
+	bool ret = false;
+
+	rcu_read_lock();
+	l1 = qcow2_md_page_find_rcu(qcow2, map->l1.page_id);
+	if (!l1 || !md_page_stable(l1, &l1_gen))
+		goto out;
+	entry = get_u64_from_be_page(l1->page, map->l1.index_in_page);
+	pos = entry & ~LX_REFCOUNT_EXACTLY_ONE;
+	if (!(entry & LX_REFCOUNT_EXACTLY_ONE) || !pos ||
+	    (entry & L1_RESERVED_ZERO_MASK) || CLU_OFF(qcow2, pos))
+		goto out;
+
+	pos += map->l2.index * sizeof(u64);
+	calc_page_id_and_index(pos, &map->l2.page_id, &map->l2.index_in_page);
+	l2 = qcow2_md_page_find_rcu(qcow2, map->l2.page_id);
+	if (!l2 || !md_page_stable(l2, &l2_gen))
+		goto out;
+	entry = get_u64_from_be_page(l2->page, map->l2.index_in_page);
+	pos = entry & ~LX_REFCOUNT_EXACTLY_ONE;
+	if (!(entry & LX_REFCOUNT_EXACTLY_ONE) || !pos ||
+	    (pos & (L2_COMPRESSED_CLUSTER | L2_READS_ALL_ZEROES |
+		    L2_RESERVED_ZERO_MASK)) || CLU_OFF(qcow2, pos))
+		goto out;
+	if (qcow2->ext_l2) {
+		ext_l2 = get_u64_from_be_page(l2->page,
+					      map->l2.index_in_page + 1);
+		if (ext_l2 & (ext_l2 >> 32))
+			goto out;
+	}
+
+	/* Pairs with smp_wmb() in qcow2_md_page_change() */
+	smp_rmb();
+	if (READ_ONCE(l1->gen) != l1_gen || READ_ONCE(l2->gen) != l2_gen)
+		goto out;
+
+	map->l1.md = l1;
+	map->l2.md = l2;
+	map->level = L1_LEVEL | L2_LEVEL;
+	map->ext_l2 = ext_l2;
+	if (qcow2->ext_l2 && !fake_service_qio(qio))
+		map->subclus_mask = qio_subclus_mask(qcow2, qio);
+	map->data_clu_alloced = true;
+	*ret_pos = pos;
+	ret = true;
+out:
+	rcu_read_unlock();
+	return ret;
+}
+
 /*
  * This caches pages of allocated on disk md levels, which are
  * required for submission @qio, and checks they are stable.
@@ -2135,6 +2215,11 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio,
 	WARN_ON_ONCE(map->data_clu_pos != 0);
 	if (qcow2_calc_cluster_map(qcow2, *qio, map) < 0)
 		return -EIO;
+	if (avoid_metadata_changes && !write &&
+	    parse_metadata_lockless(qcow2, *qio, map, &pos)) {
+		map->data_clu_pos = pos;
+		return 0;
+	}
 	spin_lock_irq(&qcow2->md_pages_lock);
 again:
 	/* Check L1 page */
@@ -2230,7 +2315,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
 	spin_lock_irq(&qcow2->md_pages_lock);
 	set_u64_to_be_page(r1->md->page, r1->index_in_page, r2_pos);
 	qcow2_md_make_dirty(qcow2, r1->md, true);
-	r2->md->status |= MD_UPTODATE;
+	qcow2_md_set_uptodate(qcow2, r2->md);
 	spin_unlock_irq(&qcow2->md_pages_lock);
 
 	mark_cluster_used(qcow2, r2->md, r2->index_in_page);
@@ -2529,7 +2614,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
 			goto err_free_r2_pages;
 		spin_lock_irq(&qcow2->md_pages_lock);
 		qcow2_zero_fill_page_from(md->page, 0);
-		md->status |= MD_UPTODATE;
+		qcow2_md_set_uptodate(qcow2, md);
 		spin_unlock_irq(&qcow2->md_pages_lock);
 	}
 
@@ -2752,7 +2837,7 @@ static int prepare_l_entry_update(struct qcow2 *qcow2, struct qio *qio,
 
 	spin_lock_irq(&qcow2->md_pages_lock);
 	if (qcow2_md_make_dirty(qcow2, md, false))
-		md->wbd = new_wbd;
+		WRITE_ONCE(md->wbd, new_wbd);
 	else
 		WARN_ON_ONCE(new_wbd);
 	first = !test_and_set_bit(index_in_page, md->wbd->changed_indexes);
@@ -2875,7 +2960,7 @@ static int prepare_l_entry_replace(struct qcow2 *qcow2, struct qcow2_map *map,
 		if (!lockd)
 			return -ENOMEM;
 		spin_lock_irq(&qcow2->md_pages_lock);
-		md->lockd = lockd;
+		WRITE_ONCE(md->lockd, lockd);
 	}
 
 	md_index_set_locked(qcow2, md, index_in_page);
@@ -4123,8 +4208,7 @@ static void submit_metadata_writeback(struct qcow2 *qcow2)
 		/* L1L2 mustn't be redirtyed, when wb in-flight! */
 		WARN_ON_ONCE(!(md->status & MD_DIRTY) ||
 			      (md->wbd && (md->status & MD_WRITEBACK)));
-		md->status |= MD_WRITEBACK;
-		md->status &= ~MD_DIRTY;
+		WRITE_ONCE(md->status, (md->status & ~MD_DIRTY) | MD_WRITEBACK);
 		spin_unlock_irq(&qcow2->md_pages_lock);
 
 		submit_rw_md_page(WRITE, qcow2, md);
@@ -4843,8 +4927,10 @@ static void handle_cleanup_mask(struct qio *qio)
 		spin_lock_irqsave(&qcow2->md_pages_lock, flags);
 		clear_bit(ext->lx_index_in_page, md->lockd->indexes);
 		WARN_ON_ONCE(--md->lockd->nr < 0);
-		if (!md->lockd->nr)
-			swap(md->lockd, lockd);
+		if (!md->lockd->nr) {
+			lockd = md->lockd;
+			WRITE_ONCE(md->lockd, NULL);
+		}
 		list_splice_init(&md->wait_list, &qio_list);
 		spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
 		qcow2_dispatch_qios(qcow2, NULL, &qio_list);
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 478e8cdf6d90..af8a6d286830 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -313,6 +313,24 @@ static struct md_page *qcow2_md_page_find(struct qcow2 *qcow2, u64 id)
 }
 ALLOW_ERROR_INJECTION(qcow2_md_page_find, NULL);
 
+static int md_page_cmp(const void *key, const struct rb_node *node)
+{
+	u64 id = *(const u64 *)key;
+	u64 md_id = READ_ONCE(rb_entry(node, struct md_page, node)->id);
+
+	if (id < md_id)
+		return -1;
+	return id > md_id;
+}
+
+/* Under rcu_read_lock(), may miss a page while the tree is changing */
+struct md_page *qcow2_md_page_find_rcu(struct qcow2 *qcow2, u64 id)
+{
+	struct rb_node *node = rb_find_rcu(&id, &qcow2->md_pages, md_page_cmp);
+
+	return node ? rb_entry(node, struct md_page, node) : NULL;
+}
+
 /*
  * This returns md if it's found and up to date, or NULL.
  * @qio is zeroed if it's postponed.
@@ -380,7 +398,7 @@ struct md_page *qcow2_md_page_renumber(struct qcow2 *qcow2, u64 id, u64 new_id)
 	if (md) {
 		WARN_ON_ONCE(!list_empty(&md->wait_list));
 		qcow2_md_page_erase(qcow2, md);
-		md->id = new_id;
+		WRITE_ONCE(md->id, new_id);
 		if (WARN_ON(md_page_try_insert(qcow2, md) < 0))
 			md = NULL;
 	}
@@ -409,6 +427,7 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
 
 	(*md)->id = index;
 	(*md)->status = 0;
+	(*md)->gen = 0;
 	(*md)->wbd = NULL;
 	(*md)->lockd = NULL;
 	atomic_set(&(*md)->wpc_readers, 0);
@@ -470,7 +489,7 @@ int qcow2_md_page_read_sync(struct qcow2 *qcow2, u64 id, struct md_page **md)
 	}
 
 	spin_lock_irq(&qcow2->md_pages_lock);
-	(*md)->status |= MD_UPTODATE;
+	qcow2_md_set_uptodate(qcow2, *md);
 	spin_unlock_irq(&qcow2->md_pages_lock);
 	return 0;
 err:
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 2107499ea947..accac35fa345 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -137,6 +137,7 @@ struct md_page {
 #define MD_WRITEBACK	(1U << 2) /* Writeback was submitted */
 #define MD_WRITEBACK_ERROR (1U << 3) /* Last writeback failed with error */
 	unsigned int status;
+	unsigned int gen; /* See qcow2_md_page_change() */
 	u8 writer_gen;
 	u16 discard_waiters;
 	struct page *page;
@@ -418,6 +419,7 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index,
 					struct md_page **md);
 int qcow2_md_page_read_sync(struct qcow2 *qcow2, u64 id,
 			    struct md_page **md);
+struct md_page *qcow2_md_page_find_rcu(struct qcow2 *qcow2, u64 id);
 struct md_page *qcow2_md_page_find_or_postpone(struct qcow2 *qcow2,
 					       u64 id, struct qio **qio);
 struct md_page *qcow2_md_page_renumber(struct qcow2 *qcow2, u64 id,
@@ -447,6 +449,29 @@ loff_t qcow2_calc_used_end(struct qcow2 *qcow2);
 void qcow2_merge_backward_work(struct work_struct *work);
 void qcow2_merge_backward_cancel(struct qcow2_target *tgt);
 
+/*
+ * Called with MD_DIRTY, MD_WRITEBACK (on revert), or a lock bit set,
+ * before the L1/L2 entries change, so a reader that sees the new gen sees
+ * the flag or a later status, and a reader that sees a new entry sees the
+ * new gen.
+ * See md_page_stable().
+ */
+static inline void qcow2_md_page_change(struct qcow2 *qcow2,
+					struct md_page *md)
+{
+	lockdep_assert_held(&qcow2->md_pages_lock);
+	smp_store_release(&md->gen, md->gen + 1);
+	smp_wmb();
+}
+
+/* A reader that sees MD_UPTODATE sees the page contents */
+static inline void qcow2_md_set_uptodate(struct qcow2 *qcow2,
+					 struct md_page *md)
+{
+	lockdep_assert_held(&qcow2->md_pages_lock);
+	smp_store_release(&md->status, md->status | MD_UPTODATE);
+}
+
 static inline struct qcow2_target *to_qcow2_target(struct dm_target *ti)
 {
 	return ti->private;
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes without md_pages_lock
  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
                   ` (2 preceding siblings ...)
  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  1:25 ` Denis V. Lunev
  2026-11-25 11:19   ` Konstantin Khorenko
  2026-12-01  0:25   ` no-reply
  2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock Denis V. Lunev
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

Fast path writes still take md_pages_lock in parse_metadata() to map
the cluster and count themselves in the L2 page's active_writers. With
reads off the lock it is the remaining global serialization point for
an overwrite workload.

Map plain writes of allocated clusters through
parse_metadata_lockless() too, then count the write and recheck the
L2 page's md->gen. A discard that unmaps the cluster locks its index,
which bumps md->gen, long before it waits for writers in
delay_discard_if_writers(). With a full barrier on both sides, either
the write sees the new md->gen, uncounts itself and takes the locked
path, or the discard sees the count and waits for the write to finish
before the cluster can be reused. The barrier is taken on entry, so a
discard that re-enters to recheck the generation it waits for is
covered as well.

The write reads md->writer_gen without the lock. If it reads the
generation the discard has just switched to, the switch comes after
the md->gen bump and the discard's barrier, so the write's recheck
sees the bump and backs off. If it reads the old one, the discard
waits for it as for any earlier write.

Discards and write-zeroes keep the locked parse.

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-map.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index b22cb5c90918..9d68d713ec3b 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -621,7 +621,7 @@ static bool delay_if_has_wpc_readers(struct qcow2 *qcow2, struct md_page *md,
 static void inc_writers(struct md_page *md, struct qio *qio)
 {
 	qio->writer_md = md;
-	qio->writer_gen = md->writer_gen;
+	qio->writer_gen = READ_ONCE(md->writer_gen);
 	atomic_inc(&md->active_writers[qio->writer_gen]);
 }
 
@@ -670,6 +670,14 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md,
 	u8 gen;
 
 	spin_lock_irq(&qcow2->md_pages_lock);
+	/*
+	 * md->active_writers checks are valid only if increases are from
+	 * main kwork (as we are), under md_pages_lock, or from a lockless
+	 * fast path write, which counts itself and then rechecks md->gen,
+	 * bumped by md_index_set_locked() when this discard locked the index.
+	 * Pairs with smp_mb__after_atomic() in parse_metadata_lockless().
+	 */
+	smp_mb();
 	if (qio->flags & QIO_DISCARD_WAIT_FL) {
 		if (atomic_read(&md->active_writers[qio->writer_gen]))
 			goto delay;
@@ -679,10 +687,6 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md,
 		goto unlock;
 	}
 
-	/*
-	 * md->active_writers checks are valid only if increases are
-	 * from main kwork (as we are) or under md_pages_lock.
-	 */
 	gen = md->writer_gen;
 	if (md->discard_waiters) {
 		/*
@@ -2130,10 +2134,11 @@ static bool md_page_stable(struct md_page *md, unsigned int *gen)
 }
 
 /*
- * Map a read of an allocated cluster without md_pages_lock. Both L1 and
- * L2 pages must be cached and clean, and the cluster mapped exactly once,
- * not compressed and not all-zeroes. A page change seen through md->gen,
- * or any other case, returns false, and the caller parses under the lock.
+ * Map a read or write of an allocated cluster without md_pages_lock. Both
+ * L1 and L2 pages must be cached and clean, and the cluster mapped exactly
+ * once, not compressed and not all-zeroes. A page change seen through
+ * md->gen, or any other case, returns false, and the caller parses under
+ * the lock.
  */
 static bool parse_metadata_lockless(struct qcow2 *qcow2, struct qio *qio,
 				    struct qcow2_map *map, u64 *ret_pos)
@@ -2176,6 +2181,16 @@ static bool parse_metadata_lockless(struct qcow2 *qcow2, struct qio *qio,
 	if (READ_ONCE(l1->gen) != l1_gen || READ_ONCE(l2->gen) != l2_gen)
 		goto out;
 
+	if (op_is_write(qio->bi_op)) {
+		inc_writers(l2, qio);
+		/* Pairs with smp_mb() in delay_discard_if_writers() */
+		smp_mb__after_atomic();
+		if (READ_ONCE(l2->gen) != l2_gen) {
+			dec_writers(qio);
+			goto out;
+		}
+	}
+
 	map->l1.md = l1;
 	map->l2.md = l2;
 	map->level = L1_LEVEL | L2_LEVEL;
@@ -2215,7 +2230,8 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio,
 	WARN_ON_ONCE(map->data_clu_pos != 0);
 	if (qcow2_calc_cluster_map(qcow2, *qio, map) < 0)
 		return -EIO;
-	if (avoid_metadata_changes && !write &&
+	if (avoid_metadata_changes &&
+	    (!write || (*qio)->bi_op == REQ_OP_WRITE) &&
 	    parse_metadata_lockless(qcow2, *qio, map, &pos)) {
 		map->data_clu_pos = pos;
 		return 0;
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock
  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
                   ` (3 preceding siblings ...)
  2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes " Denis V. Lunev
@ 2026-11-25  1:25 ` Denis V. Lunev
  2026-12-01  0:27   ` 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
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context
  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
                   ` (4 preceding siblings ...)
  2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock Denis V. Lunev
@ 2026-11-25  1:25 ` 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
                   ` (4 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

From: Denis V. Lunev <den@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@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

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 7/9] dm-qcow2: requeue requests when the request pool is empty
  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
                   ` (5 preceding siblings ...)
  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  1:25 ` 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
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

The request pool was sized at twice mq-deadline's default nr_requests
of 2 * min(depth, BLKDEV_DEFAULT_RQ). With the default single hardware
queue, even a request from every tag could not exhaust the reserve.

Without a scheduler the device has dm_mq_queue_depth tags per hardware
queue. If GFP_ATOMIC slab allocation fails with more requests in flight
than the reserve can cover, qcow2_clone_and_map() kills the next request
and the guest gets an I/O error. Return DM_MAPIO_REQUEUE so blk-mq
applies backpressure and retries the request when resources free up.

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-map.c | 2 +-
 drivers/md/dm-qcow2.h     | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index d1dec85236b8..c450d1de5689 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4938,7 +4938,7 @@ int qcow2_clone_and_map(struct dm_target *ti, struct request *rq,
 
 	qrq = mempool_alloc(tgt->qrq_pool, GFP_ATOMIC);
 	if (!qrq)
-		return DM_MAPIO_KILL;
+		return DM_MAPIO_REQUEUE;
 	qio = (void *)qrq + sizeof(*qrq);
 	init_qrq_and_embedded_qio(tgt, rq, qrq, qio);
 
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index accac35fa345..dce623ccc78e 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -193,7 +193,8 @@ struct qcow2_backward_merge {
 
 struct qcow2_target {
 	struct dm_target *ti;
-#define QCOW2_QRQ_POOL_SIZE 512 /* Twice nr_requests from blk_mq_init_sched() */
+/* Reserve to keep requests moving when slab allocations fail. */
+#define QCOW2_QRQ_POOL_SIZE 512
 	mempool_t *qrq_pool;
 	mempool_t *qio_pool;
 	/*
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 8/9] dm-ploop: requeue requests when the request pool is empty
  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
                   ` (6 preceding siblings ...)
  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-11-25  1:25 ` 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
                   ` (2 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

The next commit disables the default I/O scheduler for devices that
ploop_dmcreate_stub() creates with a zero-rq table. Loading a ploop
table later keeps that scheduler setting, so the device can have more
requests in flight than the 512-entry reserve sized for mq-deadline.

If the reserve is empty and GFP_ATOMIC allocation fails,
ploop_clone_and_map() kills the request with an I/O error. Requeue it
so blk-mq retries when resources are available.

https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-ploop: ploop target driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 drivers/md/dm-ploop-map.c | 2 +-
 drivers/md/dm-ploop.h     | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index c62b414862b1..827346e037b0 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -2663,7 +2663,7 @@ int ploop_clone_and_map(struct dm_target *ti, struct request *rq,
 
 	prq = mempool_alloc(ploop->prq_pool, GFP_ATOMIC);
 	if (!prq)
-		return DM_MAPIO_KILL;
+		return DM_MAPIO_REQUEUE;
 	pio = (void *)prq + sizeof(*prq);
 
 	ploop_init_prq_and_embedded_pio(ploop, rq, prq, pio);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 093b7f9397a4..660e4d3531b8 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -164,7 +164,8 @@ struct ploop {
 	struct wait_queue_head dispatcher_wq_data;
 	struct wait_queue_head dispatcher_wq_fsync;
 	struct dm_target *ti;
-#define PLOOP_PRQ_POOL_SIZE 512 /* Twice nr_requests from blk_mq_init_sched() */
+/* Reserve to keep requests moving when slab allocations fail. */
+#define PLOOP_PRQ_POOL_SIZE 512
 	mempool_t *prq_pool;
 #define PLOOP_PIO_POOL_SIZE 512
 	mempool_t *pio_pool;
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Devel] [PATCH hci-8.2 9/9] dm: default dm-qcow2 devices to no I/O scheduler
  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
                   ` (7 preceding siblings ...)
  2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 8/9] dm-ploop: " Denis V. Lunev
@ 2026-11-25  1:25 ` 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
  10 siblings, 2 replies; 27+ messages in thread
From: Denis V. Lunev @ 2026-11-25  1:25 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

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

Request-based dm has one hardware queue by default, so it gets
mq-deadline. On that queue mq-deadline caps requests in flight at 256
by default (2 * min(depth, BLKDEV_DEFAULT_RQ)) and serialises insert
and dispatch on its lock. The cost grows with queue depth and the
number of submitters. Sorting by device sector buys little for dm-qcow2
because adjacent guest sectors can be far apart in the image, and the
backing device can schedule the image I/O itself.

Set DM_TARGET_NO_SCHED_BY_DEFAULT on dm-qcow2. When the target in the
initial request-based table has this flag, dm_mq_init_request_queue()
sets BLK_MQ_F_NO_SCHED_BY_DEFAULT, as loop does, so elevator_set_default()
leaves the device with none.

mq-deadline arbitrates between I/O priority classes at dispatch. With
none, the dm device loses that arbitration. dm-qcow2 issues image I/O
from its workers, so the request's priority class does not reach the
backing device either. mq-deadline can still be selected through sysfs.

libploop creates qcow2 devices and ploop_dmcreate_stub() devices with a
zero-rq table and loads the real table later. Set the flag on zero-rq
as well because the scheduler is chosen when the device is created.

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-target.c  | 3 ++-
 drivers/md/dm-rq.c            | 2 ++
 drivers/md/dm-zero-rq.c       | 2 +-
 include/linux/device-mapper.h | 5 +++++
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index af8a6d286830..3789fb191207 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -1274,7 +1274,8 @@ static void qcow2_resume(struct dm_target *ti)
 static struct target_type qcow2_target = {
 	.name = "qcow2",
 	.version = {1, 0, 0},
-	.features = DM_TARGET_SINGLETON | DM_TARGET_NOWAIT,
+	.features = DM_TARGET_SINGLETON | DM_TARGET_NOWAIT |
+		    DM_TARGET_NO_SCHED_BY_DEFAULT,
 	.module = THIS_MODULE,
 	.ctr = qcow2_ctr,
 	.dtr = qcow2_dtr,
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 0d31fcf84aed..af05ec40bf85 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -585,6 +585,8 @@ int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t)
 	md->tag_set->queue_depth = dm_get_blk_mq_queue_depth();
 	md->tag_set->numa_node = md->numa_node_id;
 	md->tag_set->flags = BLK_MQ_F_STACKING;
+	if (dm_target_no_sched_by_default(dm_table_get_target(t, 0)->type))
+		md->tag_set->flags |= BLK_MQ_F_NO_SCHED_BY_DEFAULT;
 	md->tag_set->nr_hw_queues = dm_get_blk_mq_nr_hw_queues();
 	md->tag_set->driver_data = md;
 
diff --git a/drivers/md/dm-zero-rq.c b/drivers/md/dm-zero-rq.c
index 315ef8c930b3..3584e86e80e2 100644
--- a/drivers/md/dm-zero-rq.c
+++ b/drivers/md/dm-zero-rq.c
@@ -60,7 +60,7 @@ static int zero_clone_and_map_rq(struct dm_target *ti, struct request *rq,
 static struct target_type zero_target = {
 	.name   = "zero-rq",
 	.version = {1, 1, 0},
-	.features = DM_TARGET_NOWAIT,
+	.features = DM_TARGET_NOWAIT | DM_TARGET_NO_SCHED_BY_DEFAULT,
 	.module = THIS_MODULE,
 	.ctr    = zero_ctr,
 	.clone_and_map_rq = zero_clone_and_map_rq,
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 05715910fae9..1b131ef7060b 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -313,6 +313,11 @@ struct target_type {
 #define DM_TARGET_ATOMIC_WRITES		0x00000400
 #define dm_target_supports_atomic_writes(type) ((type)->features & DM_TARGET_ATOMIC_WRITES)
 
+/* Skip the default I/O scheduler for this request-based target. */
+#define DM_TARGET_NO_SCHED_BY_DEFAULT	0x00000800
+#define dm_target_no_sched_by_default(type) \
+		((type)->features & DM_TARGET_NO_SCHED_BY_DEFAULT)
+
 struct dm_target {
 	struct dm_table *table;
 	struct target_type *type;
-- 
2.55.0

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, no I/O scheduler
  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
                   ` (8 preceding siblings ...)
  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-11-26 13:58 ` Andrey Zhadchenko
  10 siblings, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

1. 8/9: a failed split pio allocation still fails the request; requeue
   or defer it too.
2. 9/9: the zero-rq flag moves every ploop device that libploop creates
   to none as well; say so and why, or keep ploop on mq-deadline.
3. 9/9: take a high bit for the vz-only DM_TARGET_ flag.
4. 9/9 and the cover letter: say that elevator merging is lost too.
5. 2/9, 3/9, 4/9: commit message fixes, see the replies.
6. 6/9: the comment above dm_complete_request_direct().

The lockless mapping in 3/9 and 4/9 and the unlocked pause check in
5/9 hold: I found no interleaving that breaks the barrier pairs. The
series was reviewed on hci-8.2 plus Andrey's per-qio fast path v3
picked onto it; the result matches the blobs your patches apply to.

On Wed, 25 Nov 2026 02:25:16 +0100, Denis V. Lunev wrote:
> mq-deadline does fewer IOPS with 24 jobs than with 8. dm-qcow2 does not
> reorder or merge anything the elevator could help with, the backing file's

Item 4: with none, adjacent requests that miss the plug are no longer
merged on the dm device, and only 4K random I/O was measured. Please
drop this claim or measure sequential I/O.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 2/9] dm-qcow2: free md pages after an RCU grace period
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Fix the R1 sentence: item 5 of the cover letter reply.

On Wed, 25 Nov 2026 02:25:18 +0100, Denis V. Lunev wrote:
> qcow2_md_page_renumber() erases and relinks a node in place without a
> grace period. A walker on it can only miss, and it only moves R1
> pages, which lockless lookups never accept.

Nothing checks the page type: the lockless lookups only ask for L1 and
L2 page ids, so they never look an R1 page up. Say that.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 3/9] dm-qcow2: map fast path reads without md_pages_lock
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Split the long paragraph: item 5 of the cover letter reply.

On Wed, 25 Nov 2026 02:25:19 +0100, Denis V. Lunev wrote:
> An L1 or L2 entry changes only while its page is dirty, or under
> writeback when a failed writeback is reverted. A qio on a locked
> index waits for the unlock, so a page with a locked index is refused
> as well. qcow2_md_page_change() publishes md->gen with release

Five sentences and a list in one paragraph: put the writer side
(qcow2_md_page_change()) and the reader side (the two samples) into
paragraphs of their own.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes without md_pages_lock
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Fix the reason for the old writer_gen case: item 5 of the cover
  letter reply.

On Wed, 25 Nov 2026 02:25:20 +0100, Denis V. Lunev wrote:
> sees the bump and backs off. If it reads the old one, the discard
> waits for it as for any earlier write.

When another discard switched writer_gen, this discard does not wait
for the old generation. The write is still safe because this discard
holds the lock bit on the same L2 page, and its own md->gen bump makes
the recheck fail. Please say that here and next to inc_writers().

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Fix the comment: item 6 of the cover letter reply.

On Wed, 25 Nov 2026 02:25:22 +0100, Denis V. Lunev wrote:
> + * Raising BLOCK_SOFTIRQ from a task wakes ksoftirqd. Complete inline
> + * if affinity permits. The caller must not hold a lock that completion

Under the default rq_affinity=1 the cache domain check is skipped on
purpose, as the message says; "if affinity permits" reads as the
opposite. "unless rq_affinity=2 asks for the submitting CPU" says what
the code does.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 8/9] dm-ploop: requeue requests when the request pool is empty
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Requeue or defer a request whose split pio allocation fails: item 1
  of the cover letter reply.

On Wed, 25 Nov 2026 02:25:24 +0100, Denis V. Lunev wrote:
>  	prq = mempool_alloc(ploop->prq_pool, GFP_ATOMIC);
>  	if (!prq)
> -		return DM_MAPIO_KILL;
> +		return DM_MAPIO_REQUEUE;

This covers the prq only. ploop_split_and_chain_pio() takes the split
pios from pio_pool, also 512 entries and GFP_ATOMIC, and when that
fails ploop_prepare_one_embedded_pio() ends the request with
BLK_STS_RESOURCE, an I/O error in the container. With no scheduler
after 9/9 the device can have far more requests in flight than that
reserve was sized for, so this path becomes reachable. The bvec
allocation in the same function already defers to blocking context;
the split can do the same.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 9/9] dm: default dm-qcow2 devices to no I/O scheduler
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Konstantin Khorenko @ 2026-11-25 11:19 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Say that ploop devices lose the scheduler too, or keep them on it:
  item 2.
- A high bit for the vz-only flag: item 3.
- Say that elevator merging is lost: item 4 of the cover letter reply.

On Wed, 25 Nov 2026 02:25:25 +0100, Denis V. Lunev wrote:
> libploop creates qcow2 devices and ploop_dmcreate_stub() devices with a
> zero-rq table and loads the real table later. Set the flag on zero-rq
> as well because the scheduler is chosen when the device is created.

Item 2: ploop_dmcreate_stub() creates ploop devices too, so they all
end up on none, while a device created directly with a ploop table
stays on mq-deadline. The subject and the cover letter speak of
dm-qcow2 only, and ploop was not measured. Either say it and why none
is right for ploop as well, or let libploop pick the scheduler per
format.

> +#define DM_TARGET_NO_SCHED_BY_DEFAULT	0x00000800

Item 3: 0x800 is the next bit mainline hands out, so the next backport
of a new DM_TARGET_ flag collides with it. Take a high bit.

> mq-deadline arbitrates between I/O priority classes at dispatch. With
> none, the dm device loses that arbitration. dm-qcow2 issues image I/O

Item 4: it also loses merging of adjacent requests that miss the plug,
and the read-over-write preference.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 0/9] dm-qcow2: lockless fast path, direct completion, no I/O scheduler
  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
                   ` (9 preceding siblings ...)
  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
  10 siblings, 0 replies; 27+ messages in thread
From: Andrey Zhadchenko @ 2026-11-26 13:58 UTC (permalink / raw)
  To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel

My few points:

1. I don't like rcu, smp_wb, etc. dances around md_pages validity. It is 
too complicated and also looks like reinventing the wheel. I had another 
idea in my mind for a while:
  - change md_pages container from rbtree to xarray. It is tailored to 
page-tables which md_pages essentially are. We get the access and store 
helpers with known guarantees out of the box, so we don't need to dance 
with synchronisation primitives. Also it is more efficient than rbtree.
  - add new 'staging' rbtree (or whatever) where pages lie when they are 
constructed. Only when the pages are ready they are published to main 
xarray.

2. I don't like MANUAL dances around md->gen. What you want here is 
seqcount_spinlock_t (write_seqcount_begin() + write_seqcount_end() for 
writer and raw_read_seqcount() + read_seqcount_retry() for reader). Your 
code more or less implements that instead of using existing primitives.

3. I really like new dm_complete_request_direct() because it helps us to 
get rid of dm_nr_hw_queues() and reduces qd1 latency. This is a real gain.

4. I don't like parse_metadata_lockless() as this just a duplicate of 
parse_metadata() with a few quirks. It potentially doubles any 
maintainer or submitter work while changing metadata parsing. It 
introduces complex synchronization steps with many edge cases.

4. I don't buy the speed measurements.
Here what I got:

fio with randwrite, 4K size, io_uring, iodepth=64. dm_mq_nr_hw_queues=8 
for patchset 1 and dm_mq_nr_hw_queues=1 for all other. Value is IOPS.
Baseline is raw file on ext4 formatted ramdisk. patchset1 is fastpath 
patchset, patchset 2 is this patchset, patchset 1+2-lockless does not 
include patches that turn fast read into lockless.

       baseline    patchset 1   patchset 1+2   patchset 1+2-lockless
1thr   388K         371K           428K                426K
2thr   781K         819K           811K                817K
4thr  1471K        1171K          1167K               1119K
8thr  2222K        1453K          1398K               1360K

randwrite, 4K size, io_uring, iodepth=1; IOPS/latency p99, us

       baseline    patchset 1   patchset 1+2   patchset 1+2-lockless
1thr  396K/2.27    113K/8.45     145K/6.57           140K/6.8

My machine is Xeon E-2136, 6 cores / 12 threads, so 4thread is the last 
point under 100% cpu for dm-based devices.


So my final opinion:
  - direct complete we should take anyway, this a big win
  - lockless part is a benchmaxxxing and we should consider our IOPS 
targets before taking it.
Introduced complexity is big (even if we use existing primitives instead 
of re-implementing them with barriers) but the win is negligible on any 
real scenarios. If you run this with 1000 submitters spinlock will 
perform even worse, but what's the point? 4threads have more or less the 
same 5GB/s performance with tiny-tiny 4K request size. What is real-case 
scenario? What is the values we want to achieve? As far as I remember 
our target was 1M IOPS.
This all also looks like premature optimization. I think the next steps 
should be parallelizing metadata changes to different md pages. For this 
we will potentially need per-md page lock which will also naturally 
reduce md_pages_lock contention even if we take this per-md page lock on 
fast path.

P.S. Also looks L1 page is mostly full of never-changing constants. If 
we set some index and it has LX_REFCOUNT_EXACTLY_ONE it never changes 
afterwards. So maybe we can fully skip any synchronization on L1 page if 
we have a bitmap of such indexes. Or we can probably just create a plain 
l2 array instead (32Kb per 1Tb disk with l2 and clu_size 1Mb) and never 
really use L1 page, only keep it coherent.

On 11/25/26 02:25, Denis V. Lunev wrote:
> On top of Andrey's "dm-qcow2: per-qio fast path" v3 [1] the fast path still
> serializes on md_pages_lock and deferred_lock, every request completes
> through BLOCK_SOFTIRQ (usually in ksoftirqd), and the device runs under
> mq-deadline. This series maps fast path reads and overwrites without
> md_pages_lock (a per md page generation counter, md pages freed after an
> RCU grace period), submits without deferred_lock, completes dm-qcow2
> requests directly in the worker, and makes dm-qcow2 default to no I/O
> scheduler. dm-qcow2 and dm-ploop now requeue a request instead of
> failing it when the request pool is empty, since without mq-deadline
> the queue is deeper than the pools were sized for.
> 
> The series applies on top of v3 [1] rebased to hci-8.2.
> 
> The scheduler default is the largest single step. mq-deadline caps a
> device at 256 requests in flight (2 * min(depth, BLKDEV_DEFAULT_RQ)), so a
> guest disk with several virtqueues is throttled to that regardless of its
> queue sizes, and its dispatch lock serializes all submitters: v3 under
> mq-deadline does fewer IOPS with 24 jobs than with 8. dm-qcow2 does not
> reorder or merge anything the elevator could help with, the backing file's
> own queue still has its scheduler, and IO limits (blk-throttle) act on bios
> before the elevator. What is lost is I/O priority class arbitration on the
> dm device; mq-deadline can still be selected through sysfs.
> 
> 4K random I/O, iodepth 32 per job, brd-backed ext4, 1M clusters, fio jobs
> one per core across all NUMA nodes, the same patches on the hci-8.1
> kernel, kIOPS / p99 us:
> 
>                         v3              v3            this series
>                     (mq-deadline)     (none)          (none, default)
>    read,   8 jobs     550 /  848     1554 /  578       1836 /  191
>    read,  24 jobs     384 / 2040     1690 / 1401       4308 /  214
>    write,  8 jobs     547 /  971     1353 /  627       1663 /  177
> 
>    raw file on the same ext4: read 8 jobs 2162, 24 jobs 5377, write 8 jobs 1859
> 
> One job, same columns. QD1 as kIOPS / us per request (1 / IOPS) / p99 us,
> QD32 as kIOPS / p99 us:
> 
>    read,  QD1       80 / 12.5 / 11   87 / 11.5 / 11   105 /  9.5 /  8
>    write, QD1       78 / 12.8 / 11   83 / 12.0 / 11    99 / 10.1 /  9
>    read,  QD32         258 / 171        320 / 114         359 / 102
>    write, QD32         256 / 167        304 / 129         339 / 107
> 
>    raw file: QD1 read 3.5 us, write 3.8 us per request
> 
> Tested on hci-8.2 (26.4) in a VM: ploop-pytest for the qcow2 and ploop
> formats, data verification under concurrent read/write/discard. The
> same checks passed on hci-8.1.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-95494
> 
> [1] http://lore.virtuozzo.com/kernel/20261113111126.793039-1-andrey.zhadchenko@virtuozzo.com/
> 
> Denis V. Lunev (9):
>    dm-qcow2: move md_pages_lock off the deferred_lock cache line
>    dm-qcow2: free md pages after an RCU grace period
>    dm-qcow2: map fast path reads without md_pages_lock
>    dm-qcow2: map fast path writes without md_pages_lock
>    dm-qcow2: submit fast path qios without deferred_lock
>    dm-rq: complete dm-qcow2 requests directly in task context
>    dm-qcow2: requeue requests when the request pool is empty
>    dm-ploop: requeue requests when the request pool is empty
>    dm: default dm-qcow2 devices to no I/O scheduler
> 
>   drivers/md/dm-ploop-map.c     |   2 +-
>   drivers/md/dm-ploop.h         |   3 +-
>   drivers/md/dm-qcow2-cmd.c     |  10 +-
>   drivers/md/dm-qcow2-map.c     | 182 ++++++++++++++++++++++++++++------
>   drivers/md/dm-qcow2-target.c  |  43 ++++++--
>   drivers/md/dm-qcow2.h         |  33 +++++-
>   drivers/md/dm-rq.c            |  22 ++++
>   drivers/md/dm-rq.h            |   1 +
>   drivers/md/dm-zero-rq.c       |   2 +-
>   include/linux/device-mapper.h |   5 +
>   10 files changed, 260 insertions(+), 43 deletions(-)
> 

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 1/9] dm-qcow2: move md_pages_lock off the deferred_lock cache line
  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
  0 siblings, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:05 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> Every request submitted to the device takes deferred_lock in
> qcow2_submit_embedded_qio(), and every metadata parse takes
> md_pages_lock in parse_metadata(). With the fast path both run on all
> submitting CPUs at once. The two locks share a cache line, so each
> one's traffic bounces the line under the other one's holders, and the
> cost grows with the number of submitting CPUs.
> 
> Give md_pages_lock a cache line of its own and keep each lock next to
> the lists it protects: the qio queues with deferred_lock, the discard
> wait list and the writeback batch lists with md_pages_lock.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=1


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 2/9] dm-qcow2: free md pages after an RCU grace period
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:06 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> Metadata lookups are going to walk the md_pages tree without
> md_pages_lock. Such a walk may still be on a node that is erased and
> freed at the same time, e.g. by do_md_page_read_complete() on a failed
> read.
> 
> Free md pages from an RCU callback and link new nodes with
> rb_link_node_rcu(), so a lookup under rcu_read_lock() never touches
> freed memory. rb_find_rcu() tolerates concurrent rotations with a
> false negative at worst. The rotations of rb_insert_color() may store
> a pointer to the new node again, so order its initialization before
> them too. Wait for pending callbacks with rcu_barrier() on module
> exit.
> 
> qcow2_md_page_renumber() erases and relinks a node in place without a
> grace period. A walker on it can only miss, and it only moves R1
> pages, which lockless lookups never accept.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=2


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 3/9] dm-qcow2: map fast path reads without md_pages_lock
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:17 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> Every fast path read takes md_pages_lock in parse_metadata() to look
> up the L1 and L2 pages and read their entries. The lock is global for
> the device, so reads from all submitting CPUs serialize on it, and
> adding submitters makes each read more expensive instead of adding
> throughput.
> 
> Map the common read without the lock: both pages cached and clean, no
> index of them locked, and the cluster mapped exactly once, not
> compressed and not all-zeroes. Anything else falls back to the locked
> parse. The pages are found with rb_find_rcu(), which the RCU freeing
> of md pages makes safe. L1 and L2 pages stay cached once they are
> uptodate, so the pointers stay valid after rcu_read_unlock() as they
> do after the lock.
> [ ... ]
> reused cluster. That race is VSTOR-154939, accepted as Won't Fix.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=3


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes without md_pages_lock
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:25 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> Fast path writes still take md_pages_lock in parse_metadata() to map
> the cluster and count themselves in the L2 page's active_writers. With
> reads off the lock it is the remaining global serialization point for
> an overwrite workload.
> 
> Map plain writes of allocated clusters through
> parse_metadata_lockless() too, then count the write and recheck the
> L2 page's md->gen. A discard that unmaps the cluster locks its index,
> which bumps md->gen, long before it waits for writers in
> delay_discard_if_writers(). With a full barrier on both sides, either
> the write sees the new md->gen, uncounts itself and takes the locked
> path, or the discard sees the count and waits for the write to finish
> before the cluster can be reused. The barrier is taken on entry, so a
> discard that re-enters to recheck the generation it waits for is
> covered as well.
> 
> The write reads md->writer_gen without the lock. If it reads the
> generation the discard has just switched to, the switch comes after
> the md->gen bump and the discard's barrier, so the write's recheck
> sees the bump and backs off. If it reads the old one, the discard
> waits for it as for any earlier write.
> 
> Discards and write-zeroes keep the locked parse.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=4


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock
  2026-11-25  1:25 ` [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock Denis V. Lunev
@ 2026-12-01  0:27   ` no-reply
  0 siblings, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:27 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=5


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:35 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dm-rq: dm_complete_request_direct() gates inline completion
  on in_task(), not preemptible()
--

commit 6b8fa61333058b203793f7fad936707219ef0649
Author: Denis V. Lunev <den@openvz.org>

dm-rq: complete dm-qcow2 requests directly in task context

This adds dm_complete_request_direct(). In task context it runs dm_softirq_done() inline through blk_mq_complete_request_direct(). It otherwise falls back to blk_mq_complete_request(). dm-qcow2's qrq_endio() now uses it.

https://virtuozzo.atlassian.net/browse/VSTOR-95494

> 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);

[Severity: Medium]
Is in_task() a strong enough condition for running the original request's end_io inline here?

in_task() stays true while a spinlock is held, with preemption or BH disabled, and inside an RCU read-side section. Before this patch, blk_mq_complete_request() never ran the end_io on the caller's stack in those contexts.

dm-qcow2 itself looks safe. qrq_endio() is only reached after the target has dropped its locks, or from workqueues. The problem is on the lower-layer side. qcow2_aio_complete() is the ki_complete callback for the backing file. qcow2_call_rw_iter() also calls it synchronously. The target can't tell what context the lower layer completes the kiocb in.

If a lower layer completes in task context with a lock, preemption or RCU held, the end_io now runs there. That could cause a self-deadlock, a sleep in atomic context, or deep stack recursion.

blk_mq_complete_request_direct() is meant for preemptible callers. Would it be better to also require preemptible(), which implies !irqs_disabled(), or to take an explicit flag from the caller as scsi_done_direct() does?

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=6

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 7/9] dm-qcow2: requeue requests when the request pool is empty
  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
  0 siblings, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:37 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dm-qcow2: bug-fix commit lacks a Fixes: trailer
- [Low] dm-qcow2: commit message and comment misdescribe QRQ pool sizing
--

commit a330f95d960153bb6811c7c36e6af96c4873e137
Author: Denis V. Lunev <den@openvz.org>

dm-qcow2: requeue requests when the request pool is empty

The commit makes qcow2_clone_and_map() return DM_MAPIO_REQUEUE instead of
DM_MAPIO_KILL when mempool_alloc(GFP_ATOMIC) fails. It also replaces the
comment on QCOW2_QRQ_POOL_SIZE.

> The request pool was sized at twice mq-deadline's default nr_requests
> of 2 * min(depth, BLKDEV_DEFAULT_RQ). With the default single hardware
> queue, even a request from every tag could not exhaust the reserve.
>
> Without a scheduler the device has dm_mq_queue_depth tags per hardware
> queue. If GFP_ATOMIC slab allocation fails with more requests in flight
> than the reserve can cover, qcow2_clone_and_map() kills the next request
> and the guest gets an I/O error. Return DM_MAPIO_REQUEUE so blk-mq
> applies backpressure and retries the request when resources free up.
>
> 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>

[Severity: Low]
This fixes a spurious I/O error on allocation failure, so should it carry:

  Fixes: 2a728299abdb ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")

> diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
> --- a/drivers/md/dm-qcow2.h
> +++ b/drivers/md/dm-qcow2.h
> @@ -193,7 +193,8 @@ struct qcow2_backward_merge {
>  
>  struct qcow2_target {
>  	struct dm_target *ti;
> -#define QCOW2_QRQ_POOL_SIZE 512 /* Twice nr_requests from blk_mq_init_sched() */
> +/* Reserve to keep requests moving when slab allocations fail. */
> +#define QCOW2_QRQ_POOL_SIZE 512
>  	mempool_t *qrq_pool;
>  	mempool_t *qio_pool;

[Severity: Low]
This isn't a functional problem, but are the first paragraph of the commit
message and this comment accurate about the pool sizing?

The pool was not "sized" this way by this patch, since QCOW2_QRQ_POOL_SIZE
stays at 512. The claim that the reserve cannot be exhausted holds only
with mq-deadline, where nr_requests is 2 * min(2048, 128) = 256. Without a
scheduler, DM_MQ_QUEUE_DEPTH is 2048 tags, which is more than 512. The
series makes no-scheduler the default (dm: default dm-qcow2 devices to no
I/O scheduler), so the first paragraph describes a configuration that no
longer applies. It also reads as if the pool can never run dry, which
contradicts the second paragraph.

The old comment explaining why 512 was chosen is removed, and the new one
gives no sizing rationale. Could the message and comment say that 512 is
not enough to cover all tags without a scheduler, and that the requeue
path handles that case?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=7

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 8/9] dm-ploop: requeue requests when the request pool is empty
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:38 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> The next commit disables the default I/O scheduler for devices that
> ploop_dmcreate_stub() creates with a zero-rq table. Loading a ploop
> table later keeps that scheduler setting, so the device can have more
> requests in flight than the 512-entry reserve sized for mq-deadline.
> 
> If the reserve is empty and GFP_ATOMIC allocation fails,
> ploop_clone_and_map() kills the request with an I/O error. Requeue it
> so blk-mq retries when resources are available.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-95494
> Feature: dm-ploop: ploop target driver
> Signed-off-by: Denis V. Lunev <den@openvz.org>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=8


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Devel] [PATCH hci-8.2 9/9] dm: default dm-qcow2 devices to no I/O scheduler
  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
  1 sibling, 0 replies; 27+ messages in thread
From: no-reply @ 2026-12-01  0:39 UTC (permalink / raw)
  To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
  Cc: devel

> From: Denis V. Lunev <den@openvz.org>
> 
> Request-based dm has one hardware queue by default, so it gets
> mq-deadline. On that queue mq-deadline caps requests in flight at 256
> by default (2 * min(depth, BLKDEV_DEFAULT_RQ)) and serialises insert
> and dispatch on its lock. The cost grows with queue depth and the
> number of submitters. Sorting by device sector buys little for dm-qcow2
> because adjacent guest sectors can be far apart in the image, and the
> backing device can schedule the image I/O itself.
> 
> Set DM_TARGET_NO_SCHED_BY_DEFAULT on dm-qcow2. When the target in the
> initial request-based table has this flag, dm_mq_init_request_queue()
> sets BLK_MQ_F_NO_SCHED_BY_DEFAULT, as loop does, so elevator_set_default()
> leaves the device with none.
> 
> mq-deadline arbitrates between I/O priority classes at dispatch. With
> none, the dm device loses that arbitration. dm-qcow2 issues image I/O
> from its workers, so the request's priority class does not reach the
> backing device either. mq-deadline can still be selected through sysfs.
> 
> libploop creates qcow2 devices and ploop_dmcreate_stub() devices with a
> zero-rq table and loads the real table later. Set the flag on zero-rq
> as well because the scheduler is chosen when the device is created.
> 
> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=9


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2026-12-01  0:41 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock Denis V. Lunev
2026-12-01  0:27   ` 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

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.