Skip to content

Suggestion: Use zstd compression for images #151

Description

@anarazel

Hi,

I noticed that the various OS images are all only compressed with zlib. That is mildly disadvantageous because zstd is better at compressing, but perhaps more importantly, it makes the conversion from qcow2 to raw slower.

qemu-img convert -p -m 16 -o compression_type=zstd -c -O qcow2 freebsd-15.0-arm64.qcow2 freebsd-15.0-arm64.zstd.qcow2

zstd:

freebsd-15.0-arm64.zstd.qcow2
file format: qcow2
virtual size: 12 GiB (12884901888 bytes)
disk size: 333 MiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zstd
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
Child node '/file':
    filename: freebsd-15.0-arm64.zstd.qcow2
    protocol type: file
    file length: 334 MiB (349831168 bytes)
    disk size: 333 MiB

original zlib:

andres@awork3:/tmp$ qemu-img info freebsd-15.0-arm64.qcow2 
image: freebsd-15.0-arm64.qcow2
file format: qcow2
virtual size: 12 GiB (12884901888 bytes)
disk size: 343 MiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
Child node '/file':
    filename: freebsd-15.0-arm64.qcow2
    protocol type: file
    file length: 343 MiB (359661568 bytes)
    disk size: 343 MiB

Time for raw conversion:

andres@awork3:/tmp$ time numactl --physcpubind 10-13 qemu-img convert freebsd-15.0-arm64.qcow2 freebsd-15.0-arm64.raw

real	0m1.484s
user	0m3.622s
sys	0m0.767s
andres@awork3:/tmp$ time numactl --physcpubind 10-13 qemu-img convert freebsd-15.0-arm64.zstd.qcow2 freebsd-15.0-arm64.raw

real	0m0.751s
user	0m1.369s
sys	0m0.767s

(limited it to 4 cores to be similar-ish to the GHA environment)

So a few MB smaller and ~twice as fast to decompress.

Although I guess I don't really understand why the images are stored as qcow2 and then converted to raw images. I assume using the qcow2 for the VMs turned out to be slower? The within qcow2 compression isn't that good for overall compression ratio, because it has to support being updated etc. If you stored the images as compressed sparse tarballs, you should be able to get their size down.

tar --sparse -cvf - freebsd-15.0-arm64.raw|zstd -T0 -10 > freebsd-15.0-arm64.raw.tar.zst

gets you a 259M file. Which doesn't take long to decompress either:

time tar -x --zstd -f ../freebsd-15.0-arm64.raw.tar.zst

real	0m1.654s
user	0m1.633s
sys	0m1.844s

Greetings,

Andres

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions