# 引言

IBM 为此种需求提供了一个解决方案，那就是 Virtual Machine Monitor ( VMM )，也被叫做 hypervisor (这个名字可能更为人所知).

VMM 工作在 OS 和 硬件之间，给予操作系统一种 I am in the control of the while machine 的假象，但实际上是多重操作系统共享底层硬件。

VMM 扮演了一种 运行操作系统的操作系统 的角色，比 Guest OS 更底层一些，让 Guest OS 认为他们就工作在 Bare Machine 上面，因为提供对于 Guest OS 的透明度是 VMM 的首要任务。

# 虚拟化 CPU

VMM 必须要承担起 Machine Switch 的工作，因为 VMM 必须把整个虚拟机操作系统的状态都得保存下来（寄存器，程序计数器，特权的硬件状态），然后把另一个虚拟机的状态给恢复到硬件上，然后设置程序计数器为准备运行的虚拟机的程序计数器，就完成了一次切换。

open:
push    dword mode
push    dword flags
push    dword path
mov     exa, 5
push    eax
int     80h


When running in this mode, one still doesn’t have access to privileged instructions, but one can access a little more memory than when in user mode; the OS can use this extra memory for its data structures and all is well.
On hardware that doesn’t have such a mode, one has to run the OS in user mode and use memory protection (page tables and TLBs) to protect OS data structures appropriately.

# The Information Gap

Just like the OS doesn’t know too much about what application programs really want, and thus must often make general policies that hopefully work for all programs, the VMM often doesn’t know too much about what the OS is doing or wanting; this lack of knowledge, sometimes called the information gap between the VMM and the OS, can lead to various inefﬁciencies.

It makes sense to spin like this if the OS in charge of the entire machine and thus knows there is nothing else that needs to run. However, when a VMM is running underneath two different OSes, one in the idle loop and one usefully running user processes, it would be useful for the VMM to know that one OS is idle so it can give more CPU time to the OS doing useful work.