All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: seek unallocated L2 entries in one pass within md
Date: Tue, 25 Aug 2026 12:41:57 +0200	[thread overview]
Message-ID: <202608251041.67PAfvqT774856@f0.sw.ru> (raw)
In-Reply-To: <20260819000745.28823-7-andrey.zhadchenko@virtuozzo.com>

The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.9.vz10
------>
commit 056b0452a90b769a5445d978bc7dde0536ae3b7a
Author: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Date:   Wed Aug 19 03:07:44 2026 +0300

    dm-qcow2: seek unallocated L2 entries in one pass within md
    
    When a cluster is unallocated but its L2 table exists, the seek code
    walks it one cluster at a time: SEEK_DATA re-parses metadata for
    every cluster of the range, and with a backing image each cluster
    additionally costs a qio and completion allocation for the lower
    delta descent.
    
    If the unmapped range reaches the cluster border, prolong it over the
    following unallocated L2 entries: they are cached in the very md page
    the current entry was parsed from, so this is just scanning for
    non-zero words. Then the lower delta is scanned in one pass over the
    whole range, and SEEK_DATA without a backing image skips it in one go.
    
    Entries with any subcluster or "reads as zeroes" bits set stop the
    scan and spin parse_metadata() machinery.
    
    On a 16G image (128K clusters, extended L2) with all L2 tables
    allocated but no clusters mapped over a backing image with data at
    15G, warm-cache SEEK_DATA improves from 44.8 ms to 0.4 ms.
    
    https://virtuozzo.atlassian.net/browse/VSTOR-139407
    Feature: dm-qcow2: block device over QCOW2 files driver
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
    Reviewed-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
    Reviewed-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 879d2f1827006..eaaf0a521d7bd 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4439,6 +4439,34 @@ static inline void seek_qio_next_clu(struct qio *qio, struct qcow2_map *map)
 	seek_qio_set_sector(qio, bi_sector);
 }
 
+/*
+ * Manually scan L2 metadata pages until we hit something interesting.
+ * We do not take md_pages_lock here because we have no promises about
+ * concurrent writes anyway.
+ */
+static loff_t seek_extend_unmapped_end(struct qio *qio, struct qcow2_map *map,
+				       loff_t end)
+{
+	struct qcow2 *qcow2 = qio->qcow2;
+	loff_t lim = SEEK_QIO_DATA(qio)->lim;
+	u32 step = 1 + qcow2->ext_l2;
+	u32 index = map->l2.index_in_page + step;
+	u64 *entries;
+
+	entries = kmap_local_page(map->l2.md->page);
+	for (; index + step <= PAGE_SIZE / sizeof(u64) && end < lim;
+	     index += step) {
+		/* Zero test does not need be64_to_cpu() */
+		if (READ_ONCE(entries[index]) ||
+		    (qcow2->ext_l2 && READ_ONCE(entries[index + 1])))
+			break;
+		end += qcow2->clu_size;
+	}
+	kunmap_local(entries);
+
+	return min_t(loff_t, end, lim);
+}
+
 static struct qio *advance_and_spawn_lower_seek_qio(struct qio *old_qio, loff_t end)
 {
 	struct qcow2 *lower = old_qio->qcow2->lower;
@@ -4501,12 +4529,16 @@ static int qcow2_llseek_hole_qio(struct qio *qio, int whence, loff_t *result)
 				struct qio *new_qio;
 				loff_t end;
 
-				if (!(map.level & L2_LEVEL))
+				if (!(map.level & L2_LEVEL)) {
 					end = min_t(loff_t,
 						    to_bytes(get_next_l2(qio)),
 						    SEEK_QIO_DATA(qio)->lim);
-				else
+				} else {
 					end = to_bytes(qio->bi_iter.bi_sector) + size;
+					/* extend operates on cluster granularity */
+					if (!CLU_OFF(qio->qcow2, end))
+						end = seek_extend_unmapped_end(qio, &map, end);
+				}
 
 				new_qio = advance_and_spawn_lower_seek_qio(qio, end);
 				if (!new_qio) {
@@ -4550,6 +4582,16 @@ static int qcow2_llseek_hole_qio(struct qio *qio, int whence, loff_t *result)
 				qio->bi_iter.bi_sector += to_sector(size);
 				qio->bi_iter.bi_size -= size;
 				goto calc_subclu;
+			} else if (arg.unmapped && (map.level & L2_LEVEL)) {
+				loff_t end = to_bytes(qio->bi_iter.bi_sector) + size;
+				sector_t next;
+
+				/* Skip the following unallocated entries in one go */
+				if (!CLU_OFF(qio->qcow2, end)) {
+					next = to_sector(seek_extend_unmapped_end(qio, &map, end));
+					seek_qio_set_sector(qio, next);
+					continue;
+				}
 			}
 		}
 

  reply	other threads:[~2026-08-25 10:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19  0:07 [Devel] [PATCH VZ10 v2 0/7] dm-qcow: lseek improvements Andrey Zhadchenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 1/7] drivers/md/dm-qcow2: fix lower delta seek window clamp Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 2/7] drivers/md/dm-qcow2: keep seek parse window within limit Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 3/7] drivers/md/dm-qcow2: fix seek constant comparison Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 4/7] drivers/md/dm-qcow2: fix seek skip to the next L2 table Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 5/7] drivers/md/dm-qcow2: scan lower delta in one pass over empty L1 entry Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 6/7] drivers/md/dm-qcow2: seek unallocated L2 entries in one pass within md Andrey Zhadchenko
2026-08-25 10:41   ` Konstantin Khorenko [this message]
2026-08-19  0:07 ` [Devel] [PATCH VZ10 v2 7/7] drivers/md/dm-qcow2: forbid unaligned virtual size for images Andrey Zhadchenko
2026-08-25 10:41   ` [Devel] [PATCH RHEL10 COMMIT] dm-qcow2: " Konstantin Khorenko
2026-08-19  8:54 ` [Devel] [PATCH VZ10 v2 0/7] dm-qcow: lseek improvements Vasileios Almpanis
2026-08-24 14:38 ` Pavel Tikhomirov

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=202608251041.67PAfvqT774856@f0.sw.ru \
    --to=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 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.