-
Notifications
You must be signed in to change notification settings - Fork 699
Description
Many/most distro images are distributed in QCOW2 format, which is not supported by VZ.
So every time a VZ instance is started the image is converted into RAW format first. Which takes just a few seconds, but also increases disk space usage:
Normally the file would be copied via clonefile
and not take up extra space. Any further changes would be written just to the copy via the copy-on-write mechanism, but the shared base image would only exist once.
The savings become even larger when the user runs multiple instances using the same image:
Normally each additional image would use another clonefile
and not use extra space. But since we are converting to RAW separately for each instance, they are not even using clones of each other, but new identical conversions of the original image.
Assume QCOW2 image is 500MB and you create 2 RAW instances: total space needed is 500MB for the QCOW2 version in the cache, plus 500MB for each instance, for a total of 1.5GB
If we had a 500MB RAW image in the cache then total space needed would be 500MB for the cache instance, plus pocket-change for the meta data of the 2 clones, saving 1GB of disk.
I suggest that the request to the cache download should include the desired format.
- The desired format is already in the cache: return a copy/clone of it
- The image is in a different format in the cache: convert to the desired format, but keep original
- Download image from source, return it if already in desired format
- Otherwise convert to desired format, then delete the download
Case 2 can happen if the user used the image with QEMU before and now wants to create a VZ instance. It makes sense to keep the original format in case they want to create another QEMU instance. It is also possible that the QEMU instance still exists, in which case deleting the cache copy would not clear up any space because it is just a clone.
Case 4 is the case when a user only uses the default VZ driver. They will only need to keep the desired (RAW) version in the cache. In case they later need a QCOW2 version, they will have to download it again. But from then on both versions will be in the cache.
The cache needs to retain the checksum of the original image and not use the checksum of the converted copy for lookup.