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 B3D721FF0AF for ; Fri, 20 Nov 2026 14:33:29 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5A7EB217F5; Fri, 20 Nov 2026 14:32:58 +0100 (CET) From: Lukas Sichert To: pve-devel@lists.proxmox.com Subject: [PATCH storage 2/4] fix #8196: lvm: add discard throughput limit Date: Fri, 20 Nov 2026 14:32:41 +0100 Message-ID: <20261120133245.51042-3-l.sichert@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120133245.51042-1-l.sichert@proxmox.com> References: <20261120133245.51042-1-l.sichert@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795181572923 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.441 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: NS6CRTYTLGHMK2HIZN4IM5VANXPJFJ2H X-Message-ID-Hash: NS6CRTYTLGHMK2HIZN4IM5VANXPJFJ2H X-MailFrom: l.sichert@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 CC: Lukas Sichert X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Unthrottled discards can overload the controllers of enterprise storage arrays. The cleanup worker already issues discards in bounded batches through the loop that paces the saferemove writes, so applying a rate limit there throttles discards as well. Add a 'discard_throughput' option to on-volume-remove. It takes the same values as saferemove_throughput and only has an effect if discard is enabled. If wiping is enabled and saferemove_throughput is set as well, the lower of both limits is used, as both share the one pacing loop. The task log line announcing the limit no longer says "saferemove", as the limit can now come from either option. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8196 Signed-off-by: Lukas Sichert --- src/PVE/Storage/LVMPlugin.pm | 24 ++++++++++++++--- src/test/run_test_lvm_throughput.pl | 40 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 3f74cfc..ca274b8 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -759,14 +759,21 @@ my sub free_lvm_volumes_locked { my $zero_out = $scfg->{saferemove}; my $zeroout_variant = $zero_out ? 'blkzeroout' : 'none'; - my $throughput = undef; # discards alone are not rate limited + my $throughput = undef; if ($zero_out && (my $value = $scfg->{saferemove_throughput})) { # Normalize zero spellings before selecting the default or dividing by the rate. $throughput = abs(parse_throughput($value)) || undef; } + if ($on_remove_opts->{discard} && (my $value = $on_remove_opts->{discard_throughput})) { + # Wiping and discarding share one pacing loop, so the lower of both limits applies. + my $limit = abs(parse_throughput($value)) || undef; + if (defined($limit) && (!defined($throughput) || $limit < $throughput)) { + $throughput = $limit; + } + } if (defined($throughput)) { my $rendered_throughput = render_bytes($throughput); - print "using saferemove throughput limit: $rendered_throughput/s\n"; + print "using throughput limit: $rendered_throughput/s\n"; } # If the storage does not support write_zeroes fall back to writing zeroes manually using @@ -1068,6 +1075,15 @@ my $on_volume_remove_format = { . " range before removing it, allowing thin-provisioned storage to reclaim previously" . " allocated physical space, provided the storage supports discard.", }, + discard_throughput => { + description => "Discard throughput in bytes per second (optional suffix: k, m, or g)." + . " Only has an effect if 'discard' is enabled. If 'saferemove_throughput' is set" + . " as well, the lower limit is used.", + type => 'string', + format_description => 'bytes per second', + pattern => '-?\d+[kmgKMG]?', + optional => 1, + }, }; sub verify_on_volume_remove { @@ -1119,7 +1135,9 @@ sub properties { }, saferemove_throughput => { title => "Wipe Throughput", - description => "Wipe throughput in bytes per second (optional suffix: k, m, or g).", + description => "Wipe throughput in bytes per second (optional suffix: k, m, or g)." + . " If 'discard' is enabled and 'discard_throughput' in 'on-volume-remove' is set" + . " as well, the lower limit is used.", type => 'string', pattern => '-?\d+[kmgKMG]?', }, diff --git a/src/test/run_test_lvm_throughput.pl b/src/test/run_test_lvm_throughput.pl index b6f6fa8..d71f05a 100755 --- a/src/test/run_test_lvm_throughput.pl +++ b/src/test/run_test_lvm_throughput.pl @@ -51,4 +51,44 @@ for my $value ('0m', '-0', '00', '1m') { ); } +my $discard_granularity = 0; +$plugin->mock( + file_read_firstline => sub { + return + $_[0] =~ m!/size$! ? 2048 + : $_[0] =~ m!/discard_granularity$! ? $discard_granularity + : 0; + }, +); +my @cases = ( + ['wipe, lower on-volume-remove wins', 1, '2m', '1m', 1, 0, 1], + ['wipe, lower saferemove_throughput wins', 1, '1m', '2m', 1, 0, 1], + ['wipe, zero on-volume-remove leaves the other', 1, '2m', '0', 0.5, 0, 1], + ['wipe, discard_throughput ignored without discard', 1, '2m', '1m', 0.5, 0, 0], + ['discard only', 0, undef, '2m', 0.5, 512, 1], + ['discard only, saferemove_throughput ignored', 0, '1m', undef, undef, 512, 1], +); +for my $case (@cases) { + my ($label, $wipe, $old, $new, $expected, $granularity, $discard) = @$case; + $discard_granularity = $granularity; + open(my $fh, '>', "$dir/del-$name") or die "create test volume: $!\n"; + close($fh) or die "close test volume: $!\n"; + @delays = (); + @commands = (); + my $output = ''; + my $scfg = { vgname => "..$dir", saferemove => $wipe }; + $scfg->{saferemove_throughput} = $old if defined($old); + my @remove_opts = ( + $discard ? 'discard=1' : (), defined($new) ? "discard_throughput=$new" : (), + ); + $scfg->{'on-volume-remove'} = join(',', @remove_opts) if @remove_opts; + open(my $stdout, '>', \$output) or die "capture output: $!\n"; + my $previous = select($stdout); + eval { PVE::Storage::LVMPlugin->free_image('test', $scfg, $name, 0, 'raw')->(); }; + select($previous); + close($stdout) or die "close captured output: $!\n"; + like($output, qr/^(?:zeroed out|discarded) /m, "$label: processed the volume"); + is_deeply(\@delays, defined($expected) ? [$expected] : [], "$label: delays"); +} + done_testing(); -- 2.47.3