ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

QEMU-KVM BLOCK CACHE MODE

2021-10-14 14:59:39  阅读:266  来源: 互联网

标签:CACHE guest cache storage KVM mode device disk QEMU


Performance Tweaks

Jump to navigationJump to search

Contents

Introduction

This page is intended to be a collection of various performance tips/tweaks to help you get the most from your KVM virtual servers.

General

VirtIO

Use virtIO for disk and network for best performance.

  • Linux has the drivers built in since Linux 2.6.24 as experimental, and since Linux 3.8 as stable
  • FreeBSD has the drivers built in since 9.0
  • Windows requires the Windows VirtIO Drivers to be downloaded and installed manually

Disk Cache

Note: The information below is based on using raw volumes, other volume formats may behave differently.

Small Overview

Note: The overview below is dependent of the specific hardware used, i.e. a HW Raid with a BBU backed disk cache works just fine with 'writeback' mode, so take it just as an general overview.

ModeHost Page CacheDisk Write CacheNotes
nonedisabledenabledbalances performance and safety (better writes)
writethroughenableddisabledbalances performance and safety (better reads)
writebackenabledenabledfast, can loose data on power outage depending on hardware used
directsyncdisableddisabledsafest but slowest (relative to the others)
unsafeenabledenableddoesn't flush data, fastest and unsafest

cache=none seems to be the best performance and is the default since Proxmox 2.X.

     host don't do cache. 
     guest disk cache is writeback
     Warn : like writeback, you can loose datas in case of a powerfailure
     you need to use barrier option in your linux guest fstab if kernel < 2.6.37 to avoid fs corruption in case of powerfailure.  
     This mode causes qemu-kvm to interact with the disk image file or block device with O_DIRECT semantics, so the host page cache is bypassed 
     and I/O happens directly between the qemu-kvm userspace buffers and the          storage device. Because the actual storage device may report 
     a write as completed when placed in its write queue only, the guest's virtual storage adapter is informed that there is a writeback cache, 
     so the guest would be expected to send down flush commands as needed to manage data integrity.
     Equivalent to direct access to your hosts' disk, performance wise.

cache=writethrough

     host do read cache
     guest disk cache mode is writethrough
     Writethrough make a fsync for each write. So it's the more secure cache mode, you can't loose data. It's also the slower.
     This mode causes qemu-kvm to interact with the disk image file or block device with O_DSYNC semantics, 
     where writes are reported as completed only when the data has been committed to the storage device. 
     The host page cache is used in what can be termed a writethrough caching mode. 
     The guest's virtual storage adapter is informed that there is no writeback cache, so the guest would not need to send down 
     flush commands to manage data integrity. The storage behaves as if there is a writethrough cache.

cache=directsync

     host don't do cache.
     guest disk cache mode is writethrough
     similar to writethrough, a fsync is made for each write.
     This mode causes qemu-kvm to interact with the disk image file or block device with both O_DSYNC and O_DIRECT semantics, 
     where writes are reported as completed only when the data has been committed to the storage device, and when it is also desirable to bypass the host page cache.
     Like cache=writethrough, it is helpful to guests that do not send flushes when needed.
     It was the last cache mode added, completing the possible combinations of caching and direct access semantics.
    
cache=writeback     
     host do read/write cache
     guest disk cache mode is writeback
     Warn : you can loose datas in case of a powerfailure
     you need to use barrier option in your linux guest fstab if kernel < 2.6.37 to avoid fs corruption in case of powerfailure.
     
     This mode causes qemu-kvm to interact with the disk image file or block device with neither O_DSYNC nor O_DIRECT semantics,
     so the host page cache is used and writes are reported to the guest as completed when placed in the host page cache, 
     and the normal page cache management will handle commitment to the storage device. 
     Additionally, the guest's virtual storage adapter is informed of the writeback cache,
     so the guest would be expected to send down flush commands as needed to manage data integrity. 
     Analogous to a raid controller with RAM cache.

For read cache memory: try to add more memory in your guest, they already do the job with their buffer cache

cache=writethrough or directsync can be also quite fast if you have a SAN or HW raid controller with battery backed cache.

Using qcow2 backed disks and either cache=directsync or writethrough can make things slower.


some interestings articles :

cache mode and fsync : KVM storage performance and cache settings on Red Hat Enterprise Linux 6.2

OS Specific

Windows

USB Tablet Device

Disabling the USB tablet device in windows VMs can reduce idle CPU usage and reduce context switches. This can be done on the GUI. You can use vmmouse to get the pointer in sync (load drivers inside your VM). [1]

Use raw disk image and not qcow2

Consider using raw image or partition for a partition, especially with Microsoft SQL database files because qcow2 can be very slow under such type of load.

Trace Flag T8038 with Microsoft SQL Server

Setting the trace flag -T8038 will drastically reduce the number of context switches when running SQL 2005 or 2008.

To change the trace flag:

  1. Open the SQL server Configuration Manager
  2. Open the properties for the SQL service typically named MSSQLSERVER
  3. Go to the advanced tab
  4. Append ;-T8038 to the end of the startup parameters option

For additional references see: Proxmox forum

Do not use the Virtio Balloon Driver

The Balloon driver has been a source of performance problems on Windows, you should avoid it. (see [SOLVED] Hyper-Threading vs No Hyper-Threading; Fixed vs Variable Memory | Proxmox Support Forum for the discussion thread)

标签:CACHE,guest,cache,storage,KVM,mode,device,disk,QEMU
来源: https://blog.csdn.net/yiyeguzhou100/article/details/120764039

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有