Virtual Machines
Philipp Koehn 30 April 2018
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
Virtual Machines Philipp Koehn 30 April 2018 Philipp Koehn - - PowerPoint PPT Presentation
Virtual Machines Philipp Koehn 30 April 2018 Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018 Basic Idea 1 Run multiple instances of full operating systems on a machine Example: run Windows and Linux on a
Philipp Koehn 30 April 2018
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
1
run Windows and Linux on a Mac
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
2 Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
3
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
4
move a VM to another host (maybe because of spike of VM usage overloads current machine)
– take snapshot (fast) – copy all pages of snapshot (not so fast) – copy modified pages (fast) – freeze virtual machine and copy VM memory
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
5
sharing of a single computer among several users
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
6
VMWare 1999
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
7
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
8
– runs as a process of the operating system – has privileged access to CPU
– manages their access to hardware – intercepts exceptions and interrupts
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
9
Normal OS
exec syscall
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
10
Virtual Machine
exec syscall
exec
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
11
– process runs in own virtual memory – makes systems calls to kernel
– manages processes – handles interrupts and exceptions e.g., page faults
e.g., allow access to physical memory
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
12
⇒ Very little overhead when running inside virtual machine (unless very I/O intensive)
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
13
– privileged CPU state – input/output devices – exceptions – interrupts
VMM catches exceptions and directs them to the right guest
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
14
Normal OS
exec
exception interrupt syscall
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
15
Virtual Machine
exec
exec
exception interrupt syscall
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
16
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
17
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
18
– access to physical memory – handling interrupt flags
i.e., rewritten into user mode instructions
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
19
page tables of virtual memory – VMM maintains copy of page tables – traps access attenpts – emulating them instead in software
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
20
– network adapter – disk – keyboard – video/audio i/o
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
21
– new execution mode: guest mode → direct execution of guest OS code incl. privileged instructions – virtual machine control block (VMCB) → controls what operations trap records info to handle traps in VMM
– new instruction "vmrun" enters guest mode, runs VM code – when VM traps, CPU executes new "exit" instruction – enters VMM, which emulates operation
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
22
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
23
– managing it: OS assumes it owns it all – mapping it: OS assumes it can map to any physical page
– VMM needs to assign hardware pages to VMs – VMM needs to control mappings for isolation → OS can only map to a hardware page given to it by the VMM
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
24
machine: actual hardware memory, e.g., 16 GB of DRAM physical: abstraction of hardware memory managed by OS
→ OS thinks the computer has 2 GB of contiguous physical memory
underlying machine memory may be discontiguous virtual: virtual address spaces of process (48 bit → 256TB)
but: these page tables are not used by the MMU hardware
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
25
Guest A Guest B
Guest Virtual Guest Physical Machine Memory Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
26
("shadow page tables")
to its V→P tables – VMM maps OS page tables as read only – when OS writes to page tables, trap to VMM – VMM applies write to shadow table and OS table, returns
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
27
– Managed by OS in VM, backwards-compatible – No need to trap to VMM when OS updates its page tables
Managed by VMM
– tagged TLB w/ virtual process identifiers (VPIDs) – tag VMs with VPID, no need to flush TLB on VM/VMM switch
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
28
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
29
specific versions of libraries
"web service" answers HTTP request to fulfill complex tasks
virtual machine – package all the software into a virtual machine – deployment: run virtual machine – but: relatively large overhead (runs entire operating system)
containers
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
30
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018
31
Philipp Koehn Computer Systems Fundamentals: Virtual Machines 30 April 2018