Change the Windows virtual machine default disk type for the KVM platform in Cloudstack to Virtio

Source: Internet
Author: User
Tags cloudstack

Objective

The purpose of this article is to solve the problem of poor performance of Windows virtual machines when using Cloudstack (Cloudplatform), based on the KVM virtualization platform.

This performance, mainly refers to disk IO and network card performance.


Related documents

Since the CS document only emphasizes the concept of PV, different hardware interface types are distinguished according to PV mode. So we collect some links for literacy.

About PV ( paravirtualization-Semi-virtualized ) mode, see:

Http://www.rackspace.com/knowledge_center/article/choosing-a-virtualization-mode-pv-versus-pvhvm

Http://wiki.xenproject.org/wiki/Paravirtualization_%28PV%29

http://zh.wikipedia.org/wiki/%E8%99%9A%E6%8B%9F%E5%8C%96

http://www.ibm.com/developerworks/cn/cloud/library/cl-hypervisorcompare-kvm/


In addition, for virtio, you can view the following links:

Http://www.linux-kvm.org/page/Virtio

Http://smilejay.com/2012/11/virtio-overview/(a brother who is not worth knowing about KVM)


Background

In two project summaries (CS+KVM), the customer mentions Windows performance is insufficient, but as to which aspect performance, does not elaborate, too many. User Feedback In a nutshell: Virtual machines run too slowly.

More than 10 blade servers, 30T SAN storage, will be nearly million G memory. Just ran a few 100 virtual machines, still slow, the way it is.

Come on, slow down, we'll have to find the reason.


Preliminary analysis

I this person is relatively superficial, the first thought is the disk IO is not, this is the most direct to let customers think the system is slow (to eliminate the problem of insufficient memory).

After examination, found that:

1. The Windows virtual machine created with CS, the disk type of the system disk is the IDE (you run the IDE interface Windows 2008R2, also requires performance, this is the way). All data disks created in addition to the system disk, the interface type is all Virtio.

As for how to view the hard disk interface type, you can open the Device Manager in the system-view the disk drive type. Or, in a KVM host, use "Virsh Edit virtual machine name" to find disk-related configurations. Direct use of Virt-manager is also possible.

2. The Linux (common release) virtual machine created with CS, the system disk and the data disk hard disk interface type are all Virtio.


Here, I attributed the problem to: in CS, based on the KVM platform, the Windows virtual machine created by the system disk interface type is IDE, which is the main cause of slow performance. The optimal disk interface type should be virtio.

Note:

Some people will say that you are too arbitrary, well, my company based on KVM Desktop virtualization products, at that time with the VMware View,xendesktop do performance comparable (are the default configuration), run Win7 and Win2008, in the case of general load, rarely run slow problem. So, based on the KVM platform, running Windows system, the effect is not too bad. Of course, in addition to the hard disk interface using the Virtio, but also made other tuning.

But, knowing KVM friend, should know Kvm+virtio is a pair of good base friend. As for the performance test comparison between the IDE and the Virtio, I will have the opportunity to come up with the specific test data later.


The problem seems to be simple, the IDE interface of the system disk is replaced by the Virtio interface.


Take a look at what system types are indicated in the official documentation, and the default system disk interface type is virtio:

  • (KVM only) If you choose a OS that's pv-enabled, the VMs created fro M this ISO would have a SCSI ( virtio " Span style= "Background-color:rgb (252,252,252);" >) root disk. If the OS is not pv-enabled, the VMs would have the IDE root disk. The pv-enabled types is:

    • Fedora

    • Fedora

    • Fedora all

    • Fedora

    • Fedora 9

    • Other PV

    • Debian gnu/linux

    • CentOS 5.3

    • CentOS 5.4

    • CentOS 5.5

    • Red Hat Enterprise Linux 5.3

    • Red Hat Enterprise Linux 5.4

    • Red Hat Enterprise Linux 5.5

    • Red Hat Enterprise Linux 6

It is learned from the above information that the operating system with PV mode enabled, the root disk, which is the system disk, will use the Virtio mode by default and the IDE mode will be used by default if the operating system with PV mode is not enabled .

Careful you will also find that the above list, almost all of the Linux system, in addition to the "other PV" this geek (in fact, there is "Windows PV", as for why, perhaps the people who write documents lazy, perhaps, later).

Why almost all Linux systems, the official said the sentence:

(KVM only) all VMs is required to support the Virtio drivers. These drivers is installed in all Linux kernel versions 2.6.25 and greater. The administrator must set config_virtio_balloon=y in the VIRTIO configuration.


All virtual machines require support for virtio drivers, while the Virtio drivers for Linux platforms are integrated into 2.6.25 or later kernels. This means that Linux can directly identify Virtio interface devices. While Virtio is an abstract API interface on top of hypervisor, it is a semi-virtualized driver that Virtio works with hypervisor to provide excellent performance. In other words, virtio is not a standard interface type. You have seen virtio hard drive when you buy hard disk. Therefore, it is also understandable that this driver is not integrated in Windows. This is also why the system disk interface type for virtual machines that are not enabled for PV mode is IDE.


Is it not windows that can't use Virtio? Of course not. People say, as long as the PV mode enabled operating system, the system disk will be virtio. So CS provides 2 of the operating system types in PV mode other PV and Windows PV. Actually only other PV this kind. Because of the code, Windows PV is eventually categorized as other PV.

Of course, the Virtio driver in the Windows system needs to be installed on its own.


Preliminary solution

Here, the problem is initially resolved, that is, in CS, the Windows-related virtual machines and templates in the operating system type, defined as: Windows PV or other PV.

The system disk type can be used Virtio as long as the operating system type of PV mode is selected.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/43/A3/wKioL1Pbm3Xxs9MKAACusWfkZhk877.jpg "style=" float: none; "title=" Pv-mode-1.png "alt=" Wkiol1pbm3xxs9mkaacuswfkzhk877.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/43/A3/wKiom1PbmlywrOqBAAEBRUxMzOI423.jpg "style=" float: none; "title=" Pv-mode-2.png "alt=" Wkiom1pbmlywroqbaaebruxmzoi423.jpg "/>


If so you think it should be happy, then I will hehe.

In line with no Zuo no die, why do you try the principle, I still want to find the fundamental solution.


In-depth analysis

First think about why CS defines the operating system that enables PV and does not enable PV mode, why the Windows virtual machine system disk based on the KVM platform in CS does not directly use the Virtio interface type. Instead of the second block except for the system disk, the third disk uses the Virtio interface type? Do CS developers not know that this performance will be improved in a qualitative way?


I think:

1. Enable PV and do not enable PV, at the CS code level, the most fundamental to solve is to distinguish between the root disk interface type using the IDE or Virtio (for the KVM platform)

The Windows virtual machine system disk in the 2.KVM platform uses the IDE instead of using the Virtio interface directly, actually to facilitate the deployment of a KVM virtual machine with CS. Why, if the Windows virtual machine also uses the Virtio interface type disk drive by default, what problem do you encounter? You will find that the virtual machine failed to start. Or when you find a disk drive in the same step when you install a Windows virtual machine from ISO, Windows cannot find the disk drive. What will you do at this time?

When installing VISTA,WIN7,2008.WIN8 and other high-version windows, in the hard drive that step, you are allowed to load drive drivers via ISO. It is also true that the virtio ISO format driver installation package is available, this time you can eject the installation ISO, then attach the Virtio driver iso, install the driver after the drive and then eject the ISO, again the attachment system ISO. Well, the system can identify the disk drive. What about the 2003, XP, you have to insert a floppy disk to install the driver, what do you do? Does the CS offer a floppy drive?

3. The system disk is an IDE interface, and the other disks are Virtio, as stated above. First of all, you can install the system, and then installed Virtio Drive. Regardless of the xp,2003, or the win7,2008,windows system can recognize the IDE interface of the hard disk, waiting for you to install the system, and then the data disk installation Virtio driver.

4. Developers are based on the above considerations, so design it. Of course you can after the installation of Virtio disk and Nic driver, shutdown, the virtual machine operating system type changed to Windows PV mode, and then power on, the virtual machine will use Virtio as the system disk interface type. Or you can convert a virtual machine that is installed with a virtio drive into a template and set the operating system type to Windows PV, so you don't have to worry about driving problems later with the virtual machines created with that template.

5. Of course, if you are outside of CS, you have completed the KVM platform Windows virtual Machine template, and directly joined the Virtio driver, and then import CS. Then this template OS type, you also need to set the Windows PV mode.


However, I am currently in a project where it is not convenient to modify the operating system type of a virtual machine or template to Windows PV.

One more virtual machine, statistics inconvenient, all Windows virtual machines are Windows PV mode ... Secondly, in the spirit of breaking the casserole, from the code level, directly find the root cause, and modify it. So you don't have to set up annoying Windows PV.

Of course, the premise is that all of the drivers (disk drives + network cards) of Virtio have been added to my template.


Parsing code:


On the official GitHub Https://github.com/apache/cloudstack of CS

Search for the following keywords: vritio,windows pv,other pv,ide, etc., free to play.


After some research, find the following two files:

Https://github.com/apache/cloudstack/blob/afc188cb5c72e316975799c95529e8692ddcb94b/plugins/hypervisors/kvm/src /com/cloud/hypervisor/kvm/resource/kvmguestosmapper.java


Https://github.com/apache/cloudstack/blob/7542ffc48282ff703fdb586ce447091260ae3c02/plugins/hypervisors/kvm/src /com/cloud/hypervisor/kvm/resource/libvirtcomputingresource.java



1. First look at Kvmguestosmapper.java, which defines the list of supported operating systems in the KVM platform:

public class kvmguestosmapper {    private static final  Logger s_logger = logger.getlogger (kvmguestosmapper.class);     private  static Map<String, String> s_mapper = new HashMap<String,  String> ();    static {       ......         s_mapper.put ("windows server 2008  (64-bit)",  "Windows  server 2008 ");         s_mapper.put (" Windows Server  2008 R2  (64-bit) ", " windows server 2008 ");         s_mapper.put ("windows xp  (64-bit)",  "Windows xp");         s_mapper.put ("windows nt 4",  "Windows nt");         s_mappEr.put ("windows 3.1",  "windows 3.1");         s_ Mapper.put ("WINDOWS&NBSP;PV",  "OTHER&NBSP;PV");         s_ Mapper.put ("freebsd 10  (32-bit)",  "freebsd 10");         s_mapper.put ("freebsd 10  (64-bits",  "freebsd 10");         s_mapper.put ("other pv  (32-bit)",  "OTHER&NBSP;PV");         s_mapper.put ("other pv  (64-bit)",  "OTHER&NBSP;PV");        ......    }


As you can see, this table corresponds to the operating system type, in S_mapper.put, there are two fields: S_mapper.put (operating system version, operating system type);

One operating system type, including multiple operating system versions, note that we said that Windows PV is also categorized as other PV.


2. Again to view the Libvirtcomputingresource.java file.

Find Virtio See the following information:

Made a judgment that if the operating system type belongs to guestpvenabled, the disk bus is returned as Virtio, and if not, the IDE is used.

Private Diskdef.diskbus Getguestdiskmodel (String platformemulator) {if (isguestpvenabled (Platformemulator)) {        return DiskDef.diskBus.VIRTIO;        } else {return DiskDef.diskBus.IDE; }    }


Then find guestpvenabled, find a class, the type, defined, those system types belong to guestpvenabled, you can see that most of the Linux system and other PV are categorized as guestpvenabled:


Boolean isguestpvenabled (String guestosname)  {         if  (guestosname == null)  {             return false;        }         if  (Guestosname.startswith ("Ubuntu")  | |  guestosname.startswith ("fedora 13")  | |  guestosname.startswith ("fedora 12")  | |  guestosname.startswith ("fedora 11")  | |                  Guestosname.startswith ("fedora 10")  | |  guestosname.startswith ("fedora 9")  | |  guestosname.startswith ("centos 5.3")  | |  guestosname.startswith ("centos 5.4")  | |                  Guestosname.startswith ("centos 5.5")  | | guestosname.startswith ("CentOS")  | |  guestosname.startswith ("Fedora")  | |                  Guestosname.startswith ("red hat enterprise linux 5.3")  | |  guestosname.startswith ("red hat enterprise linux 5.4")  | |                  Guestosname.startswith ("red hat enterprise linux 5.5")  | |  guestosname.startswith ("red hat enterprise linux 6")  | |  guestosname.startswith ("Debian gnu/linux")  | |                  Guestosname.startswith ("freebsd 10")  | |  guestosname.startswith ("OTHER&NBSP;PV"))  {             return true;        } else {             return false;        }


Complete solution:

Thus, we have the idea of modifying the Isguestpvenabled class (Libvirtcomputingresource.java), or modifying the operating system counterpart (Kvmguestosmapper.java).

However, modifying these two files results in a different effect:

1. If you modify the Isguestpvenabled class in the Libvirtcomputingresource.java file, in the class, add the operating system type. Note that this is the operating system type, not the operating system version. For example, add the Windows 2008 operating system all versions are PV mode, to join guestosname. StartsWith ("Windows Server"), in which case the PV settings are applied to all versions under 2008.

2. If you modify Kvmguestosmapper.java, you can define one of the operating system versions as PV mode. For example, define the R2 as PV mode,

Will:

S_mapper.put ("Windows Server R2 (64-bit)", "Windows Server 2008");

Modified to:

S_mapper.put ("Windows Server R2 (64-bit)", "other PV");


This will not affect Windows Server (32-bit) and Windows Server (64-bit) versions.


After the modification, you need to compile the file (it seems necessary to compile the CS code all over again, compile a single file failed). Will get Libvirtcomputingresource.class or kvmguestosmapper.class files.


Then use tools such as WinRAR to open the KVM node:/usr/share/cloudstack-agent/lib/cloud-plugin-hypervisor-kvm-4.2.1.jar file, Replace the resulting class file with the old file in the \com\cloud\hypervisor\kvm\resource directory. Save.


Then replace the modified jar file back to the KVM host and restart the Cloudstack-agent service. Then you create a new Windows Server R2 (64-bit) virtual machine, and you find that the Virtio disk drive and the NIC adapter are used by default.


A Windows Server R2 (64-bit) virtual machine that already exists needs to be shut down and then powered on. Before the Virtio configuration is applied. Note In KVM virtualization, the shutdown, restart, and restart of the virtual machine is different.


This method, because it modifies the code directly, adds the required operating system type or specific version to the Guestpvenabled class, so you do not need to specify the operating system type Windows PV in CS. Fundamentally solve the problem.


Disadvantages of:

Each upgrade requires a compilation to replace the file, unless it is installed with its own compiled installation package.


This article is from the "Systems" blog, so be sure to keep this source http://systems.blog.51cto.com/2500547/1533981

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.