KVM guest caching modes

kvm中host和guest各自维护自己的page caches,使得内存中有两份缓存数据。host的缓存为page cache可以理解为读缓存,guest的缓存为disk write cache,可以理解为写缓存,前者优化读性能,后者优化写性能。如果disk write cache开启,那么一旦数据存在disk write cache中,写操作认为已经完成,即使真正的数据尚未在物理磁盘上。因此如果掉电,则存在数据丢失风险,数据完整性得不到保障。除非用户手动指定fsync(同步内存中所有已修改的文件数据到储存设备),或者disk wriet cache中的内容发生了变化,才会把数据写到物理磁盘上。

kvm/qemu支持以下缓存模式:

1.writethrough

qemu-kvm1.2版本下为默认缓存模式,the host page cache is enabled, but the disk write cache is disabled,数据完整性得到保障(不经过写缓存,而是直接写到物理磁盘),读操作性能较好,写操作性能较差。

2.writeback

qemu-kvm1.2版本以上为默认缓存模式,both the host page cache and the disk write cache are enabled,读写操作性能都很优异,唯一的缺点就是写操作的数据掉电可能丢失,无法保证数据完整性。

3.none

the host page cache is disabled, but the disk write cache is enabled. 读操作性能较差,写操作性能较好,同样数据完整性得不到保障。

4.unsafe

Caching mode of unsafe ignores cache transfer operations completely. 应该是guest发出的刷新缓存指令被忽视,意味着以牺牲数据的完整性来换取性能的提升。

5.directsync

两种缓存均关闭,读写操作性能较差。

cache mode host page cache disk write cache
writethrough on off
writeback on on
none off on
unsafe on ignore
directsync off off

reference:

https://www.suse.com/documentation/sles11/book_kvm/data/sect1_1_chapter_book_kvm.html

http://www.bubuko.com/infodetail-1070877.html

http://blog.chinaunix.net/uid-26000137-id-3957726.html

http://www-01.ibm.com/support/knowledgecenter/linuxonibm/liaat/liaatbpkvmguestcache.htm

http://blog.csdn.net/jollyjumper/article/details/12374415

posted on 2015-12-16 15:52  月流霜  阅读(1038)  评论(0编辑  收藏  举报