From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id B0FCA1FF0B7 for ; Fri, 13 Nov 2026 02:27:30 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1EEC82172A; Fri, 13 Nov 2026 02:27:13 +0100 (CET) From: Thomas Lamprecht 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 Message-ID: <20261113012702.864671-4-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113012702.864671-1-t.lamprecht@proxmox.com> References: <20261113012702.864671-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794533227879 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.251 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 62MUWQOBYQCCPO5EAQQRGT67MTIMKEVC X-Message-ID-Hash: 62MUWQOBYQCCPO5EAQQRGT67MTIMKEVC X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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