Lec16 Virtualization
Lec16 Virtualization
Operating Systems
Hong Xu
https://github.com/henryhxu/CSCI3150
https://github.com/henryhxu/CSCI3150
Acknowledgement
CSCI3150 Intro to OS 2
What is virtualization?
Virtualization is the ability to run multiple operating systems on a single physical syst
em and share the underlying hardware resources 1
Goals:
Provide flexibility for users
3
Requirements for Virtualizable Architectures
“First, the VMM provides an environment for programs which is essentially identical
with the original machine;
second, programs run in this environment show at worst only minor decreases in spe
ed;
4
VMM Platform Types
Hosted Architecture
Bare-Metal Architecture
6
Virtualization: rejuvenation
IBM VM/370
VMWare
Docker containers
7
IBM VM/370
Technology: trap-and-emulate
Normal Application
Privileged Kernel
Trap Emulate
CPU
8
Trap and Emulate Virtualization on x86 architecture
Challenges
Correctness: not all privileged instructions produce traps!
Performance:
System calls: traps in both enter and exit (10X)
9
Virtualization on x86 architecture
Solutions:
Dynamic binary translation & shadow page table
Para-virtualization (Xen)
Hardware extension
10
Dynamic binary translation
11
Binary translation
12
How does VMWare do this?
13
Convert unsafe operations and cache them
Input: BB
55 ff 33 c7 03 ...
Each Translator Invocation
• Consume a basic block (BB)
• Produce a compiled code fragment (CCF)
14
Dynamic binary translation
Pros:
Make x86 virtualizable
Cons:
Overhead
15
Shadow page table
Guest
page table
Shadow
page table
16
Shadow page table
Pros:
Transparent to guest VMs
Cons:
Big overhead of keeping two page tables consistent
17
Xen
18
Xen and the art of virtualization
SOSP’03
19
Para-virtualization
20
Overview of the Xen approach
Better performance
21
Xen architecture
22
Virtualization on x86 architecture
Challenges
Correctness: not all privileged instructions produce traps!
Performance:
System calls: traps in both enter and exit (10X)
23
CPU virtualization
Protection
Xen in ring0, guest kernel in ring1
24
Memory virtualization
Guest kernels are responsible for allocating and managing the hardware page tables.
After registering the page table to Xen, all subsequent updates must be validated.
25
Porting effort is quite low
26
Evaluation
27
Conclusion
Full virtualization
unmodified guest OS; good isolation
Para virtualization:
Better performance (potentially)
28
Instead: Leverage hardware support
29
Protection Rings
Ring 3
[Fischbach] 30
Why aren’t protection rings good enoug
h?
VM
CPL 3
Increasing Privilege Level
guest kernel CPL 1
Ring 0
hypervisor CPL 0 Ring 1
Ring 2
Ring 3
31
A short list of pre-VT problems
32
First generation: Intel VT-x & AMD SVM
Ring3 Ring3
VMRUN
Ring2 Ring2
Ring1 VMEXIT Ring1
Ring0 Ring0
33
VT in a Nutshell
34
CPU Virtualization With VT-x
36
Containers and isolation
42
Containers: idea
Benefits
Consistent environment (runtime, dependencies, etc.)
Performance
43
Pre-container isolation features in Linux
chroot
Set the current root directory for processes
Added to Unix in 1979
Namespaces
Provide processes with their own view of resources
Process IDs, networking sockets, hostnames, etc.
Copy-on-Write Filesystem
Allow a process to view existing filesystem, but any modifications result in copies then
updates
Akin to virtual memory after fork
44
Key technologies
CSCI3150 Intro to OS 45
Namespace
Controls what resources a process can see, and what they are called
CSCI3150 Intro to OS 46
cgroups in Linux
47
Controllers enforce restrictions for cgroups
48
Controllers in Linux
io
Limit I/O requests either capped per process or proportionally.
memory
Enforce memory caps on processes
pids
Limit number of new processes in a cgroup
perf_event
Allow monitoring performance
cpu
Limit CPU usage when CPU is busy
freezer
Allow suspending all processes in a cgroup
49
Linux containers = combinations of namespaces & cgroups
50