kvm原理学习:
Linux as a Hypervisor:
By adding virtualization capabilities to a standard Linux kernel, we can enjoy all
the fine-tuning work that has gone (and is going) into the kernel, and bring that
benefit into a virtualized environment. Under this model, every virtual machine is a regular Linux process scheduled by the standard Linux scheduler. Its memory is allocated by the Linux memory allocator, with its knowledge of NUMA and integration into the scheduler.
A normal Linux process has two modes of execution: kernel and user. Kvm adds a third mode: guest mode (which has its own kernel and user modes, but these do not interest the hypervisor at all).
三种工作模式如下:
kvm Components:
The simplicity of kvm is exemplified by its structure; there are two components:
● A device driver for managing the virtualization hardware; this driver exposes its capabilities via a character device /dev/kvm
● A user-space component for emulating PC hardware; this is a lightly modified qemu process,QEMU is a well known processor emulator written by French computer wizard Fabrice Bellard.
见附件!
What is the difference between kvm and QEMU? ##kvm和QEMU的不同点
Qemu uses emulation; kvm uses processor extensions for virtualization.
What is the difference between kvm and Xen? ##xen和kvm的不同点
Xen is an external hypervisor; it assumes control of the machine and divides resources among guests. On the other hand, kvm is part of Linux and uses the regular Linux
scheduler and memory management. This means that kvm is much smaller and simpler to use.
On the other hand, Xen supports both full virtualization and a technique called paravirtualization, which allows better performance for modified guests. kvm does not
at present support paravirtualization.
-
- KVM 所使用的方法是通过简单地加载内核模块而将 Linux 内核转换为一个系统管理程序。这个内核模块导出了一个名为 /dev/kvm 的设备,它可以启用内核的客户模式(除了传统的内核模式和用户模式)。有了 /dev/kvm 设备,VM 使自己的地址空间独立于内核或运行着的任何其他 VM 的地址空间。设备树(/dev)中的设备对于所有用户空间进程来说都是通用的。但是每个打开 /dev/kvm 的进程看到的是不同的映射(为了支持 VM 间的隔离)。KVM安装 KVM 之后,您可以在用户空间启动客户操作系统。每个客户操作系统都是主机操作系统(或系统管理程序)的一个单个进程。
- KVM 是指基于 Linux 内核的虚拟机(Kernel-based Virtual Machine),2006年10月,由以色列的 Qumranet 组织开发的一种新的“虚拟机”实现方案。 2007年2月发布的 Linux 2.6.20内核第一次包含了KVM 。增加KVM到Linux内核是 Linux发展的一个重要里程碑,这也是第一个整合到Linux主线内核的虚拟化技术。
- KVM 在标准 Linux 内核中增加了虚拟技术,从而我们可以通过优化的内核来使用虚拟技术。在 KVM 模型中,每一个虚拟机都是一个由 Linux 调度程序管理的标准进程,你可以在用户空间启动客户机操作系统。
- 一个普通的 Linux 进程有两种运行模式:内核和用户。 KVM 增加了第三种模式:客户模式(有自己的内核和用户模式)
作为VMM,KVM分为两部分,分别是运行于kernel模式的KVM和运行于User模式下的Qemu模块,这里的kernel模式和User模式,实际上指的是VMX根模式下的特权级0和特权级3,KVM将虚拟机所在的运行模式称为Gues模式 当一起工作的时候,KVM管理CPU和MEM的访问,QEMU仿真硬件资源(硬盘,声卡,USB,等等).而qemu-kvm是为了针对KVM专门做了修改和优化的QEMU分支.
KVM的所有IO虚拟化工作时借助Qemu完成的,显著降低了实现的工作量!这是KVM的优势之一! ##看下图即可理解
KVM是Linux的一个模块。可以用modprobe去加载KVM模块。加载了模块后,才能进一步通过其他工具创建虚拟机。但仅有KVM模块是远远不够的,因为用户无法直接控制内核模块去作事情:还必须有一个用户空间的工具才行。这个用户空间的工具,开发者选择了已经成型的开源虚拟化软件QEMU。说起来QEMU也是一个虚拟化软件。它的特点是可虚拟不同的CPU。比如说在x86的CPU上可虚拟一个Power的CPU,并可利用它编译出可运行在Power上的程序。KVM使用了QEMU的一部分,并稍加改造,就成了可控制KVM的用户空间工具了
- KVM 所使用的方法是通过简单地加载内核模块而将 Linux 内核转换为一个系统管理程序。这个内核模块导出了一个名为 /dev/kvm 的设备,它可以启用内核的客户模式(除了传统的内核模式和用户模式)。有了 /dev/kvm 设备,VM 使自己的地址空间独立于内核或运行着的任何其他 VM 的地址空间。设备树(/dev)中的设备对于所有用户空间进程来说都是通用的。但是每个打开 /dev/kvm 的进程看到的是不同的映射(为了支持 VM 间的隔离)。KVM安装 KVM 之后,您可以在用户空间启动客户操作系统。每个客户操作系统都是主机操作系统(或系统管理程序)的一个单个进程。