All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes
@ 2026-11-12 11:12 Andrey Zhadchenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Andrey Zhadchenko @ 2026-11-12 11:12 UTC (permalink / raw)
  To: khorenko, alexander.ivanov; +Cc: devel

A discard unmapping a cluster locks its L2 index, so requests coming
later wait until the discard is finished. But a data write, which has
resolved the index before it was locked, may still be in flight when
the discard drops the cluster refcount in process_indexes_end(). If
the cluster is allocated again before this write lands, the write
corrupts the data or the metadata of the new owner.

Make such a discard wait for these writes before the cluster is freed:

Patch 1 counts in-flight data writes per L2 page in two generations.
Nobody reads the counters yet, so there is no functional change.

Patch 2 is the fix. The discard switches the generation of its L2 page
and waits for the previous one to drain right before the refcount is
dropped. Writes submitted after the switch are counted separately, so
the wait is bounded by the writes already in flight.

Patch 3 is an optimisation. Discards of clusters mapped by one L2 page
usually come to process_indexes_end() in one batch. Let them wait for
the same generation together instead of one by one.

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

Andrey Zhadchenko (3):
  dm-qcow2: count in-flight data writes per L2 page
  dm-qcow2: wait for in-flight writes before freeing a discarded cluster
  dm-qcow2: let discards of one L2 page wait for in-flight writes
    together

 drivers/md/dm-qcow2-map.c    | 118 +++++++++++++++++++++++++++++++++++
 drivers/md/dm-qcow2-target.c |   6 ++
 drivers/md/dm-qcow2.h        |  12 ++++
 3 files changed, 136 insertions(+)

-- 
2.43.5

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

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

* [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
@ 2026-11-12 11:12 ` Andrey Zhadchenko
  2026-11-12 11:22   ` no-reply
  2026-11-12 18:59   ` Konstantin Khorenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster Andrey Zhadchenko
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 14+ messages in thread
From: Andrey Zhadchenko @ 2026-11-12 11:12 UTC (permalink / raw)
  To: khorenko, alexander.ivanov; +Cc: devel

A discard, which frees a cluster, has to know when data writes
submitted to the cluster earlier are completed. Nothing tracks them
now: a write goes from perform_rw_mapped() straight to the image file
and is not linked to anything a discard could wait for.

Count every data write submitted from perform_rw_mapped() in the L2
page mapping its cluster, from submission till completion. The counter
is split in two generations and a write is counted in the current one.
This allows the next patch to switch the generation and to wait for the
previous one to drain without being starved by new writes.

The counting is done from the main work only, so the generation is
stable there and no lock is needed.

No functional change: nobody switches the generation or waits for the
counters yet.

https://virtuozzo.atlassian.net/browse/VSTOR-154659
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c    | 22 ++++++++++++++++++++++
 drivers/md/dm-qcow2-target.c |  3 +++
 drivers/md/dm-qcow2.h        |  8 ++++++++
 3 files changed, 33 insertions(+)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 34d9d9810f601..2c0e7bdb251dc 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -368,10 +368,12 @@ void qcow2_init_qio(struct qio *qio, unsigned int bi_op, struct qcow2 *qcow2)
 	qio->queue_list_id = QLIST_DEFERRED;
 	qio->ext = NULL;
 	qio->data = NULL;
+	qio->writer_md = NULL;
 	qio->bi_op = bi_op;
 	qio->bi_io_vec = NULL;
 	qio->flags = 0;
 	qio->ref_index = REF_INDEX_INVALID;
+	qio->writer_gen = 0;
 	atomic_set(&qio->remaining, 1);
 
 	/*
@@ -613,6 +615,21 @@ static bool delay_if_has_wpc_readers(struct qcow2 *qcow2, struct md_page *md,
 	return ret;
 }
 
+static void inc_writers(struct md_page *md, struct qio *qio)
+{
+	qio->writer_md = md;
+	qio->writer_gen = md->writer_gen;
+	atomic_inc(&md->active_writers[qio->writer_gen]);
+}
+
+static void dec_writers(struct qio *qio)
+{
+	struct md_page *md = qio->writer_md;
+
+	qio->writer_md = NULL;
+	atomic_dec(&md->active_writers[qio->writer_gen]);
+}
+
 static u32 calc_cow_mask(struct qcow2 *qcow2, u64 ext_l2,
 			 struct qio *qio, bool wants_backing,
 			 bool wants_data, bool wants_zeroes)
@@ -2863,6 +2880,9 @@ static void data_rw_complete(struct qio *qio)
 		bi_status = errno_to_blk_status(qio->ret);
 	}
 
+	if (qio->writer_md)
+		dec_writers(qio);
+
 	wbd = qio->data;
 	if (wbd) {
 		WARN_ON_ONCE(!write);
@@ -2919,6 +2939,8 @@ static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
 		qio->data = md->wbd;
 		spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
 	}
+	if (rw == WRITE)
+		inc_writers(md, qio);
 
 	map_and_submit_rw(qcow2, map->data_clu_pos, qio);
 }
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 8337efc5c6238..07ca928002e0a 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -399,6 +399,9 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
 	(*md)->lockd = NULL;
 	atomic_set(&(*md)->wpc_readers, 0);
 	(*md)->wpc_noread_count = 0;
+	(*md)->writer_gen = 0;
+	atomic_set(&(*md)->active_writers[0], 0);
+	atomic_set(&(*md)->active_writers[1], 0);
 	INIT_LIST_HEAD(&(*md)->wait_list);
 	INIT_LIST_HEAD(&(*md)->wpc_readers_wait_list);
 	INIT_LIST_HEAD(&(*md)->wb_link);
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index ad5286b16883e..5755788e0e5ae 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -135,6 +135,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;
+	u8 writer_gen;
 	struct page *page;
 	struct list_head wait_list;
 	/* To link in qcow2::{,slow}wb_batch_list and qcow2::QLIST_COMPLETED_WB */
@@ -148,6 +149,11 @@ struct md_page {
 	atomic_t wpc_readers;
 	int wpc_noread_count; /* Read is prohibited, if positive */
 	struct list_head wpc_readers_wait_list;
+	/*
+	 * Data writes in flight to clusters mapped by this L2 page, split
+	 * in two generations. New writes are counted in writer_gen one.
+	 */
+	atomic_t active_writers[2];
 };
 
 enum qcow2_backward_merge_state {
@@ -357,6 +363,7 @@ struct qio {
 	 * bio processing should resume.
 	 */
 	u8 queue_list_id:4;
+	u8 writer_gen:1;
 
 	atomic_t remaining;
 
@@ -365,6 +372,7 @@ struct qio {
 	int ret; /* iocb result */
 	void (*complete)(struct qio *me);
 	void *data;
+	struct md_page *writer_md;
 	/* Some operations (COW) require special destruction or requeue */
 	struct qio_ext *ext;
 	struct list_head link;
-- 
2.43.5

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

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

* [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
@ 2026-11-12 11:12 ` Andrey Zhadchenko
  2026-11-12 11:26   ` no-reply
  2026-11-12 18:59   ` Konstantin Khorenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together Andrey Zhadchenko
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 14+ messages in thread
From: Andrey Zhadchenko @ 2026-11-12 11:12 UTC (permalink / raw)
  To: khorenko, alexander.ivanov; +Cc: devel

A discard unmapping a cluster locks its L2 index, punches the cluster,
clears the index and, after the L2 writeback, drops the cluster
refcount in process_indexes_end(), which makes the cluster reusable.
A data write submitted to the cluster before the index was locked may
still be in flight at that moment. If it lands after the cluster is
allocated again, it corrupts the data or the metadata of the new owner.

Make such a discard wait in process_indexes_end() until the writes
counted in its L2 page are completed, right before the refcount is
dropped. The discard switches the generation of the page, so writes
submitted later are counted separately, and waits for the previous
generation to drain. Writes submitted after the index is locked can't
refer the cluster, so there is no need to wait for them.

Only one discard at a time switches the generation of a page, others
wait for it to finish first. Otherwise a second switch would return
new writes to the generation the first discard waits for, and the
last of them would complete without waking it.

The hole punch in issue_discard() is not delayed: a write landing
into the cluster between the punch and the reuse is harmless, since
allocate_cluster() punches a reused cluster again.

Clusters shared with snapshots and compressed clusters are never
written directly, so discards of them do not wait.

https://virtuozzo.atlassian.net/browse/VSTOR-154659
Fixes: 6e1c3e5a91fd ("drivers/md/dm-qcow2: update metadata on whole cluster discard")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c    | 83 +++++++++++++++++++++++++++++++++++-
 drivers/md/dm-qcow2-target.c |  3 ++
 drivers/md/dm-qcow2.h        |  6 ++-
 3 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 2c0e7bdb251dc..b07747f80030f 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -622,12 +622,87 @@ static void inc_writers(struct md_page *md, struct qio *qio)
 	atomic_inc(&md->active_writers[qio->writer_gen]);
 }
 
+static void discard_waiters_to_list(struct qcow2 *qcow2, struct md_page *md,
+				    struct list_head *list)
+{
+	struct qio *discard, *tmp;
+
+	lockdep_assert_held(&qcow2->md_pages_lock);
+	list_for_each_entry_safe(discard, tmp, &qcow2->discard_wait_list, link) {
+		if (discard->ext->lx_md == md)
+			list_move_tail(&discard->link, list);
+	}
+}
+
 static void dec_writers(struct qio *qio)
 {
 	struct md_page *md = qio->writer_md;
+	struct qcow2 *qcow2 = qio->qcow2;
+	u8 gen = qio->writer_gen;
+	LIST_HEAD(wait_list);
+	unsigned long flags;
 
 	qio->writer_md = NULL;
-	atomic_dec(&md->active_writers[qio->writer_gen]);
+	/*
+	 * Fully ordered RMW pairs with smp_mb() in delay_discard_if_writers():
+	 * either we see switched generation, or the discard sees our put.
+	 * The generation can't be switched back to ours while a discard
+	 * waits for it, so the same generation means nobody is to wake.
+	 */
+	if (atomic_dec_return(&md->active_writers[gen]) ||
+	    READ_ONCE(md->writer_gen) == gen)
+		return;
+
+	spin_lock_irqsave(&qcow2->md_pages_lock, flags);
+	discard_waiters_to_list(qcow2, md, &wait_list);
+	spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
+	qcow2_dispatch_qios(qcow2, NULL, &wait_list);
+}
+
+static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md,
+				     struct qio *qio)
+{
+	LIST_HEAD(wake_list);
+	bool ret = false;
+	u8 gen;
+
+	spin_lock_irq(&qcow2->md_pages_lock);
+	if (qio->flags & QIO_DISCARD_WAIT_FL) {
+		if (atomic_read(&md->active_writers[qio->writer_gen]))
+			goto delay;
+		qio->flags &= ~QIO_DISCARD_WAIT_FL;
+		md->gen_switched = false;
+		discard_waiters_to_list(qcow2, md, &wake_list);
+		goto unlock;
+	}
+
+	/* another discard already waits: we can't switch without breaking it */
+	if (md->gen_switched)
+		goto delay;
+
+	/*
+	 * 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 (!atomic_read(&md->active_writers[gen]))
+		goto unlock;
+
+	WRITE_ONCE(md->writer_gen, !gen);
+	smp_mb(); /* Pairs with atomic_dec_return() in dec_writers() */
+	if (!atomic_read(&md->active_writers[gen]))
+		goto unlock;
+
+	md->gen_switched = true;
+	qio->writer_gen = gen;
+	qio->flags |= QIO_DISCARD_WAIT_FL;
+delay:
+	list_add_tail(&qio->link, &qcow2->discard_wait_list);
+	ret = true;
+unlock:
+	spin_unlock_irq(&qcow2->md_pages_lock);
+	qcow2_dispatch_qios(qcow2, NULL, &wake_list);
+	return ret;
 }
 
 static u32 calc_cow_mask(struct qcow2 *qcow2, u64 ext_l2,
@@ -3547,6 +3622,9 @@ static int prepare_cluster_discard(struct qcow2 *qcow2, struct qio **qio,
 		ext->only_set_ext_l2 = true;
 	else if (zeroes && !qcow2->ext_l2)
 		ext->set_all_zeroes = true;
+	/* wait only if the cluster can be reused later */
+	if (unmap && !map->clu_is_cow)
+		ext->wait_writers = true;
 
 	(*qio)->flags |= QIO_IS_DISCARD_FL;
 	return 1;
@@ -4294,6 +4372,9 @@ next:		qio = qio_list_pop(qio_list);
 		 */
 		if (delay_if_has_wpc_readers(qcow2, ext->lx_md, &qio))
 			goto next;
+		if (ext->wait_writers &&
+		    delay_discard_if_writers(qcow2, ext->lx_md, qio))
+			goto next;
 
 		pos = ext->unuse_clu_pos;
 		for (; pos < ext->unuse_clu_end; pos += clu_size) {
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 07ca928002e0a..24a42c5a66759 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -228,6 +228,7 @@ void qcow2_destroy(struct qcow2 *qcow2)
 		     "qcow2: list %d is not empty", i);
 
 	WARN_ON(!list_empty(&qcow2->paused_qios) ||
+		!list_empty(&qcow2->discard_wait_list) ||
 		!list_empty(&qcow2->wb_batch_list) ||
 		!list_empty(&qcow2->slow_wb_batch_list) ||
 		timer_pending(&qcow2->slow_wb_timer));
@@ -400,6 +401,7 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
 	atomic_set(&(*md)->wpc_readers, 0);
 	(*md)->wpc_noread_count = 0;
 	(*md)->writer_gen = 0;
+	(*md)->gen_switched = false;
 	atomic_set(&(*md)->active_writers[0], 0);
 	atomic_set(&(*md)->active_writers[1], 0);
 	INIT_LIST_HEAD(&(*md)->wait_list);
@@ -666,6 +668,7 @@ static struct qcow2 *qcow2_alloc_delta(struct qcow2_target *tgt, struct qcow2 *u
 		INIT_LIST_HEAD(&qcow2->qios[i]);
 	INIT_LIST_HEAD(&qcow2->resubmit_qios);
 	INIT_LIST_HEAD(&qcow2->paused_qios);
+	INIT_LIST_HEAD(&qcow2->discard_wait_list);
 	INIT_LIST_HEAD(&qcow2->wb_batch_list);
 	INIT_LIST_HEAD(&qcow2->slow_wb_batch_list);
 	spin_lock_init(&qcow2->deferred_lock);
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 5755788e0e5ae..8eb0c49f1e4eb 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -136,6 +136,7 @@ struct md_page {
 #define MD_WRITEBACK_ERROR (1U << 3) /* Last writeback failed with error */
 	unsigned int status;
 	u8 writer_gen;
+	bool gen_switched;
 	struct page *page;
 	struct list_head wait_list;
 	/* To link in qcow2::{,slow}wb_batch_list and qcow2::QLIST_COMPLETED_WB */
@@ -280,6 +281,7 @@ struct qcow2 {
 	struct list_head qios[QLIST_COUNT];
 	struct list_head resubmit_qios;
 	struct list_head paused_qios; /* For pause_submitting_qios */
+	struct list_head discard_wait_list;
 
 	/* For batching md update: */
 	struct list_head wb_batch_list;
@@ -321,6 +323,7 @@ struct qio_ext {
 	u32 cow_mask;
 	bool only_set_ext_l2:1;
 	bool set_all_zeroes:1;
+	bool wait_writers:1;
 
 	u8 lx_level;
 
@@ -351,6 +354,7 @@ struct qio {
 #define QIO_IS_MERGE_FL		(1 << 3) /* This is service merge qio */
 #define QIO_IS_DISCARD_FL	(1 << 4) /* This zeroes index (discard or backward merge) */
 #define QIO_IS_L1COW_FL		(1 << 5) /* This qio only wants COW at L1 */
+#define QIO_DISCARD_WAIT_FL	(1 << 6) /* Discard waits writer_gen drain */
 #define QIO_SPLIT_INHERITED_FLAGS (QIO_IS_DISCARD_FL)
 	u8 flags;
 #define REF_INDEX_INVALID 2
@@ -363,7 +367,7 @@ struct qio {
 	 * bio processing should resume.
 	 */
 	u8 queue_list_id:4;
-	u8 writer_gen:1;
+	u8 writer_gen:1; /* for discard this is the generation it waits */
 
 	atomic_t remaining;
 
-- 
2.43.5

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

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

* [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster Andrey Zhadchenko
@ 2026-11-12 11:12 ` Andrey Zhadchenko
  2026-11-12 11:24   ` no-reply
  2026-11-12 18:59   ` Konstantin Khorenko
  2026-11-12 12:40 ` [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Alexander Ivanov
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 14+ messages in thread
From: Andrey Zhadchenko @ 2026-11-12 11:12 UTC (permalink / raw)
  To: khorenko, alexander.ivanov; +Cc: devel

Only one discard at a time switches the generation of an L2 page and
waits for the previous one to drain. Others queue behind it and then
do the same one by one, so N discards of clusters mapped by one L2
page take N drain cycles under write load. This is the common case:
discards updating the same L2 page complete its writeback together
and come to process_indexes_end() in one batch.

A discard, which finds a switch in progress while no write is counted
in the new generation yet, has exactly the same writes to wait for as
the discard which switched. Let it join: wait for the same previous
generation instead of queueing for its own switch. If that generation
is already empty, nothing is in flight and the discard goes on
immediately.

Count the discards waiting for the previous generation instead of
keeping a flag, and allow the next switch when the last of them is
released.

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

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index b07747f80030f..21f2d34ca371f 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -671,20 +671,34 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md,
 		if (atomic_read(&md->active_writers[qio->writer_gen]))
 			goto delay;
 		qio->flags &= ~QIO_DISCARD_WAIT_FL;
-		md->gen_switched = false;
-		discard_waiters_to_list(qcow2, md, &wake_list);
+		if (!--md->discard_waiters)
+			discard_waiters_to_list(qcow2, md, &wake_list);
 		goto unlock;
 	}
 
-	/* another discard already waits: we can't switch without breaking it */
-	if (md->gen_switched)
-		goto delay;
-
 	/*
 	 * 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) {
+		/*
+		 * New writes since previous switch and another discard
+		 * already waits: do not break it and delay
+		 */
+		if (atomic_read(&md->active_writers[gen]))
+			goto delay;
+
+		gen = !gen;
+		/*
+		 * No new writes and previous writes just completed
+		 * but waiters haven't been processed yet: proceed
+		 */
+		if (!atomic_read(&md->active_writers[gen]))
+			goto unlock;
+		goto wait;
+	}
+
 	if (!atomic_read(&md->active_writers[gen]))
 		goto unlock;
 
@@ -693,7 +707,8 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md,
 	if (!atomic_read(&md->active_writers[gen]))
 		goto unlock;
 
-	md->gen_switched = true;
+wait:
+	md->discard_waiters++;
 	qio->writer_gen = gen;
 	qio->flags |= QIO_DISCARD_WAIT_FL;
 delay:
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 24a42c5a66759..3cdd1ec2aab4b 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -401,7 +401,7 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
 	atomic_set(&(*md)->wpc_readers, 0);
 	(*md)->wpc_noread_count = 0;
 	(*md)->writer_gen = 0;
-	(*md)->gen_switched = false;
+	(*md)->discard_waiters = 0;
 	atomic_set(&(*md)->active_writers[0], 0);
 	atomic_set(&(*md)->active_writers[1], 0);
 	INIT_LIST_HEAD(&(*md)->wait_list);
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 8eb0c49f1e4eb..1e1eb9e4daef0 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -136,7 +136,7 @@ struct md_page {
 #define MD_WRITEBACK_ERROR (1U << 3) /* Last writeback failed with error */
 	unsigned int status;
 	u8 writer_gen;
-	bool gen_switched;
+	u16 discard_waiters;
 	struct page *page;
 	struct list_head wait_list;
 	/* To link in qcow2::{,slow}wb_batch_list and qcow2::QLIST_COMPLETED_WB */
-- 
2.43.5

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

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

* Re: [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
@ 2026-11-12 11:22   ` no-reply
  2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 0 replies; 14+ messages in thread
From: no-reply @ 2026-11-12 11:22 UTC (permalink / raw)
  To: Andrey Zhadchenko, khorenko, alexander.ivanov; +Cc: devel

> A discard, which frees a cluster, has to know when data writes
> submitted to the cluster earlier are completed. Nothing tracks them
> now: a write goes from perform_rw_mapped() straight to the image file
> and is not linked to anything a discard could wait for.
> 
> Count every data write submitted from perform_rw_mapped() in the L2
> page mapping its cluster, from submission till completion. The counter
> is split in two generations and a write is counted in the current one.
> This allows the next patch to switch the generation and to wait for the
> previous one to drain without being starved by new writes.
> 
> The counting is done from the main work only, so the generation is
> stable there and no lock is needed.
> 
> No functional change: nobody switches the generation or waits for the
> counters yet.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-154659
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112111205.736027-1-andrey.zhadchenko@virtuozzo.com?part=1


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

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

* Re: [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together Andrey Zhadchenko
@ 2026-11-12 11:24   ` no-reply
  2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 0 replies; 14+ messages in thread
From: no-reply @ 2026-11-12 11:24 UTC (permalink / raw)
  To: khorenko, alexander.ivanov, Andrey Zhadchenko; +Cc: devel

> Only one discard at a time switches the generation of an L2 page and
> waits for the previous one to drain. Others queue behind it and then
> do the same one by one, so N discards of clusters mapped by one L2
> page take N drain cycles under write load. This is the common case:
> discards updating the same L2 page complete its writeback together
> and come to process_indexes_end() in one batch.
> 
> A discard, which finds a switch in progress while no write is counted
> in the new generation yet, has exactly the same writes to wait for as
> the discard which switched. Let it join: wait for the same previous
> generation instead of queueing for its own switch. If that generation
> is already empty, nothing is in flight and the discard goes on
> immediately.
> 
> Count the discards waiting for the previous generation instead of
> keeping a flag, and allow the next switch when the last of them is
> released.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-154659
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112111205.736027-1-andrey.zhadchenko@virtuozzo.com?part=3


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

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

* Re: [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster Andrey Zhadchenko
@ 2026-11-12 11:26   ` no-reply
  2026-11-12 11:47     ` Andrey Zhadchenko
  2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 1 reply; 14+ messages in thread
From: no-reply @ 2026-11-12 11:26 UTC (permalink / raw)
  To: Andrey Zhadchenko, alexander.ivanov, khorenko; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dm-qcow2: dec_writers() scans whole qcow2-wide discard_wait_list under irq-off lock
--

commit 8c3ab12e988e2b5f6106aa1b1403344b45fba8ab
Author: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

dm-qcow2: wait for in-flight writes before freeing a discarded cluster

This patch makes a discard that unmaps a non-shared cluster wait in
process_indexes_end() until the data writes counted in its L2 page have
completed. The discard switches the writer generation of the page and
waits for the previous generation to drain. A per-qcow2 discard_wait_list
holds the delayed discards, and dec_writers() wakes them.

> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c

[ ... ]

> +static void discard_waiters_to_list(struct qcow2 *qcow2, struct md_page *md,
> +				    struct list_head *list)
> +{
> +	struct qio *discard, *tmp;
> +
> +	lockdep_assert_held(&qcow2->md_pages_lock);
> +	list_for_each_entry_safe(discard, tmp, &qcow2->discard_wait_list, link) {
> +		if (discard->ext->lx_md == md)
> +			list_move_tail(&discard->link, list);
> +	}
> +}
> +
>  static void dec_writers(struct qio *qio)
>  {
>  	struct md_page *md = qio->writer_md;
> +	struct qcow2 *qcow2 = qio->qcow2;
> +	u8 gen = qio->writer_gen;
> +	LIST_HEAD(wait_list);
> +	unsigned long flags;
>  
>  	qio->writer_md = NULL;
> -	atomic_dec(&md->active_writers[qio->writer_gen]);
> +	/*
> +	 * Fully ordered RMW pairs with smp_mb() in delay_discard_if_writers():
> +	 * either we see switched generation, or the discard sees our put.
> +	 * The generation can't be switched back to ours while a discard
> +	 * waits for it, so the same generation means nobody is to wake.
> +	 */
> +	if (atomic_dec_return(&md->active_writers[gen]) ||
> +	    READ_ONCE(md->writer_gen) == gen)
> +		return;
> +
> +	spin_lock_irqsave(&qcow2->md_pages_lock, flags);
> +	discard_waiters_to_list(qcow2, md, &wait_list);
> +	spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
> +	qcow2_dispatch_qios(qcow2, NULL, &wait_list);
> +}

[Severity: Low]
Is it intended that dec_writers() scans the whole per-qcow2
discard_wait_list with irqs disabled?

When a discard switches md->writer_gen in delay_discard_if_writers() and
the last writer of the old generation completes, dec_writers() takes the
slow path:

dec_writers()
  spin_lock_irqsave(&qcow2->md_pages_lock, flags);
  discard_waiters_to_list(qcow2, md, &wait_list);

discard_waiters_to_list() walks the single qcow2-wide list and compares
discard->ext->lx_md with md, so the cost is proportional to all pending
discards on the qcow2 rather than to those on this md page.

It also moves every discard for that md, including ones that were only
delayed (no QIO_DISCARD_WAIT_FL set). Those re-run
delay_discard_if_writers() and may be delayed again, each costing an extra
qcow2_dispatch_qios() and worker pass.

This looks like a minor inefficiency rather than a correctness problem, and
the list is bounded by the number of in-flight discards. As far as I can
tell the later patch in the series ("dm-qcow2: let discards of one L2 page
wait for in-flight writes together") leaves dec_writers() unchanged, so the
wake is not narrowed there either.

Would a per-md list, or waking only the discard that holds
QIO_DISCARD_WAIT_FL, be worth considering?

[ ... ]

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112111205.736027-1-andrey.zhadchenko@virtuozzo.com?part=2

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

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

* Re: [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster
  2026-11-12 11:26   ` no-reply
@ 2026-11-12 11:47     ` Andrey Zhadchenko
  0 siblings, 0 replies; 14+ messages in thread
From: Andrey Zhadchenko @ 2026-11-12 11:47 UTC (permalink / raw)
  To: alexander.ivanov, khorenko; +Cc: devel

It is true but so far this is more like a premature optimization of low 
likelihood scenario that increases md memory footprint. In the worst 
case it is the guest that actively slows itself with parallel writes and 
discards. So no for now. Maybe we can consider this later when we add 
per-md locking

On 11/12/26 12:26, no-reply@sashiko.virtuozzo.com wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] dm-qcow2: dec_writers() scans whole qcow2-wide discard_wait_list under irq-off lock
> --
> 
> commit 8c3ab12e988e2b5f6106aa1b1403344b45fba8ab
> Author: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
> 
> dm-qcow2: wait for in-flight writes before freeing a discarded cluster
> 
> This patch makes a discard that unmaps a non-shared cluster wait in
> process_indexes_end() until the data writes counted in its L2 page have
> completed. The discard switches the writer generation of the page and
> waits for the previous generation to drain. A per-qcow2 discard_wait_list
> holds the delayed discards, and dec_writers() wakes them.
> 
>> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
>> --- a/drivers/md/dm-qcow2-map.c
>> +++ b/drivers/md/dm-qcow2-map.c
> 
> [ ... ]
> 
>> +static void discard_waiters_to_list(struct qcow2 *qcow2, struct md_page *md,
>> +				    struct list_head *list)
>> +{
>> +	struct qio *discard, *tmp;
>> +
>> +	lockdep_assert_held(&qcow2->md_pages_lock);
>> +	list_for_each_entry_safe(discard, tmp, &qcow2->discard_wait_list, link) {
>> +		if (discard->ext->lx_md == md)
>> +			list_move_tail(&discard->link, list);
>> +	}
>> +}
>> +
>>   static void dec_writers(struct qio *qio)
>>   {
>>   	struct md_page *md = qio->writer_md;
>> +	struct qcow2 *qcow2 = qio->qcow2;
>> +	u8 gen = qio->writer_gen;
>> +	LIST_HEAD(wait_list);
>> +	unsigned long flags;
>>   
>>   	qio->writer_md = NULL;
>> -	atomic_dec(&md->active_writers[qio->writer_gen]);
>> +	/*
>> +	 * Fully ordered RMW pairs with smp_mb() in delay_discard_if_writers():
>> +	 * either we see switched generation, or the discard sees our put.
>> +	 * The generation can't be switched back to ours while a discard
>> +	 * waits for it, so the same generation means nobody is to wake.
>> +	 */
>> +	if (atomic_dec_return(&md->active_writers[gen]) ||
>> +	    READ_ONCE(md->writer_gen) == gen)
>> +		return;
>> +
>> +	spin_lock_irqsave(&qcow2->md_pages_lock, flags);
>> +	discard_waiters_to_list(qcow2, md, &wait_list);
>> +	spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
>> +	qcow2_dispatch_qios(qcow2, NULL, &wait_list);
>> +}
> 
> [Severity: Low]
> Is it intended that dec_writers() scans the whole per-qcow2
> discard_wait_list with irqs disabled?
> 
> When a discard switches md->writer_gen in delay_discard_if_writers() and
> the last writer of the old generation completes, dec_writers() takes the
> slow path:
> 
> dec_writers()
>    spin_lock_irqsave(&qcow2->md_pages_lock, flags);
>    discard_waiters_to_list(qcow2, md, &wait_list);
> 
> discard_waiters_to_list() walks the single qcow2-wide list and compares
> discard->ext->lx_md with md, so the cost is proportional to all pending
> discards on the qcow2 rather than to those on this md page.
> 
> It also moves every discard for that md, including ones that were only
> delayed (no QIO_DISCARD_WAIT_FL set). Those re-run
> delay_discard_if_writers() and may be delayed again, each costing an extra
> qcow2_dispatch_qios() and worker pass.
> 
> This looks like a minor inefficiency rather than a correctness problem, and
> the list is bounded by the number of in-flight discards. As far as I can
> tell the later patch in the series ("dm-qcow2: let discards of one L2 page
> wait for in-flight writes together") leaves dec_writers() unchanged, so the
> wake is not narrowed there either.
> 
> Would a per-md list, or waking only the discard that holds
> QIO_DISCARD_WAIT_FL, be worth considering?
> 
> [ ... ]
> 

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

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

* Re: [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
                   ` (2 preceding siblings ...)
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together Andrey Zhadchenko
@ 2026-11-12 12:40 ` Alexander Ivanov
  2026-11-12 18:59 ` Konstantin Khorenko
  2026-11-12 19:00 ` Konstantin Khorenko
  5 siblings, 0 replies; 14+ messages in thread
From: Alexander Ivanov @ 2026-11-12 12:40 UTC (permalink / raw)
  To: Andrey Zhadchenko, khorenko; +Cc: devel

LGTM

Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

On 11/12/26 12:12, Andrey Zhadchenko wrote:
> A discard unmapping a cluster locks its L2 index, so requests coming
> later wait until the discard is finished. But a data write, which has
> resolved the index before it was locked, may still be in flight when
> the discard drops the cluster refcount in process_indexes_end(). If
> the cluster is allocated again before this write lands, the write
> corrupts the data or the metadata of the new owner.
>
> Make such a discard wait for these writes before the cluster is freed:
>
> Patch 1 counts in-flight data writes per L2 page in two generations.
> Nobody reads the counters yet, so there is no functional change.
>
> Patch 2 is the fix. The discard switches the generation of its L2 page
> and waits for the previous one to drain right before the refcount is
> dropped. Writes submitted after the switch are counted separately, so
> the wait is bounded by the writes already in flight.
>
> Patch 3 is an optimisation. Discards of clusters mapped by one L2 page
> usually come to process_indexes_end() in one batch. Let them wait for
> the same generation together instead of one by one.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-154659
>
> Andrey Zhadchenko (3):
>    dm-qcow2: count in-flight data writes per L2 page
>    dm-qcow2: wait for in-flight writes before freeing a discarded cluster
>    dm-qcow2: let discards of one L2 page wait for in-flight writes
>      together
>
>   drivers/md/dm-qcow2-map.c    | 118 +++++++++++++++++++++++++++++++++++
>   drivers/md/dm-qcow2-target.c |   6 ++
>   drivers/md/dm-qcow2.h        |  12 ++++
>   3 files changed, 136 insertions(+)
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

* Re: [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster Andrey Zhadchenko
  2026-11-12 11:26   ` no-reply
@ 2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 0 replies; 14+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 18:59 UTC (permalink / raw)
  To: Andrey Zhadchenko; +Cc: devel

Applying with these fixes on my side:
- "refer the cluster" -> "refer to the cluster".
- "of a page, others wait" -> "of a page; the others wait".

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
  2026-11-12 11:22   ` no-reply
@ 2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 0 replies; 14+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 18:59 UTC (permalink / raw)
  To: Andrey Zhadchenko; +Cc: devel

Applying with these fixes on my side:
- "The counting is done from the main work only" -> "The counters are
  increased from the main work only".

On Thu, 12 Nov 2026 14:12:03 +0300, Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com> wrote:
> The counting is done from the main work only, so the generation is
> stable there and no lock is needed.

The decrement runs from the aio completion, only the increment is in
the main work.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
                   ` (3 preceding siblings ...)
  2026-11-12 12:40 ` [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Alexander Ivanov
@ 2026-11-12 18:59 ` Konstantin Khorenko
  2026-11-12 19:00 ` Konstantin Khorenko
  5 siblings, 0 replies; 14+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 18:59 UTC (permalink / raw)
  To: Andrey Zhadchenko; +Cc: devel

Applying with these fixes on my side:
- patch 1: "The counting is done from the main work only" -> "The
  counters are increased from the main work only".
- patch 2: "refer the cluster" -> "refer to the cluster", and the
  comma splice "of a page, others wait" -> "of a page; the others
  wait".

On Thu, 12 Nov 2026 14:12:02 +0300, Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com> wrote:
> Make such a discard wait for these writes before the cluster is freed:

The code is right: every data write decrements exactly once, also on
error and on a resubmitted short write, and the generation switch
cannot lose the wakeup of the waiting discard.

Separate patches, not needed for this series; I created a task for
it:

1. Reads are not counted. A guest read resolved to the cluster before
   the discard locked the index can land after the cluster went to
   another LBA or to an L2 or refcount table, and return that content.
   It is older than this series (6e1c3e5a91fd). ext4 and xfs close the
   window, their hole punch waits for in-flight direct I/O, but
   fuse_file_fallocate() does not, so images on vstorage are exposed.
   https://virtuozzo.atlassian.net/browse/VSTOR-154939

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together
  2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together Andrey Zhadchenko
  2026-11-12 11:24   ` no-reply
@ 2026-11-12 18:59   ` Konstantin Khorenko
  1 sibling, 0 replies; 14+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 18:59 UTC (permalink / raw)
  To: Andrey Zhadchenko; +Cc: devel

Applying as is.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes
  2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
                   ` (4 preceding siblings ...)
  2026-11-12 18:59 ` Konstantin Khorenko
@ 2026-11-12 19:00 ` Konstantin Khorenko
  5 siblings, 0 replies; 14+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 19:00 UTC (permalink / raw)
  To: alexander.ivanov, Andrey Zhadchenko; +Cc: devel

On Thu, 12 Nov 2026 14:12:02 +0300, Andrey Zhadchenko wrote:
> dm-qcow2: do not free a discarded cluster under in-flight writes
> 
> A discard unmapping a cluster locks its L2 index, so requests coming
> later wait until the discard is finished. But a data write, which has
> resolved the index before it was locked, may still be in flight when
> the discard drops the cluster refcount in process_indexes_end(). If
> the cluster is allocated again before this write lands, the write
> corrupts the data or the metadata of the new owner.
> 
> [...]

Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.22.vz10, thanks!

[1/3] dm-qcow2: count in-flight data writes per L2 page
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b4dbaf6d1a44
[2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/93922731fc5d
[3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/48198d82491a

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


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

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

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

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 11:12 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Andrey Zhadchenko
2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: count in-flight data writes per L2 page Andrey Zhadchenko
2026-11-12 11:22   ` no-reply
2026-11-12 18:59   ` Konstantin Khorenko
2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: wait for in-flight writes before freeing a discarded cluster Andrey Zhadchenko
2026-11-12 11:26   ` no-reply
2026-11-12 11:47     ` Andrey Zhadchenko
2026-11-12 18:59   ` Konstantin Khorenko
2026-11-12 11:12 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: let discards of one L2 page wait for in-flight writes together Andrey Zhadchenko
2026-11-12 11:24   ` no-reply
2026-11-12 18:59   ` Konstantin Khorenko
2026-11-12 12:40 ` [Devel] [PATCH hci-8.1 0/3] dm-qcow2: do not free a discarded cluster under in-flight writes Alexander Ivanov
2026-11-12 18:59 ` Konstantin Khorenko
2026-11-12 19:00 ` Konstantin Khorenko

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.