QCOW2的几种预分配规则创建时间对比

主要有以下几种策略,都在同一个SSD上测试.

  • off => 缺省预分配策略,即不使用预分配策略.
  • metadata => 分配qcow2的元数据(metadata),预分配后的虚拟磁盘仍然属于稀疏映像类型,分配元数据所需的空间,但不为数据分配任何空间,这是配置是预分配里最快的,但客户机写入最慢.
  • falloc => 为元数据和数据分配空间,但将块标记为未分配,这将比metadata配置得慢,但比full配置要快,客户机写入性能将比metadata快得多,并且接近full.
  • full => 分配所有磁盘空间并置零,预分配后的虚拟磁盘属于非稀疏映像类型,并且性能和宿主机差不多,但是这个分配非常的慢.

分配速度测试:

root@debian:/var/lib/libvirt/images# time qemu-img create -f qcow2 -o preallocation=off /var/lib/libvirt/images/seedbox.qcow2 500G
Formatting '/var/lib/libvirt/images/seedbox.qcow2', fmt=qcow2 size=536870912000 cluster_size=65536 preallocation=off lazy_refcounts=off refcount_bits=16

real    0m0.144s
user    0m0.000s
sys     0m0.029s
root@debian:/var/lib/libvirt/images# time qemu-img create -f qcow2 -o preallocation=metadata /var/lib/libvirt/images/seedbox.qcow2 500G
Formatting '/var/lib/libvirt/images/seedbox.qcow2', fmt=qcow2 size=536870912000 cluster_size=65536 preallocation=metadata lazy_refcounts=off refcount_bits=16

real    1m19.068s
user    0m3.763s
sys     0m1.151s
root@debian:/var/lib/libvirt/images# time qemu-img create -f qcow2 -o preallocation=falloc /var/lib/libvirt/images/seedbox.qcow2 500G
Formatting '/var/lib/libvirt/images/seedbox.qcow2', fmt=qcow2 size=536870912000 cluster_size=65536 preallocation=falloc lazy_refcounts=off refcount_bits=16

real    1m28.153s
user    0m3.723s
sys     0m1.766s
root@debian:/var/lib/libvirt/images# time qemu-img create -f qcow2 -o preallocation=full /var/lib/libvirt/images/seedbox.qcow2 500G
Formatting '/var/lib/libvirt/images/seedbox.qcow2', fmt=qcow2 size=536870912000 cluster_size=65536 preallocation=falloc lazy_refcounts=off refcount_bits=16

real    43m11.214s
user    0m3.721s
sys     0m1.216s

所以除非特别纠结,不然还是falloc最划算.

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注