From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: khorenko@virtuozzo.com, alexander.ivanov@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v3 3/8] dm-qcow2: count fast path writes in parse_metadata()
Date: Fri, 13 Nov 2026 14:11:21 +0300 [thread overview]
Message-ID: <20261113111126.793039-4-andrey.zhadchenko@virtuozzo.com> (raw)
In-Reply-To: <20261113111126.793039-1-andrey.zhadchenko@virtuozzo.com>
perform_rw_mapped() reads md->status and md->wbd without
md_pages_lock and counts the write in md writers, relying on
dm-qcow2 sequential nature: main kwork parses a qio and submits it
in one pass. Outside main kwork an L1/L2 page changes only when its
writeback ends, and parse_l2() already delays writes to the changed
indexes of a page under writeback.
This does not hold for the per-qio fast path, which parses L2 and
submits in parallel with main kwork. The fast path takes only writes
to fully allocated clusters mapped exactly once, whose indexes are
neither locked nor changed in a dirty or under writeback L2 page. In
between, main kwork may still discard or zero the same range, which
is a valid race with the write, or allocate other subclusters of the
cluster, which does not affect the write. But a discard unmapping the
cluster lets it be reused, and a write landing after that corrupts
the new owner. The discard waits for writes counted in md writers,
but the counter is valid only if it is increased from main kwork or
under md_pages_lock.
So count a fast path write in parse_metadata() under the same
md_pages_lock hold, which checks the L2 entry. A discard switches the
writer generation after it clears the entry under the lock, so
either the fast path sees the entry cleared, or the discard waits for
the write. Drop the count, if the qio goes to main kwork afterwards.
A partial discard on the fast path punches a hole in the cluster, so
it is counted the same way and drops the count after the punch.
A discard of a shared cluster punches nothing and is not counted.
Add @fast parameter to perform_rw_mapped(). With it, skip the md->wbd
attach, which the fast path never needs, and the writers increase.
https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
v3: new patch, replaces "wait for L2 writeback in perform_rw_mapped()":
a fast path write or partial discard is counted in md writers
under the lock which checks its L2 entry, so a discard unmapping
the cluster waits for it before the cluster is freed
drivers/md/dm-qcow2-map.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 5e254c11ae7b8..b9daa258285e6 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2160,9 +2160,14 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio,
/* Find DATA cluster (from L2 page) */
pos = ret = parse_l2(qcow2, map, qio, write);
- if (ret > 0 && write && avoid_metadata_changes)
+ if (ret > 0 && write && avoid_metadata_changes) {
l2_in_flight = dirty_or_writeback(qcow2, md,
map->l2.index_in_page + !!(qcow2->ext_l2));
+ /* A discard is counted only if it is going to punch a hole */
+ if (!l2_in_flight &&
+ (!op_is_discard((*qio)->bi_op) || !map->clu_is_cow))
+ inc_writers(md, *qio);
+ }
unlock:
spin_unlock_irq(&qcow2->md_pages_lock);
if (ret <= 0) /* Err, delayed, DATA is not allocated, or zero read */
@@ -3089,7 +3094,7 @@ static void data_rw_complete(struct qio *qio)
}
}
-static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
+static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio, bool fast)
{
struct qcow2 *qcow2 = map->qcow2;
struct md_page *md = map->l2.md;
@@ -3112,15 +3117,16 @@ static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
* so lock is not needed for MD_DIRTY/changed_indexes visibility.
*/
index_in_page = map->l2.index_in_page + !!(qcow2->ext_l2);
- if (rw == WRITE && (md->status & MD_DIRTY) &&
- test_bit(index_in_page, md->wbd->changed_indexes)) {
- spin_lock_irqsave(&qcow2->md_pages_lock, flags);
- md->wbd->nr_submitted++;
- qio->data = md->wbd;
- spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
- }
- if (rw == WRITE)
+ if (rw == WRITE && !fast) {
+ if ((md->status & MD_DIRTY) &&
+ test_bit(index_in_page, md->wbd->changed_indexes)) {
+ spin_lock_irqsave(&qcow2->md_pages_lock, flags);
+ md->wbd->nr_submitted++;
+ qio->data = md->wbd;
+ spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
+ }
inc_writers(md, qio);
+ }
map_and_submit_rw(qcow2, map->data_clu_pos, qio);
}
@@ -3608,6 +3614,8 @@ static void issue_discard(struct qcow2_map *map, struct qio *qio)
if (!map->clu_is_cow) {
pos = bio_sector_to_file_pos(qcow2, qio, map);
ret = qcow2_punch_hole(qcow2->file, pos, qio->bi_iter.bi_size);
+ if (qio->writer_md)
+ dec_writers(qio);
if (ret) {
qio->bi_status = errno_to_blk_status(ret);
@@ -3878,7 +3886,7 @@ static void process_read_qio(struct qcow2 *qcow2, struct qio *qio,
qcow2_dispatch_qios(qio->qcow2, qio, NULL);
} else {
/* Mapped */
- perform_rw_mapped(map, qio);
+ perform_rw_mapped(map, qio, false);
}
qio = split;
@@ -3899,8 +3907,11 @@ static int process_one_qio(struct qcow2 *qcow2, struct qio *qio, bool fast)
ret = handle_metadata(qcow2, &qio, &map, fast);
if (!ret)
return 0;
- if (ret == QIO_NEEDS_MAIN_KWORK)
+ if (ret == QIO_NEEDS_MAIN_KWORK) {
+ if (qio->writer_md)
+ dec_writers(qio);
return 1;
+ }
/*
* Merge machinery makes out of order merges for present
@@ -3937,7 +3948,7 @@ static int process_one_qio(struct qcow2 *qcow2, struct qio *qio, bool fast)
else if (unlikely(map.clu_is_cow || map.backing_file_cow))
submit_read_sliced_cow_clu(&map, qio);
else
- perform_rw_mapped(&map, qio);
+ perform_rw_mapped(&map, qio, fast);
}
return 0;
--
2.43.5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-13 11:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 11:11 [Devel] [PATCH hci-8.1 v3 0/8] dm-qcow2: per-qio fast path Andrey Zhadchenko
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 1/8] dm-qcow2: repeat md page lookup if it was inserted in parallel Andrey Zhadchenko
2026-11-13 11:22 ` no-reply
2026-11-13 19:48 ` Konstantin Khorenko
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 2/8] dm-qcow2: prepare process_one_qio() for fastpath Andrey Zhadchenko
2026-11-13 11:26 ` no-reply
2026-11-13 11:11 ` Andrey Zhadchenko [this message]
2026-11-13 11:27 ` [Devel] [PATCH hci-8.1 v3 3/8] dm-qcow2: count fast path writes in parse_metadata() no-reply
2026-11-13 19:48 ` Konstantin Khorenko
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 4/8] dm-qcow2: add per-qio work infrastructure Andrey Zhadchenko
2026-11-13 11:30 ` no-reply
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 5/8] dm-qcow2: implement per-qio fast processing Andrey Zhadchenko
2026-11-13 11:31 ` no-reply
2026-11-13 19:48 ` Konstantin Khorenko
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 6/8] dm-qcow2: add fast_path module parameter Andrey Zhadchenko
2026-11-13 11:31 ` no-reply
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 7/8] dm-qcow2: process fast path qios in per-cpu batches on a workqueue Andrey Zhadchenko
2026-11-13 11:33 ` no-reply
2026-11-13 19:48 ` Konstantin Khorenko
2026-11-13 11:11 ` [Devel] [PATCH hci-8.1 v3 8/8] dm-qcow2: declare DM_TARGET_NOWAIT Andrey Zhadchenko
2026-11-13 11:33 ` no-reply
2026-11-13 19:48 ` [Devel] [PATCH hci-8.1 v3 0/8] dm-qcow2: per-qio fast path Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113111126.793039-4-andrey.zhadchenko@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.com \
--cc=alexander.ivanov@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox