Virtual Machines Background Adapted from SilberschatzPresentation Transcript
Virtual Machines Background Adapted from Silberschatz
A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware.
A virtual machine provides an interface identical to the underlying bare hardware.
For example, the operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory.
Virtual Machines (Cont.)
The resources of the physical computer are shared to create the virtual machines.
CPU scheduling can create the appearance that users have their own processor.
Spooling and a file system can provide virtual card readers and virtual line printers.
A normal user time-sharing terminal serves as the virtual machine operator’s console.
System Models Non-virtual Machine Virtual Machine
Advantages/Disadvantages of Virtual Machines
The virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines. What might be bad about this?
This isolation, however, permits no direct sharing of resources.
A virtual-machine system is a perfect vehicle for operating-systems research and development. System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation.
The virtual machine concept is difficult to implement due to the effort required to provide an exact duplicate to the underlying machine.
Java Virtual Machine
Compiled Java programs are platform-neutral bytecodes executed by a Java Virtual Machine (JVM).
JVM consists of
- class loader
- class verifier
- runtime interpreter
Just-In-Time (JIT) compilers increase performance
Java Virtual Machine
An Overview of Virtual Machine Architectures Smith and Nair
Instruction Set Architecture (ISA)
Precise specification of the interface between hardware and software
Application Binary Interface (ABI)
Defines how an application can work with a platform at the binary level. (Contrast with API.)
Includes user ISA, system call interface, etc.
Suppose an ABI is changed.
VMM also known as hypervisor.
Hardware OS Application ISA Hardware OS Application Virtual ISA VMM ISA Guest Host OS Application Virtual ISA Virtual Machine
Virtual Machine Uses
One ISA can be used to emulate another.
Provides cross-platform portability.
Emulators can optimize as they emulate.
Also can optimize same ISA to same ISA.
A single physical machine can be replicated, providing isolation between the VMs.
Two virtual machines can be composed, combining the functionality of each.
Process vs. System
Meaning of “machine” depends on perspective.
To a process, the machine is the system calls, libraries, etc.
The entire system also runs on a machine.
Includes ISA, actual devices, etc.
Other kinds of machines?
As there are two perspectives, there are two kinds of virtual machines: process and system.
Process virtual machine can support an individual process.
System virtual machine can run a complete OS plus environment.
Process vs. System x86 Linux Java VM Native App Native App Java VM Java Prog Java Prog x86 Linux VMM Native App Native App W32 App Windows W32 App Process VM System VM Examples?
A process has the illusion of having the whole machine to itself.
What are relative merits?
Especially useful with some kind of profile-directed translation.
High Level Language VMs
High-level language is compiled to an intermediate language.
VM then runs the intermediate language.
Example is Java: Interpreted or translated?
“ Classic” (Define. Pros/cons?)
VMM built directly on top of hardware.
Most efficient, but requires wiping the slate clean.
Requires device drivers in the VMM.
Hosted (Define. Pros/cons?)
VMM built on top of existing OS.
Devices drivers supplied by host OS, VMM uses facilities provided by host OS.
Whole System VMs: Emulation
ISA not the same, must emulate everything.
Co-Designed VMs: Optimization
Hardware designed to support VMs.
Provides a clean design for virtualization.
Can be significantly more efficient.
The state of a machine must be maintained.
Physical machine: latches, flip-flops, etc.
Virtual machine: combination of physical machine and state emulated in software using RAM, etc.
At certain points in execution, such as a trap, the state of the machine must be “materialized”.
Not trivial due to complex hardware techniques used to provide high performance.
This ability to materialize the state is termed “preciseness”.
Three aspects of virtualization
State: registers and memory
Instructions: may involve emulation
State materialization: when exceptions occur
Process VMs Virtualization
Provided by hardware
Registers mapped to host registers as available (overflow to memory). Memory mapped to host memory.
Provided by VM software
Mapped to host resources as available.
Emulated, JIT compiled
Provided by VM software
System VMs Virtualization
“ Classic” VMs
Mapped 1:1, except for privileged registers.
Native, except trapping for priveleged instructions
Provided by hardware
Whole System VMs
Mapped to available memory, not 1:1
Provided by VM software
Provided by hardware/VM software combination
“ Classic” OS VMs (IBM)
VMs can support an individual process only, or can support a whole OS.
Can construct a useful taxonomy based on:
process or system
same ISA or different ISA
Virtualizing I/O Devices on VMware Workstation’s Host VMM
Virtualizing the PC Platform
Some privileged instructions fail silently. (Why is this a problem?) (What’s the solution?)
PC hardware diversity
Why is this problematic for a “classic” VM?
Pre-existing PC software
Must stay compatible
To address these, VMware uses a hosted VM. (Not a “classic” VM.)
VMApp runs in the host, using the VMDriver host kernel component to establish the VMM.
CPU is thus executing in either the host world or the virtual world, using VMDriver to switch worlds.
World switches are expensive, since user and system state must be switched.
Virtualizing the NIC
I/O port operations by guest OS must be intercepted by VMM.
Must then be processed in the VMM (to maintain the virtual state).
Or executed in the host world. (When must it do what?)
Send operations start as a sequence of ops to virtual I/O ports.
Upon finalization of the send, the VMApp issues a host OS syscall to the VMNet driver, which passes it on the real NIC.
Finally requires raising a virtual IRQ to signal completetion.
Receive operations operate in reverse.
VMApps executes select() syscall on possible sources.
Reads packet, forwards it to VMM which raises a virtual IRQ.
Reducing Network Virtualization Overheads
Handling I/O ports in the VMM
Many accesses don’t involve actual I/O.
Let the VMM maintain the state, avoiding a worlds switch.
If data rate is high, queue up packets, send them in a group.
Use shared memory bitmap rather than requiring VMApp to call select() when an IRQ is received on the host system.
Reducing CPU virtualization overhead
Find operations to the interrupt controller that have memory semantics and replace with MOV operation, which does not require intervention by the VMM.
Apparently requires dynamic binary translation.
Modifying the guest OS
Eliminate idle task page table switching, which is not necessary, since the idle task pages are mapped in every process page table.
Run idle task with page table of last process.
What would happen if the idle task had a bug and wrote to some random addresses?
Creating a custom virtual device
Virtualizing a real device is somewhat inefficient, since the interface to these devices is optimized for real devices, not virtual devices.
Designing a custom virtual device can reduce expensive operations.
Disadvantage is that must write a new device driver in guest OS for this virtual device.
Modifying the host OS
VMNet driver allocates kernel memory sk_buff , then copies from VMApp to sk_buff .
Can eliminate copy by using memory from VM physical memory.
Bypassing the host OS
VMM uses own drivers, rather than going through the host OS. (Note that going through the host OS is using a kind of process VM provided by the host OS.)
Disadvantage is that you have to write your own VMM driver for every supported real device.
Main goal is to develop some understanding of the issues of hosted system VM performance.
Xen and the Art of Virtualization
Motivation of Xen
Server farm scenario
Multiple applications installed on machines.
Configuration interaction between apps (like versions of Java jars, shared libraries, etc.) can lead to compatibility problems requiring time-consuming system administration to solve.
Behavior of one app can impact performance of another. Need performance isolation.
Instead use multiple VMs, one VM per app.
Each app can configure the entire OS exactly how it requires.
Relatively easier to implement algorithms at the VM level to isolate the performance behavior of different apps.
To avoid performance penalties of VMs like VMware, use paravirtualization.
Support for unmodified binaries is essential.
Must virtualize all features required by existing ABIs.
Support for full multi-app OSs is important. (Not just process VMs.)
Complex configurations may have multiple processes and should be configured within a single VM.
Paravirtualization is necessary to obtain high performance and strong resource isolation.
For example, virtualizing page tables can result in many expensive traps.
Even on ISAs designed for virtualization, completely hiding the virtualization from guest OS risks correctness and performance.
For example, the VM should know real time (and not just virtual time) to handle things like timeouts.
The VM Interface Overview
Xen in top 64 MB of every AS, avoiding TLB flush for hypervisor transitions.
Guest OSs update actual hardware page tables through Xen, which improves performance. (But makes them aware of virtualization.)
Guest OS must run at lower privilege. Since ring 1-2 seldom used, run guest OS in ring 1.
Guest OSs must register handlers with Xen. Only page fault handler must be modified to not read from privileged register.
“ Fast” handlers may be registered to avoid going through ring 0. (This seems to change the ABI. Non-dynamically binaries will need to be recompiled.)
Replaced with event system.
Each guest OS has a time interface and is aware of real and virtual time.
Network, Disk, etc.
All replaced with special, buffer-based event mechanism.
Explicit calls into the hypervisor by the guest OS. Used by guest OS for things like updating hardware page tables.
Time and timers
Guest OSs made aware of real time and virtual time.
Virtual time advances only when the guest OS is executing. Used for scheduling by the guest OS.
Xen-provided timers are used by guest OS.
Solves one efficiency problem with VMware Workstation.
Guest XP causes host to perform poorly, because must constantly deliver timer interrupts to XP to do things like smooth transition animations (like minimizing a window, etc.). Forcing the guest to use XP provided timer would eliminate the need to virtualize these timer interrupts.
Reserved for each guest OS instance at time of creation.
Provides strong isolation.
Isolation is tricky, but batching of requests provides some degree of it.
Generally good performance.
Unfortunately, comparisons with a number of products not publishable due to licensing.
Isolation tests were better than expected, given the currently weak disk isolation.
A virtual ISA (paravirtualization) is better.
Allows VMs to be isolated from one another. One VM can’t cause the other to thrash, for instance.
Allows up to 100 OS instances
Making the guest OS aware of virtualization improves correctness and performance
Control and management of Xen itself is done from a guest OS, via a special interface.
Microkernels Meet Recursive Virtual Machines Ford et al