KVM虚拟化性能优化

可从以下几个方面优化KVM虚拟机,提高虚拟机的性能。

1、全虚拟化使用半虚拟化驱动(virtio)

virtio是KVM的半虚拟化机制,可提高IO性能,使用virtio可心显著提高KVM性能。virtio包括磁盘驱动和网卡驱动,下面是在XML文件中的使用方法:
磁盘配置文件:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/vm/testvm.img'/>
<target dev='vda' bus='virtio'/>
</disk>
网卡配置文件:
<interface type='bridge'>
<mac address='52:54:00:e3:b7:2d'/>
<source bridge='br0'/>
<model type='virtio'/>
<virtualport type='openvswitch'/>
</interface>
2、使用writeback缓存选项
针对客户机块设备的缓存,drive有一个子选项cache来设置缓存模式。两个主要的选项为writeback和writethrough,man手册是这样说的
By default, writethrough caching is used for all block device. This means that the host page cache will be used to read and write data but write notification will be sent to the guest only when the data has been reported as written by the storage subsystem.
Writeback caching will report data writes as completed as soon as the data is present in the host page cache. This is safe as long as you trust your host. If your host crashes or loses power, then the guest may experience data corruption.
writethrough写操作时不使用主机的缓存,只有当主机接受到存储子系统写操作通知时,宿主机才通知客户机写操作,也就是说这是同步的。而writeback则是异步的,它是当客户机有写请求时,先将数据写入宿主机缓存,而此时主机并未将数据真正写入存储系统。之后,待合适的时机主机会真正的将数据写入存储。显然writeback会更快。
这样使用writeback选项:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<source file='/vm/testvm.img'/>
<target dev='vda' bus='virtio'/>
</disk>

相关推荐