What kind of virtual machine should I use? (1)

Source: Internet
Author: User

The Virtualization of 80x86 machines has been too hot recently. Not only have Microsoft joined the war corps, but there are also a bunch of startups to scream. What kind of virtual machine is better? This article tries to summarize some of my experiences.

Good is a relative concept. Virtual machines on the market not only come from different companies on the surface, but also have varied core implementation technologies and application scenarios. On the one hand, you need to know what virtualization technology can bring to you. On the one hand, you need to know what you need, on the other hand, you need to know what virtual machines are used to achieve your goal, and what virtualization strategy is best for you. This process is the selection process. I hope that after reading this article, you will have a rough understanding of the 80x86 virtualization technology and its development status. Let's skip the text about the advantages of virtualization technology. Let's look at how virtual machines are implemented and classify them on the market.

If we re-implement a virtual machine, there are several options. The most direct choice is to use software to simulate hardware. Write a simple while loop to simulate a CPU job:

 

   code highlighting produced by actipro codehighlighter (freeware) 
http://www.CodeHighlighter.com/
--> while ( true ) {
var instr = getnextinstruction ();
switch (instr) {
case XXX:
// do XXX
case halt:
return ;
}< BR >}< br>

This is also the implementation principle of common game machine simulator. Coupled with software simulated peripherals, such as the motherboard, hard disk or something. This type of virtual machine is called enumlator.

 

Emulator has the biggest advantage of being independent of the underlying hardware. You can simulate a memory 2cpu on 586. This is especially useful for engineers who develop software with special hardware. Because of the low efficiency of the simulator, it can only be reduced to debugging tools. To improve performance, compilation is introduced to replace interpretation execution. The famous JIT (JVM is also a virtual machine) is one of them, and qemu is a virtual machine that implements bytecode compilation in the 80x86 field. However, this is more of a kind of runtime optimization technology, which does not fundamentally change its implementation, nor fundamentally change the execution efficiency.

The fundamental solution is to directly use the CPU of the host machine instead of simulating the CPU through software loops. In addition, the memory does not need to be simulated, or you can directly use the host machine's CPU for execution. This is the virtualization technology.

Memory is relatively easy to implement. Generally, there is a ing table for ing between virtual memory and actual memory address. This kind of memory virtualization is widely used and very mature technology. The Virtualization Technology proposed by AMD later further accelerates the table ing on the hardware layer.

The difficulty lies in the 80x86 ring structure. From ring0 to ring3, the permissions are decreased sequentially. In actual use, Windows only uses RING 0 and ring 3. Guest OS needs to run on the Ring 0 level of 80x86. However, the host OS is already at the ring 0 level of 80x86. Virtual Machine as a user applicationProgramOnly the ring3 privilege. The CPU in this status cannot meet the needs of the guest OS. This is why the 80x86 virtualization technology is hard to implement. Therefore, at the beginning, the guest operating system must be modified to achieve virtualization. In the beginning, xen was implemented in this way. Guest OS is a specific version of Linux after the patch is installed. Obviously, Windows Kernel cannot be patched. Therefore, para-virtualization alization is only suitable for openingSource codeOr the OS supported by the vendor.

However, as hardware advances. Intel proposed VT-D technology, amd proposed Pacifica technology. Although the names are different, the result is an additional layer above ring0. This allows the virtual machine to cheat the guest operating system and make it think that it is running on a common CPU. So full-virtualization will appear. To take advantage of these new CPU technologies, they all have a driver that is directly close to the hardware, not entirely based on Host OS.

The pursuit of human beings is endless. After fully virtualized virtual machines are used in practice, especially for high-load servers, performance problems will soon be exposed. The CPU speed is good and fast. The problems are concentrated on the memory consumption, I/O operation speed, and the CPU usage.

When one machine can install multiple virtual machines, people want to install as many virtual machines as possible to improve the overall resource utilization. However, due to memory restrictions, it is difficult to increase the number of virtual machines with a single server load, while the memory utilization is not high. Assume that each virtual machine is allocated 1 GB of memory, and the memory usage is 60%, then each virtual machine has MB of memory available. 4 virtual machines are installed on a 4G machine, and GB of idle memory is available. Therefore, five virtual machines are useless. However, because each virtual machine has its own surplus memory, just in case, the overall utilization rate does not come. To solve this problem, the virtual machines in large factories have many optimizations, such as deflate and ballooning. These optimizations usually involve some special drivers installed on the guest operating system to control the memory allocation of the guest operating system (or directly supported by the Linux kernel ).

I/O speed and CPU usage problems are caused by software-simulated peripherals, especially hard disks and NICs. The solution naturally tries its best to use real hardware. You can install an optimized driver on the guest OS. However, to further improve the performance, it is stuck in the DMA (Direct Memory Access, Direct Memory Access) technology. DMA is an I/O optimization technology that allows the CPU to directly access the memory without being involved in I/O. Because the memory address is virtualized, while DMA is hardware controlled, it cannot be modified to know the address after virtualization. The solution to this problem still relies on Intel and AMD. We believe that in the future there will be virtual I/O CPUs that support hardware support. However, we have been waiting for a long time since the planned release.

At this time, due to efficiency reasons, full-virtualization alization becomes para-virtualization alization again. Because the driver is also a change to the guest OS, it is no longer transparent virtualization. If the corresponding operating system does not have a driver, you will not be able to use it (or you will not be able to use the optimized peripherals and memory ). This is another problem for Windows. So far, KVM has not released Windows hard drive virtio drivers, resulting in low efficiency.

Today we are talking about the hardware genre, and tomorrow we will continue to talk about the software genre. To be continued ......

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.