Introduction to KVM/Qemu Virtualization Technology

Introduction 1    

KVM virtual machine is based on linux kernel virtualization, which has been integrated in various major distribution versions of linux since linux 2.6.20. It uses linux's own scheduler for management, so compared to xen , its core source code is very small. KVM virtualization requires hardware support (such as intel VT technology or AMD V technology), and is a complete virtualization based on hardware. In the early days of xen , it was para-virtualization based on software simulation, and the new version is full virtualization based on hardware support.

Qemu is an analog processor, and now the most used is to combine KVM and QEMU.

To be precise, KVM is a module of the Linux kernel. You can use the command modprobe to load the KVM module. After this module is loaded, the virtual machine can be further created through the tool. But KVM modules alone are not enough. Because the user cannot directly control the kernel to do things, there must be a tool running in user space. For this user space tool, kvm developers chose the already formed open source virtualization software QEMU. Speaking of QEMU is also a virtualization software. Its feature is that it can virtualize different CPUs. For example, a power CPU can be virtualized on an x86 CPU, and a CPU that can run on power can be compiled using it, and a program that can run on power can be compiled using it. KVM uses a part of QEMU, and with a little modification, it becomes a user space tool that can control KVM. So you will see that the official KVM download has two major parts (qemu and kvm) and three files (KVM modules, QEMU tools, and a collection of the two). That is, you can upgrade only the KVM modules, or only the QEMU tools. This is the relationship between KVM and QEMU.

      As shown below:

       

      Linux Kernel-based Virtual Machine (KVM) is a Linux open source virtualization software based on hardware virtualization extensions (Intel VT-X and AMD-V) and a modified version of QEMU. There are two more KVM implementation modules: kvm.ko is the infrastructure that provides core virtualization; processor-specific modules kvm-intel.ko and kvm-amd.ko . It is designed to support full hardware emulation when multiple unmodified PC operating systems need to be booted.

       An ordinary linux process has two modes of operation: kernel and user. And KVM adds a third mode: guest mode (with its own kernel and user mode). In the kvm model, each virtual machine is a standard process managed by the linux scheduler.

       kvm consists of two parts: one is a device driver that manages virtual hardware, which uses the character device /dev/kvm as the management interface; the other is a user-space component that emulates PC hardware, which is a slightly modified qemu process.

Introduction 2

 现在所说的虚拟化,一般都是指在CPU硬件支持基础之上的虚拟化技术。KVM也同hyper-V、Xen一样依赖此项技术。没有CPU硬件虚拟化的支持,KVM是无法工作的。
准 确来说,KVM是Linux的一个模块。可以用modprobe去加载KVM模块。加载了模块后,才能进一步通过其他工具创建虚拟机。但仅有KVM模块是 远远不够的,因为用户无法直接控制内核模块去作事情:还必须有一个用户空间的工具才行。这个用户空间的工具,开发者选择了已经成型的开源虚拟化软件 QEMU。说起来QEMU也是一个虚拟化软件。它的特点是可虚拟不同的CPU。比如说在x86的CPU上可虚拟一个Power的CPU,并可利用它编译出 可运行在Power上的程序。KVM使用了QEMU的一部分,并稍加改造,就成了可控制KVM的用户空间工具了。所以你会看到,官方提供的KVM下载有两 大部分三个文件,分别是KVM模块、QEMU工具以及二者的合集。也就是说,你可以只升级KVM模块,也可以只升级QEMU工具。这就是KVM和QEMU 的关系

介绍3

Qemu:
是一个完整的可以单独运行的软件,它可以用来模拟机器,非常灵活和可移植。它主要通过一个特殊的“重编译器”将为特定处理器编写二进制代码转换为另一种。

(也就是,在PPCmac上面运行MIPS代码,或者在X86 PC上运行ARM代码)

KQemu:
当源和目标代码有同样的架构的时候(就像最普通的情况 x86运行在x86上面),同样需要解析代码去除任何'特权指令'并且把它们替换为上下文转换。为了尽量使这个过程有效,有个内核模块KQemu处理这个事情。作为一个内核模块,KQemu仅仅需要替换最底层的ring0-only指令。在这个情况下,Qemu仍然为模拟的机器分配所有的RAM并且加载代码。不同的是,KQemu不需要重新编译代码,它仅仅调用KQemu去扫描/打补丁/执行。所有外围的硬件仿真是在Qemu中做的。虽然大部分代码都是没有变换的,但是KQemu还是需要转换ring0代码(VM内核的绝大部分代码),所以性能仍然不好。


KVM:
 KVM包括很多部件:首先,它是一个Linux内核模块(现在包括在主线中)用于转换处理器到一种新的用户 (guset)模式。用户模式有自己的ring状态集合,但是特权ring0的指令会陷入到管理器(hypervisor)的代码(遇到特权指令需要陷入hypervisor进行特殊处理)由于这是一个新的处理器执行模型,代码不需要任何的改动。除了处理器状态转换,这个内核模块同样处理很小一部分低层次的模拟,比如MMU注册(用于管理VM)和一部分PCI模拟的硬件

kvm-qemu:

可执行程序像普通Qemu一样:分配RAM,加载代码,不同于重新编译或者调用callingKQemu,它创建了一个线程(这个很重要);这个线程调用KVM内核模块去切换到用户模式,并且去执行VM代码。当遇到一个特权指令,它从新切换会KVM内核模块。该内核模块在需要的时候,像Qemu线程发信号去处理大部分的硬件仿真。这个体系结构一个比较巧妙的一个地方就是客户代码被模拟在一个posix线程,这允许你使用通常Linux工具管理。如果你需要一个有2或者4核的虚拟机,kvm-qemu创建2或者4个线程,每个线程调用KVM内核模块并开始执行。并发性(若果你有足够多的真实核)或者调度(如果你不管)是被通用的Linux调度器,这个使得KVM代码量十分的小。当一起工作的时候,KVM管理CPU和MEM的访问,QEMU仿真硬件资源(硬盘,声卡,USB,等等)当QEMU单独运行时,QEMU同时模拟CPU和硬件。

在可预见的未来,Qemu团队专注于硬件模拟和可移植性,同时KVM团队专注于内核模块(如果某些部分确实有性能提升的话,KVM会将一小部分模拟代码移进来)和与剩下的用户空间代码的交互。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326826737&siteId=291194637