does KVM raw images support preallocation?

7,397

Solution 1

According to this manual, I don't see any preallocation options for raw images.

And also it might be good to take a look at these benchmarks, It seems that any kind of raw images have better performance than qcow2.

and also I've seen many suggestions to avoid write-through caching because of performance issues but I didn't test it myself.

Solution 2

raw images do not support preallocation, qcow2 and qed-images do:

preallocation=full instead of preallocation=metadata does not only allocate metadata for the raw image, but also writes zeros to it, thus creating a non-sparse image file.

If your filesystems supports sparse-files (e.g. ext, xfs, btrfs), blocks filled only with zeros are not stored physically, that saves space at the beginning of using this image.

If you would like to allocate all space on the raw image, you can use the dd command: dd if=/dev/zero of=file.img bs=1M count=204800

If you are working towards speed, also use cache=writethrough with e.g. libvirt, this enhanced speed without loss of data if your physical machine crashes.

Share:
7,397

Related videos on Youtube

Zim3r
Author by

Zim3r

A bad member of community.

Updated on September 18, 2022

Comments

  • Zim3r
    Zim3r over 1 year

    I was trying to create a raw image with this command:

    qemu-img create -f raw -o size=200G,preallocation=metadata file.img
    

    but seem that it raw images doesn't support preallocation. if so why there is raw + preallocation in this chart?

    # qemu-img create -f raw -o size=200G,preallocation=full file.img
    Unknown option 'preallocation'
    Invalid options for file format 'raw'.
    
  • Zim3r
    Zim3r over 11 years
    Thanks but: Unknown option 'preallocation' Invalid options for file format 'raw'. and I heard bad things about write-through.
  • leoben
    leoben over 11 years
    I've edited my previous answer. Regarding writethrough: That enhances performance distinctly, of course the performance improvment depends on many other variables. You may have heard something bad about writeback-caching, as mentioned this is a risk if your physical machine crashes, but this imrpoves perfomance even more.
  • Michael Hampton
    Michael Hampton over 11 years
    It may seem counterintuitive, but cache=writethrough really does dramatically reduce performance in a lot of situations.
  • leoben
    leoben over 11 years
    In my experience this only has an impact when creating snapshots (which is a known bug) of a qcow2 image, so I deactivate it only for systems I know I will make a lot of snapshots of. I have not experienced a performance decrease in my practical experience, the contrary. It may be that in different enviroments the experience is not good or even worse than without caching, using up to date software may remedy the deficiencies.