Commit bbb4d069 authored by Julien Muchembled's avatar Julien Muchembled

kvm: always enable discard for drives

Given that the default is to use raw for device drives and qcow2 for
file drives,  and that 'discard' was already enabled for raw, this
commit is in practice mainly for file drives, for which QEMU processes
TRIM by punching holes (i.e. the image file becomes sparse).

This reduces disk usage not only by the process running the VM but
also by backups and replicas (e.g. runner1).

For qcow2 at least, the discarded space can be reused for other blocks
and qemu compacts the image at dump (for backups) so images on replicas
are not sparse.

When an image disk format doesn't support it, QEMU ignores the option
so it's safe.

Guest support of TRIM for virtio-blk is recent: Linux 5.0
parent 128a37e0
...@@ -55,7 +55,7 @@ md5sum = b7e87479a289f472b634a046b44b5257 ...@@ -55,7 +55,7 @@ md5sum = b7e87479a289f472b634a046b44b5257
[template-kvm-run] [template-kvm-run]
filename = template/template-kvm-run.in filename = template/template-kvm-run.in
md5sum = e7b9623eabe1bbd5233e0fbfde94a67c md5sum = adf05b4255269bc7d0eec479424405e4
[template-kvm-controller] [template-kvm-controller]
filename = template/kvm-controller-run.in filename = template/kvm-controller-run.in
......
...@@ -301,17 +301,12 @@ kvm_argument_list = [qemu_path, ...@@ -301,17 +301,12 @@ kvm_argument_list = [qemu_path,
'-nodefaults', '-nodefaults',
] ]
for disk_info in disk_info_list: for disk_info in disk_info_list:
additional_disk_options = '' kvm_argument_list += (
if disk_info['format'] == "raw":
additional_disk_options += ',discard=on'
kvm_argument_list.extend([
'-drive', '-drive',
'file=%s,if=%s%s%s' % ( 'file=%s,if=%s,discard=on%s' % (
disk_info['path'], disk_type, additional_disk_options, disk_info['path'], disk_type,
''.join(',%s=%s' % x for x in disk_info.items() if x[0] != 'path')) ''.join(',%s=%s' % x for x in disk_info.items() if x[0] != 'path'))
]) )
rgx = re.compile('^[\w*\,][\=\d+\-\,\w]*$') rgx = re.compile('^[\w*\,][\=\d+\-\,\w]*$')
for numa in numa_list: for numa in numa_list:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment