RFC QCOW2 compression speed
Hi,
i have been experimenting with deflate compression paramters in the past and found that the values chosen
in QCOW2 are not that optimal. In fact creation of compressed QCOW2 is very slow. And especially for backups
compression would be good, but its so slow thats almost infeasible to use.
The current settings to inflateinit2 are compression level 6 (Z_DEFAULT_COMPRESSION) and windowBits 12.
Increasing windowBits increases speed and yields better compression. Lowering the compression level increases
speed, but results in worse compression.
The issue here is that changing windowBits would (in theory) require a change of the parameters to deflateInit2 in
decompression which means that this change would make QCOW2 images incompatible.
As for discussion here is my experiment of compression a Ubuntu1604 installation in ram.
level 6, windowBits 12 -> 42 seconds, 470MB size
level 6, windowBits 15 -> 35 seconds, 448MB size
level 1, windowBits 12 -> 30 seconds, 500MB size
level 1, windowBits 15 -> 15 seconds, 483MB size
Strange enough decompression works with unchanged parameters for all files. But the documentation of zlib claims
it should produce an error if a windowBits 15 stream is deflated with a smaller windowBits parameter.
What are your thoughts in introducing a switch and/or feature to use alternate settings for inflate?
If we need to introduce an incompatible feature for the bigger windowBits might it be worth thinking of using
an alternate compression algorithm like LZ4?
Thanks,
Peter
Quoted 6 lines · Peter Lieven
Hi,
i have been experimenting with deflate compression paramters in the past and found that the values chosen
in QCOW2 are not that optimal. In fact creation of compressed QCOW2 is very slow.
I agree, I find it slow as well.
Quoted 30 lines
And especially for backups
compression would be good, but its so slow thats almost infeasible to use.
The current settings to inflateinit2 are compression level 6 (
Z_DEFAULT_COMPRESSION) and windowBits 12.Increasing windowBits increases speed and yields better compression. Lowering the compression level increases
speed, but results in worse compression.
The issue here is that changing windowBits would (in theory) require a change of the parameters to deflateInit2 in
decompression which means that this change would make QCOW2 images incompatible.
As for discussion here is my experiment of compression a Ubuntu1604 installation in ram.
level 6, windowBits 12 -> 42 seconds, 470MB size
level 6, windowBits 15 -> 35 seconds, 448MB size
level 1, windowBits 12 -> 30 seconds, 500MB size
level 1, windowBits 15 -> 15 seconds, 483MB size
Strange enough decompression works with unchanged parameters for all files. But the documentation of zlib claims
Quoted 8 lines
it should produce an error if a windowBits 15 stream is deflated with a smaller windowBits parameter.
What are your thoughts in introducing a switch and/or feature to use alternate settings for inflate?
If we need to introduce an incompatible feature for the bigger windowBits might it be worth thinking of using
an alternate compression algorithm like LZ4?
If the compression level was exposed with a command line option (and/or an environment variable, a la $GZIP), I would welcome it. I have frequently missed this feature, but I always figured it wouldn't be important enough to bother block people with it.
Thanks
Laszlo
Quoted 48 lines
Am 24.02.2017 um 12:36 schrieb Laszlo Ersek <[email protected]>:
Quoted 6 lines · Peter Lieven
Hi,
i have been experimenting with deflate compression paramters in the past and found that the values chosen
in QCOW2 are not that optimal. In fact creation of compressed QCOW2 is very slow.
I agree, I find it slow as well.
Quoted 35 lines
And especially for backups
compression would be good, but its so slow thats almost infeasible to use.
The current settings to inflateinit2 are compression level 6 (
Z_DEFAULT_COMPRESSION) and windowBits 12.Increasing windowBits increases speed and yields better compression. Lowering the compression level increases
speed, but results in worse compression.
The issue here is that changing windowBits would (in theory) require a change of the parameters to deflateInit2 in
decompression which means that this change would make QCOW2 images incompatible.
As for discussion here is my experiment of compression a Ubuntu1604 installation in ram.
level 6, windowBits 12 -> 42 seconds, 470MB size
level 6, windowBits 15 -> 35 seconds, 448MB size
level 1, windowBits 12 -> 30 seconds, 500MB size
level 1, windowBits 15 -> 15 seconds, 483MB size
Strange enough decompression works with unchanged parameters for all files. But the documentation of zlib claims
it should produce an error if a windowBits 15 stream is deflated with a smaller windowBits parameter.
What are your thoughts in introducing a switch and/or feature to use alternate settings for inflate?
Quoted 8 lines
Quoted 3 lines
If we need to introduce an incompatible feature for the bigger windowBits might it be worth thinking of using
an alternate compression algorithm like LZ4?
If the compression level was exposed with a command line option (and/or an environment variable, a la $GZIP), I would welcome it. I have frequently missed this feature, but I always figured it wouldn't be important enough to bother block people with it.
Changing the compression level via environment or a QCOW2 parameter is not a big deal. However, it helps not that much regarding speed. What helps is increasing the window size, but this is an incompatible change. And if we go for an incompatible change I would think about using a better compression algorithm than zlib deflate.
Peter
Quoted 2 lines · Peter Lieven
Changing the compression level via environment or a QCOW2 parameter is not a big deal. However, it helps not that much regarding speed. What helps is increasing the window size, but this is an incompatible change. And if we go for an incompatible change I would think about using a better compression algorithm than zlib deflate.
Indeed, lzma (think xz), or zstd, or $compression_of_the_day... may be better, and it may be disk-image dependent which algorithm is best. It sounds like we need to improve the qcow2 spec to add a header extension that describes the current compression algorithm and parameters; if omitted the image uses zlib with fixed window size, but if present, we can put everything we need to be able to choose other compression tunings and be able to decompress (still, it has to be an all-or-none). We'd also need to set an incompatible_features flag if the compression header extension is present with non-default values so that older qemu don't go corrupting the compressed data. And then you start having to worry about modularity (do you compile qemu with support for all compression libraries, or can you pick and choose which ones to compile in at the risk of which images you can't open, or do you figure out how to dlopen the right libraries as needed...)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org