KVM虚拟化:使用qemu-img创建qcow2虚拟磁盘的预分配策略分析
来源:互联网 发布:scdma是什么网络类型 编辑:程序博客网 时间:2024/05/01 01:47
简介
本文介绍使用qemu-img创建qcow2格式磁盘文件的预分配(preallocation)策略,及对虚拟磁盘性能的影响。
qcow2磁盘及预分配策略介绍
查看qemu-img手册,可以看到关于qcow2格式磁盘文件和预分配策略的简要介绍:
qcow2 QEMU image format, the most versatile format. Use it to have smaller images (useful if your filesystem does not supports holes, for example on Windows), optional AES encryption, zlib based compression and support of multiple VM snapshots. Supported options: "backing_file" File name of a base image (see create subcommand) "backing_fmt" Image format of the base image "encryption" If this option is set to "on", the image is encrypted. Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection. "cluster_size" Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster sizes can improve the image file size whereas larger cluster sizes generally provide better performance. "preallocation" Preallocation mode (allowed values: "off", "metadata", "falloc", "full"). An image with preallocated metadata is initially larger but can improve performance when the image needs to grow. "falloc" and "full" preallocations are like the same options of "raw" format, but sets up metadata also.qcow2是QEMU的虚拟磁盘映像格式,它是一种非常灵活的磁盘格式,支持瘦磁盘(类似稀疏文件)格式,可选的AES加密,zlib压缩及多快照功能。在使用qemu-img创建qcow2虚拟磁盘,可以设置磁盘预分配策略,其支持4种格式:
- off模式:缺省预分配策略,即不使用预分配策略
- metadata模式:分配qcow2的元数据(metadata),预分配后的虚拟磁盘仍然属于稀疏映像类型(allocates qcow2 metadata, and it's still a sparse image.)
- full模式:分配所有磁盘空间并置零,预分配后的虚拟磁盘属于非稀疏映像类型(allocates zeroes and makes a non-sparse image)
- falloc模式:使用posix_fallocate()函数分配文件的块并标示它们的状态为未初始化,相对full模式来说,创建虚拟磁盘的速度要快很多(which uses posix_fallocate() to "allocate blocks and marking them as uninitialized", and is relatively faster than writing out zeroes to a file)
测试与验证
使用qemu-img创建qcow2格式虚拟磁盘,并设置不同预配置参数:
[root@CentOS65 kvm]# qemu-img create -f qcow2 /home/kvm/test1-offdata.qcow2 5GFormatting '/home/kvm/test1-offdata.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 [root@CentOS65 kvm]# qemu-img create -f qcow2 -o preallocation=metadata /home/kvm/test1-metadata.qcow2 5GFormatting '/home/kvm/test1-metadata.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='metadata' [root@CentOS65 kvm]# qemu-img create -f qcow2 -o preallocation=full /home/kvm/test1-fulldata.qcow2 5GFormatting '/home/kvm/test1-fulldata.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='full' [root@CentOS65 kvm]# qemu-img create -f qcow2 -o preallocation=falloc /home/kvm/test1-fallocatdata.qcow2 5GFormatting '/home/kvm/test1-fallocatdata.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='falloc' [root@CentOS65 kvm]# ls -lash /home/kvm/total 13G4.0K drwxr-xr-x. 2 root root 4.0K Jan 29 04:45 .4.0K drwxr-xr-x. 6 root root 4.0K Jan 25 08:48 ..5.1G -rw-r--r--. 1 root root 5.1G Jan 29 04:45 test1-fallocatdata.qcow25.1G -rw-r--r--. 1 root root 5.1G Jan 29 04:44 test1-fulldata.qcow2912K -rw-r--r--. 1 root root 5.1G Jan 29 04:44 test1-metadata.qcow2136K -rw-r--r--. 1 root root 193K Jan 29 04:43 test1-offdata.qcow2从测试结果上看,可得出以下结论:
1. 缺省策略和metadata策略创建出来的磁盘属于稀疏磁盘格式,而falloc和full策略创建出来的磁盘属于非稀疏磁盘格式。
2. 由于falloc策略,无需对磁盘进行置零操作,因此其创建虚拟磁盘时的速度要比full模式快的多
在查看磁盘文件信息时,也可以使用"qemu-img info"和stat命令:
[root@CentOS65 kvm]# qemu-img info /home/kvm/test1-offdata.qcow2 image: /home/kvm/test1-offdata.qcow2file format: qcow2virtual size: 5.0G (5368709120 bytes)disk size: 136Kcluster_size: 65536[root@CentOS65 kvm]# stat /home/kvm/test1-offdata.qcow2 File: `/home/kvm/test1-offdata.qcow2' Size: 197120 Blocks: 272 IO Block: 4096 regular fileDevice: fd02h/64770d Inode: 2359300 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2016-01-29 05:07:24.747787726 -0500Modify: 2016-01-29 04:43:52.047787980 -0500Change: 2016-01-29 04:43:52.047787980 -0500
性能影响
通过falloc和full策略创建的磁盘的性能,要比另外两种策略创建的磁盘高的多,具体数据可以参考资料3.参考资料
1. Little more disk I/O perf. improvement with ‘fallocate’ing a qcow2 disk
2. Creating a Qcow2 virtual machine
3. qcow2-why not?
0 0
- KVM虚拟化:使用qemu-img创建qcow2虚拟磁盘的预分配策略分析
- Kvm/qemu-img创建qcow2镜像
- qemu-kvm 中断虚拟化代码分析
- qemu-kvm 中断虚拟化代码分析
- qemu-kvm 中断虚拟化代码分析
- kvm:qemu-kvm的qcow2磁盘的压缩
- 虚拟化qemu-img的简单用法。
- KVM虚拟化技术之使用Qemu-kvm创建和管理虚拟机
- KVM虚拟化技术之使用Qemu-kvm创建和管理虚拟机
- KVM虚拟化技术之使用Qemu-kvm创建和管理虚拟机
- qemu kvm 内存虚拟化
- qemu kvm 内存虚拟化
- qemu-kvm 中断虚拟化
- qemu-kvm 中断虚拟化
- 虚拟化之qemu-kvm
- qemu中KVM硬件虚拟化的初始化分析 (tcg、xen、kvm、qtest)(转)
- qemu+kvm 创建虚拟机并虚拟网卡
- qemu虚拟磁盘的管理
- IPV6地址数据库导出
- 2月1日-2月13日,10小时,剩3185小时
- 8VC Venture Cup 2016 - Elimination Round题解
- ubuntu下使用CGAL的pro文件
- 超详细Windows版本编译运行React Native官方实例UIExplorer项目(多图慎入)
- KVM虚拟化:使用qemu-img创建qcow2虚拟磁盘的预分配策略分析
- 终于对“基于原型”有了些理解
- 2016期许
- 完美解决 Linux 下 Sublime Text 中文输入
- Java eclipselink eclipselink.ddl-generation 的四种方式
- group by
- CSS中ID选择器只能用一次的理解
- Ubuntu下键盘输入错乱问题
- 第三方类库的下载