[pve-devel] [PATCH v2 qemu-server] add drive discard_granularity option

Alexandre Derumier aderumier at odiso.com
Fri Jun 29 16:40:23 CEST 2018


This allow to specific block size for discard

values:
  undef :default qemu logical block
  1: auto detect storage block size
  512-4294967295 : (bytes)

specific to rbd:

when we have snapshots on rbd and do a trim, the space is increasing
http://tracker.ceph.com/issues/18352

we need to trim a full object (4MB by default), to be able to free space.

test:

without discard_granularity
---------------------------
vm-107-disk-1		                                       20480M   2500M
vm-107-disk-1                                                  20480M   2500M

vm-107-disk-1 at snap1                                            20480M   2500M
vm-107-disk-1                                                  20480M  90112k

vm-107-disk-1 at snap1                                            20480M   2500M
vm-107-disk-1                                                  20480M   1020M

with discard_granularity=4M
---------------------------
vm-107-disk-1		                                       20480M   2500M
vm-107-disk-1                                                  20480M   2500M

vm-107-disk-1 at snap1                                            20480M   2500M
vm-107-disk-1                                                  20480M  90112k

vm-107-disk-1 at snap1                                            20480M   2500M
vm-107-disk-1                                                  20480M    144M
---
 PVE/QemuServer.pm | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6a355f8..b2ae324 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -905,6 +905,12 @@ my %drivedesc_base = (
 	description => 'Controls whether to pass discard/trim requests to the underlying storage.',
 	optional => 1,
     },
+    discard_granularity => {
+        type => 'integer',
+        minimum => 1, maximum => 4294967295,
+        description => 'Discard granularity size (bytes)',
+        optional => 1,
+    },
     detect_zeroes => {
 	type => 'boolean',
 	description => 'Controls whether to detect and try to optimize writes of zeroes.',
@@ -1695,6 +1701,20 @@ sub print_drivedevice_full {
 	$device .= ",serial=$serial";
     }
 
+    my $volid = $drive->{file};
+    if($volid && $drive->{discard} && $drive->{discard_granularity}) {
+
+	my $granularity = undef;
+
+	if ($drive->{discard_granularity} eq '1') {
+	    my ($blocksize) = PVE::Storage::volume_blocksize_info($storecfg, $volid, 3);
+	    $granularity = $blocksize;
+	} else {
+	    die "discard granularity can't be lower than 512 bytes\n" if $drive->{discard_granularity} < 512;
+	    $granularity = $drive->{discard_granularity};
+	}
+	$device .= ",discard_granularity=$granularity";
+    }
 
     return $device;
 }
-- 
2.11.0




More information about the pve-devel mailing list