From: Lukas Sichert <l.sichert@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Lukas Sichert <l.sichert@proxmox.com>
Subject: [PATCH storage 2/4] fix #8196: lvm: add discard throughput limit
Date: Fri, 20 Nov 2026 14:32:41 +0100 [thread overview]
Message-ID: <20261120133245.51042-3-l.sichert@proxmox.com> (raw)
In-Reply-To: <20261120133245.51042-1-l.sichert@proxmox.com>
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 <l.sichert@proxmox.com>
---
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
next prev parent reply other threads:[~2026-11-20 13:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:32 [PATCH docs/manager/storage 0/4] fix #8196: lvm: add a throughput limit for discards Lukas Sichert
2026-11-20 13:32 ` [PATCH storage 1/4] lvm: rename the saferemove throughput parser to parse_throughput Lukas Sichert
2026-11-20 13:32 ` Lukas Sichert [this message]
2026-11-20 13:32 ` [PATCH manager 3/4] ui: lvm: keep other on-volume-remove options when editing Lukas Sichert
2026-11-20 13:32 ` [PATCH docs 4/4] storage: lvm: document the discard throughput limit Lukas Sichert
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=20261120133245.51042-3-l.sichert@proxmox.com \
--to=l.sichert@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