KVM I/O slowness on RHEL 6

2024-03-15 03:20
文章标签 rhel kvm slowness

本文主要是介绍KVM I/O slowness on RHEL 6,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载:http://www.ilsistemista.net/index.php/virtualization/11-kvm-io-slowness-on-rhel-6.html?limitstart=0

Over one year has passed since my last virtual machine hypervisor comparison so, in the last week, I was preparing an article showing a face to face comparison between RHEL 6 KVM technologies versus Oracle VirtualBox 4.0 product. I spent several days creating some nice, automated script to evaluate these two products under different point of views, and I was quite confident that the benchmark session would be completed without too much trouble. So, I installed Red Hat Enterprise Linux 6 (license courtesy of Red Hat Inc. - thank you guys!) on my workstation and I begin the virtual images installation.

However, the unexpected happened: using KVM, a Windows Server 2008 R2 Foundation installation took almost 3 hours, while normally it should be completed in about 30-45 minutes. Similarly, the installation of the base system anticipating the “real” Debian 6.0 installation took over 5 minutes, when normally it can be completed in about 1 minute. In short: the KVM virtual machines were affected by awfully slow disk I/O subsystem. In previous tests, I saw that KVM I/O subsystem was a bit slower, but not by so much; clearly, something was impairing my KVM I/O speed. I tried different combination of virtualized disk controllers(IDE or VirtIO) and cache settings, but without success. I also changed my physical disk filesystem to EXT3, to avoid any possible, hypothetical EXT4 speed regression, but again with no results: the KVM slow I/O speed problem remained.

I needed a solution – and a real one: with such awfully slow I/O, the KVM guests were virtually unusable. After some wasted hours, I decided to run some targeted, systematic tests regarding VM image formats, disk controllers, cache settings and preallocation policy. Now that I find the solution and I run my KVM guest at full speed, I am very happy – and I would like to share my results with you.

Testbed and methods

First, let me describe the workstation used in this round of tests; system specifications are:

  • CPU: Core-i7 860 (quad cores, eight threads) @ 2.8 GHz and with 8 MB L3 cache

  • RAM: 8 GB DDR3 (4x 2 GB) @ 1333 MHz

  • DISKS: 4x WD Green 1 TB in software RAID 10 configuration

  • OS: Red Hat Enterprise Linux 6 64 bit

The operation system was installed with “basic server” profile and then I selectively installed the various other software required (libvirtd, qemu, etc). Key systems software are:

  • kernel version 2.6.32-71.18.1.el6.x86_64

  • qemu-kvm version 0.12.1.2-2.113.el6_0.6.x86_64

  • libvirt versio 0.8.1-27.el.x86_64

  • virt-manager version 0.8.4-8.el6.noarch

As stated before, initially all host-system partitions were formatted in EXT4, but to avoid any possible problem related to the new filesystem, I changed the VM-storing partition to EXT3.

To measure guest I/O speed, I timed the Debian 6.0 (x86_64 version) basic system installation. This is the process that, during Debian installation, immediately follow the partitions creation and format phase.

Let me thanks again Red Hat Inc. - and especially Justin Clift – to give me a free RHEL 6 license.

OK – I know that you want to know why on earth KVM I/O was so slow. However, first you had to understand something about caching and preallocation policies.


On caching and preallocation

Note: in this page, I try to condensate in very little space some hard-to-explain concepts, so I had to do some approximations. I ask the expert reader to forgive me for the over-simplification.

Normally, a virtual guest system use an host-side file to store its data: this file represent a virtual disk, that the guest use as a normal, physical disk. However, from the host view this virtual disk is a normal data file and it may be subject to caching and preallocation.

In this context, caching is the process to “hide” some disk-related data to physical RAM. When we use that cache to storein RAM only data previously read from the disk, we speak about a read cache, or write-through cache. When we store in RAM some data that will be later flushed to disk, we speak abut a write cache, or write-back cache. A write-back cache, by caching write request in the fast RAM, has higher performance; however, it is also more prone to data loss than a write-through one, as the latter only cache read requests and immediately write to disk any data.

As disk I/O is a very important parameter, Linux and Windows o.s. generally use a write-back policy with periodic flush to the physical disk. However, when using an hypervisor to virtualize some guest system, you can effectively cache things twice (one time in the host memory and another time in the virtual guest memory), so is often better to disable host-based caching on the virtual disk file and to let the guest system to manage its own caching. Moreover, a host-side write-back policy on virtual disk file significantly increase the risk of data loss in case of guest crash.

KVM let you choose one of these three cache policy: no caching, write-through (read only cache) and write-back (read and write cache). It also has a “default” setting that effectively is an alias for the write-through one. As you will see, pick the right caching scheme is a crucial choice for fast guest I/O.

Now, some words about preallocation: this is the process to better prepare the virtual disk file to store the data written by the guest system. Generally, preallocate a file means to fill it with zeros, so that the host system had to reserve in advance all the disk space assigned to the guest. In this manner, when the guest try to write to the virtual disk, it never waits for the host system to reserve the required space. Some time, preallocation does not fill the target file with zeros, but only prepare some its internal data structure: in this case, we talk about metadata preallocation. RAW disk format can use full preallocation, while QCOW2 actually use metadata preallocation (there are some patches that force full preallocation, but are experimental ones).

Why speak about caching and preallocation? Because the super-slow KVM I/O speed really boil down to this two parameters, as we are going to see.

RAW image format performance

Let's begin with some tests regarding the most basic disk image format – the RAW format. RAW images are very fast, but they miss a critical feature: the possibility to take real, fast snapshot of the virtual disk. So, they can be used only in situations were you not need a real snapshot support (or you have snapshotting capability at the filesystem level – but this is another story).

How the RAW format performs, and how caching affect the results?

RAW image performance

As you can see, as long you stay away from write-through cache, RAW image have very high speed. Note that in RAW image with no caching or write-back policy, preallocation only have a small influence.

What about the much more feature-rich QCOW2 format?

QCOW2 image format performance

The QCOW2 format is the default QEMU/KVM image format. It has some very interesting features, as compression and encryption, but especially it enable the use of real, file-level snapshots.

But how it performs?

QCOW2 image performance

Mmm... without metadata preallocation, it performs very badly. Enable metadata preallocation, stay away from write-through cache and it perform very well.

To better compare it to the RAW format, I made a chart with the no-caching RAW and QCOW2 results:

RAW vs QCOW2 performance

While without metadata preallocation the QCOW2 format is 5X slower then RAW, with enabled metadata preallocation the two are practically tied. This prove thatwhile RAW format is primarily influenced by caching setting, QCOW2 is much dependent on both the preallocation and caching policies.

The influence of the virtualized I/O controller

Another important thing to check is the influence of the virtualized I/O controller that is presented to the guest. KVM let you use not only the default IDE virtual controller, but also a new, paravirtualized I/O controller called VirtIO. This virtualized controller promise better speed and less CPU usage.

How it affect the results?

IDE vs VirtIO controller performance

As you can see, the write-through scenario is the most affected one, while with the no-caching and write-back policies it has a lesser effect.

This does not means that the VirtIO is an unimportant project: the scope of this test was only to be sure that it don't comport any I/O slowness. In a following article I will analyze this very promising driver in a much more complete manner.

I/O slowness cause: bad default settings

So, we can state that to obtain good I/O throughput from the QCOW2 format, two conditions must be met:

  • don't use a write-through cache

  • always use metadata preallocation.

However, using the virt-manager GUI interface that is normally used to create virtual disks and guest systems on Red Hat and Fedora, you can not enablemetadata preallocation on QCOW2 files. While the storage volume creation interface let you specify if you want to preallocate the virtual disk, this function actually only workwith RAW files; if you use a QCOW2 file it does nothing.

To create a file with metadata preallocation, you must open a terminal and issue the “qemu-img create” command. For example, if you want to create a ~10 GB QCOW2 with metadata preallocation, you must issue the command “qemu-img create -f qcow2 -o size=10000000000,preallocation=metadata file.img”.

Moreover, the default caching scheme is the write-through one. While generally the guest creation wizard correctly disable host-side cache, if you later add any virtual disk to the guest, often the disk is added with the “default” caching policy – a write-through one.

So, if you are using Red Hat Enterprise Linux or Fedora Linux as the host operating system for you virtualization server and you plan to use the QCOW2 format, remember to manually create preallocated virtual disk files and to use a “none” cache policy (you can also use a “write-back” policy, but be warned that your guests will be more prone to data loss).

Conclusions

First of all, don't let me wrong: I'm very exited about KVM and libvirt progresses. Now we have not only a very robust hypervisor, but also some critical paravirtualized drivers, a good graphical interface and excellent host / guest remote management capabilities. I would publicly thanks all the talented guys involved in the realization of these great and important projects – thank you boys!

However, it's a shame that the current virt-manager GUI interface don't permit to perform metadata preallocation on QCOW2 image format, as this image is much more feature-rich than the RAW one. Moreover, I would like to see not only the guest creation wizard, but all the guest editing windows to always default to no cache policy for virtual disk, but it is a secondary problem: it is not so difficult to manually change a parameter...

The first problem – no metadata preallocation on QCOW2 – is way more serious, as it can not be overcomed without resort to the command line. This problem should really be corrected as soon as possible. In the meantime, you can use the workaround described above, and remember to always check your virtual disk caching policy – don't use the “default” or “write-through” settings.

I hope than this article can help you to get the max from the very good KVM, libvirt and related projects.



这篇关于KVM I/O slowness on RHEL 6的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/810630

相关文章

使用 docker 部署 kvm 图形化管理工具 WebVirtMgr

文章目录 @[toc]前提条件镜像构建启动 webvirtmgr创建其他 superuser配置 nginx 反向代理和域名访问绑定 kvm 宿主机local sockettcp 连接 虚拟机创建创建快照虚拟机克隆删除虚拟机 kvm 官方提供了以下这些图形化管理,license 这块也提示了是商业版(Commercial)的还是哪个开源协议的,或者免费的范围这边主要的需求就是有个 k

KVM挂载本地硬盘

KVM挂载本地硬盘 改用了deepin,但说真的,部分软件真的不好用,还有bug… 最后还是用kvm部署了一台win10虚拟机,并准备把一个本地硬盘挂载到这台虚拟机上 编辑虚拟机的配置文件 virsh edit win10 增加以下内容 <disk type='block' device='disk'><driver name='qemu' type='raw'

KVM使用NAT联网

KVM使用NAT联网 KVM虚拟机启动后发现还是无法联网,通过一下修改运行时内核参数调整实现联网。具体为编辑/etc/sysctl.conf文件,修改net.ipv4.ip_forward = 0为net.ipv4.ip_forward = 1 $ cat /etc/sysctl.confnet.ipv4.ip_forward = 1 最后运行sysctl -p命令使配置立

【虚拟化】KVM常用命令操作(virsh磁盘管理)

目录 一、KVM概述 1.1 KVM工具栈 1.2 libvirt架构概述 1.3 KVM磁盘格式介绍 1.4 KVM磁盘操作常见语法 1.5 qemu-img命令简介 1.6 libguestfs安装 二、虚拟机磁盘管理 2.1 查看虚拟机磁盘 2.2 创建虚拟机磁盘 2.3 扩容磁盘容量 2.4 查看虚拟机存储状态 2.5 快照 2.6 虚拟磁盘格式转化

BMC lighttpd kvm数据分析(websocket)

1.说明 lighttpd源码: https://github.com/lighttpd/lighttpd1.4.gitlighttpd wiki: https://redmine.lighttpd.net/projects/lighttpd/wiki/libfcgi: https://github.com/toshic/libfcgi/tree/master 注意: 本章的代码仓库: ht

KVM 高级功能部署

虚拟机迁移         应用场景                 宿主机负载比较高时,可迁移走部分虚拟机                 迁移虚拟机集中于一台,节约资源                 升级宿主机硬件时,可先迁移走再进行升级                 可实现跨地域的远程迁移         虚拟机迁移                 静态迁移:造成一端时间的

KVM逃逸-嵌套虚拟化-corCTF 2024-trojan-turtles 复现

文章目录 参考KVM(Kernel-based Virtual Machine)KVM 的概念KVM 的实现ioctl 命令KVM API 文档 KVM 的编译选项QEMU 与 KVM 的结合工作原理 嵌套虚拟化(虚拟机里再建一个虚拟机)嵌套虚拟化的系统中虚拟机执行vmx指令(对虚拟机中的虚拟机的相关操作)镜像文件qcow2/上传exp/调试漏洞diff相关源码和结构体漏洞点 思路vmx相

在容器 (podman) 中运行虚拟机 (QEMU/KVM, libvirt)

虚拟机 (virtual machine) 是一种计算机的虚拟化技术, 容器 (container) 是一种更轻量级的虚拟化技术. 虚拟机可以套娃 (嵌套, nest), 也就是在虚拟机中运行虚拟机. 容器也可以套娃, 比如 Docker in Docker, Podman in Podman, Podman in Docker 等. 容器和虚拟机也可以互相套娃, 比如在虚拟机中运行容器, 是可以

QEMU/KVM 虚拟机显卡透传 (vfio-pci)

首发日期 2024-08-22, 以下为原文内容: 本文介绍将 PCIE 设备 (显卡) 透传给 QEMU/KVM 虚拟机的一种方法, 基于 Linux 内核的 vfio-pci 功能. 透传 (pass through) 之后, 虚拟机内可以直接操作 (使用) 显卡硬件, 就像物理机那样, 几乎没有虚拟化的性能损失. 这里是 穷人小水滴, 专注于 穷人友好型 低成本技术. 相关文章

kvm压缩虚拟机磁盘

kvm压缩虚拟机磁盘 kvm通过图形界面创建虚拟机后,如果指定的磁盘为200G,创建后查看物理位置文件大小为200G,注意,这里创建的时候并没有勾选“立即分配磁盘空间”。 出现以上原因会造成虚拟机安装完操作系统或者其他软件后,物理位置虚拟机文件大小会超过200G!明显是不合理的。如果用图形化界面创建虚拟机后,会造成“镜像空洞”。 解决方案: 1.创建的时候提前在需要保存的路径使用命令先创建镜