我有一个运行8个虚拟机的KVM主机(
Linux 3.14.32).它们被过度配置(为它们分配的内存大于主机上的可用物理内存).然而,它们仅消耗大约85%的物理内存,这应该为缓存留出一些空间.但是,主机上的所有内容都是非常缓慢的,并且几乎没有内存用于缓存的免费报告:
total used free shared buffers cached Mem: 32224 26767 5457 0 0 3 -/+ buffers/cache: 26762 5461 Swap: 1021 414 607
如您所见,浪费了5.5 GB.关闭虚拟机后,一切恢复正常 – 内核使用260M的缓存.
的/ proc / meminfo中:
MemTotal: 32997976 kB MemFree: 5543224 kB MemAvailable: 5584332 kB Buffers: 2612 kB Cached: 83876 kB SwapCached: 72524 kB Active: 24721804 kB Inactive: 2214632 kB Active(anon): 24675412 kB Inactive(anon): 2175048 kB Active(file): 46392 kB Inactive(file): 39584 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 1046520 kB SwapFree: 622068 kB Dirty: 84 kB Writeback: 4 kB AnonPages: 26806104 kB Mapped: 28436 kB Shmem: 488 kB Slab: 60024 kB SReclaimable: 25076 kB SUnreclaim: 34948 kB KernelStack: 3232 kB PageTables: 62212 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 17545508 kB Committed_AS: 53713960 kB VmallocTotal: 34359738367 kB VmallocUsed: 431560 kB VmallocChunk: 34359138492 kB HardwareCorrupted: 0 kB DirectMap4k: 9728 kB DirectMap2M: 33536000 kB
我将swappiness设置为0. VM的磁盘映像位于LVM上,缓存为= writeback.
解决方法
建议在使用RAW设备时绕过缓存(cache = none).这使用O_DIRECT模式,因此绕过主机页面缓存,I / O直接在qemu-kvm用户空间缓冲区和存储设备之间进行.
QEMU also supports a wide variety of caching modes. If you’re using
raw volumes or partitions,it is best to avoid the cache completely,
which reduces data copies and bus traffic.
参考:Tuning KVM