From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage 3/3] lvm: qcow2: reserve LV space for persistent dirty bitmaps
Date: Fri, 13 Nov 2026 02:17:25 +0100 [thread overview]
Message-ID: <20261113012702.864671-4-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261113012702.864671-1-t.lamprecht@proxmox.com>
Backup solutions like Veeam add persistent dirty bitmaps to qcow2
images to track changed blocks. QEMU stores them inside the image when
the VM is stopped or migrated, in addition to what 'qemu-img measure'
reports and what the LV size is based on. So only the space from
rounding up to full extents was left for them, which depends on the
image size and can be close to nothing. As QEMU writes all new bitmap
clusters before freeing the old ones, a store needs room for two
copies, almost 4 MiB for one bitmap on a 900 GiB image. If that space
is missing, storing fails with ENOSPC and the bitmap is lost.
Reserve space for two copies of two fully dirty bitmaps at the default
granularity of 64 KiB, which is also what Veeam was observed to use,
plus a refcount block for them. That is about 8 KiB per GiB of disk
size, for example 8.4 MiB for 900 GiB. The calculation assumes 128 KiB
clusters, so it also covers snapshot overlays. A finer granularity or
more than two bitmaps can still exceed the reserved space. So can a
store that needs to grow the refcount table, which happens at least for
images ending just below 16 TiB with 64 KiB clusters or 128 TiB with
128 KiB clusters, as QEMU then places the new refcount structures at the
next refcount block boundary, up to 2 GiB or 8 GiB further.
Existing LVs only get the additional space when they are resized.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PVE/Storage/LVMPlugin.pm | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 6b9867f3..e576bd74 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -9,6 +9,7 @@ use File::Basename;
use IO::File;
use JSON;
use List::Util qw(max);
+use POSIX qw(ceil);
use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
use PVE::Diskmanage;
@@ -1302,6 +1303,19 @@ my sub lvm_qcow2_format {
}
}
+# room for two copies (old and new while storing) of two fully dirty persistent bitmaps at 64 KiB
+# granularity, and a refcount block for them, assuming 128 KiB clusters
+my sub persistent_bitmaps_headroom {
+ my ($size) = @_; # in KiB
+
+ my $cluster_kib = 128;
+ my $data_clusters = ceil($size / 64 / 8 / ($cluster_kib * 1024));
+ my $table_clusters = ceil($data_clusters * 8 / ($cluster_kib * 1024));
+ my $copy_clusters = 2 * ($data_clusters + $table_clusters) + 1; # one directory cluster
+
+ return (2 * $copy_clusters + 1) * $cluster_kib;
+}
+
my sub calculate_lvm_size {
my ($size, $fmt, $measure_options) = @_;
#input size = qcow2 image size in kb
@@ -1317,7 +1331,7 @@ my sub calculate_lvm_size {
die "Missing fully-allocated value from json" if !$info->{'fully-allocated'};
- return $info->{'fully-allocated'} / 1024;
+ return $info->{'fully-allocated'} / 1024 + persistent_bitmaps_headroom($size);
}
# snapshot overlays use other cluster settings than base images, which changes the measured size
--
2.47.3
next prev parent reply other threads:[~2026-11-13 1:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 1:17 [PATCH storage 0/3] lvm: fix qcow2 images outgrowing their LV Thomas Lamprecht
2026-11-13 1:17 ` [PATCH storage 1/3] lvm: avoid qcow2 images outgrowing their LV after offline snapshot delete Thomas Lamprecht
2026-11-13 1:17 ` [PATCH storage 2/3] lvm: qcow2 resize: size the LV for the cluster settings of the image Thomas Lamprecht
2026-11-13 1:17 ` Thomas Lamprecht [this message]
2026-11-13 9:54 ` [PATCH storage 3/3] lvm: qcow2: reserve LV space for persistent dirty bitmaps Fiona Ebner
2026-11-13 11:12 ` Thomas Lamprecht
2026-11-13 12:33 ` applied: " Fiona Ebner
2026-11-13 9:52 ` applied: (subset) [PATCH storage 0/3] lvm: fix qcow2 images outgrowing their LV Fiona Ebner
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=20261113012702.864671-4-t.lamprecht@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.proxmox.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