25
Memory Virtualization (based on Scott Devine slides by VMWare)

Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Memory Virtualization

(based on Scott Devine slides by VMWare)

Page 2: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Traditional Address Spaces

0 4GB

Current Process

0 4GB Operating

System Virtual

Address Space

Physical Address Space

RAM ROM Devices Frame Buffer

Page 3: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Process Virtual Address Space

0 4GB

Traditional Address Spaces

Background Process Operating System Background Process

Operating System

0 4GB

Current Process

0 4GB Operating

System Virtual

Address Space

Physical Address Space

RAM ROM Devices Frame Buffer

Page 4: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Memory Management Unit (MMU)

•  Virtual Address to Physical Address Translation –  Works in fixed-sized pages –  Page Protection

•  Translation Look-aside Buffer –  TLB caches recently used Virtual to Physical

mappings

•  Control registers –  Page Table location –  Current ASID –  Alignment checking

Page 5: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Traditional Address Translation (I)

TLB Virtual Address Physical Address

1 2

Page 6: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Traditional Address Translation (II)

Process Page Table

Process Page Table

Process Page Table

Process Page Table

1

2 3

4 5

TLB Virtual Address Physical Address

Page 7: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Traditional Address Translation (III)

Process Page Table

Process Page Table

Process Page Table

Process Page Table

Page Fault

Handler

1

2

3

7

4

5 8

6

TLB Virtual Address Physical Address

Page 8: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Virtualized Address Spaces

Current Guest Process

0 4GB

Guest OS Virtual Address Spaces

0 4GB

0 4GB Physical

Address Space

Machine Address Space

RAM ROM Devices Frame Buffer

Virtual RAM Virtual ROM

Virtual Devices

Virtual Frame Buffer

Page 9: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Virtualized Address Translation: TLB Emulation

Physical Page Table

Emulated TLB

1

2

3

7

4

5

96

TLB Virtual Address Machine Address

Guest Page Table

page fault

VMM traps

4

true page fault

Guest OS page fault

handler

hidden page fault

8

Page 10: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Issues

•  Guest page table consistency –  What happens when the guest changes an entry

in its page table? –  What happens when the guest switches to a new

page table on a process context switch?

•  Performance –  Guest context switches flush entire software TLB –  Minimize hidden page faults –  Aggressive flushing will cause flood of hpfs every

guest context switch –  Keep one shadow page table per guest process

Page 11: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Virtualized Address Translation: Shadow Page Tables

Guest Page Table

Shadow Page Table

Guest Page Table

Guest Page Table

Shadow Page Table

Shadow Page Table

Virtual CR3

Real CR3

Page 12: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Guest Write to CR3

Guest Page Table

Shadow Page Table

Guest Page Table

Guest Page Table

Shadow Page Table

Shadow Page Table

Virtual CR3

Real CR3

Page 13: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Guest Write to CR3

Guest Page Table

Shadow Page Table

Guest Page Table

Guest Page Table

Shadow Page Table

Shadow Page Table

Virtual CR3

Real CR3

Page 14: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Undiscovered Guest Page Table

Guest Page Table

Shadow Page Table

Guest Page Table

Guest Page Table

Shadow Page Table

Shadow Page Table

Virtual CR3

Real CR3

Guest Page Table

Page 15: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Undiscovered Guest Page Table

Guest Page Table

Shadow Page Table

Guest Page Table

Guest Page Table

Shadow Page Table

Shadow Page Table

Virtual CR3

Real CR3

Guest Page Table

Shadow Page Table

Page 16: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Virtualized Address Translation: Shadow Page Table

Physical Page Table

Shadow Page Table

1

2

3

7

4

5

96

TLB Virtual Address Machine Address

Guest Page Table

page fault

VMM traps

4

true page fault

Guest OS page fault

handler

hidden page fault

8

Page 17: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Issues

•  Benefits –  Handle page faults in same way as Emulated TLB –  Fast guest context switching

•  Page Table Consistency –  Guest may not need invalidate TLB on writes to

off-line page tables –  Need to trace writes to shadow page tables to

invalidate entries

•  Memory Bloat –  Caching guest page tables takes memory –  Need to determine when guest has reused page

tables

Page 18: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Hardware-assisted Virtualization: Nested Page Tables

•  Nested paging uses an additional nested page table (nPT) to translate guest physical addresses to system physical addresses

•  The gPT maps guest linear addresses to guest physical addresses. Nested page tables (nPT) map guest physical addresses to system physical addresses.

•  Guest and nested page tables are set up by the guest and hypervisor respectively. When a guest attempts to reference memory using a linear address and nested paging is enabled, the page walker performs a 2-dimensional walk using the gPT and nPT to translate the guest linear address to system physical address.

•  Nested paging removes the overheads associated with shadow paging. Unlike shadow paging, once the nested pages are populated, the hypervisor does not need to intercept and emulate guest’s modification of gPT.

•  However because nested paging introduces an additional level of translation, the

TLB miss cost could be larger.

Page 19: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Reclaiming Memory: ballooning

Guest OS

balloon

Guest OS

balloon

Guest OS

inflate balloon (+ pressure)‏

deflate balloon (– pressure)‏

may page out to virtual disk

may page in from virtual disk

guest OS manages memory implicit cooperation

Page 20: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Page Sharing

•  Motivation –  Multiple VMs running same OS, apps –  Deduplicate redundant copies of code, data,

zeros

•  Transparent page sharing –  Map multiple PPNs to single MPN copy-on-write –  Pioneered by Disco [Bugnion et al. SOSP ’97],

but required guest OS hooks

•  VMware content-based sharing –  General-purpose, no guest OS changes –  Background activity saves memory over time

Page 21: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Page Sharing: Scan Candidate PPN

VM 1 VM 2 VM 3

011010 110101 010111 101100

Machine Memory …06af

3 43f8 123b

Hash: VM: PPN: MPN:

hint frame

hash table

hash page contents …2bd806af

Page 22: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

I/O Virtualization

Page 23: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Type of devices

•  Dedicated Devices –  Monitor, keyboard, mouse –  No virtualization required, but VMM routing because guest

OS runs in user mode –  Interrupt handled by VM on activation by VMM

•  Partitioned Devices –  Disks –  VMM maintains a map of parameters and re-issues the

requests to physical devices •  Shared Devices

–  Network adapter –  VMM translates through a virtual device drivers

•  Spooled Devices –  Printer

•  Nonexistent Devices –  Comm network

Page 24: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Performing I/O

Applications

Operating System

Hardware

I/O Drivers

system calls

driver calls

I/O operations

Page 25: Memory Virtualization - unipi.itdidawiki.cli.di.unipi.it/lib/exe/fetch.php/magistrale... · 2011. 1. 17. · shadow paging, once the nested pages are populated, the hypervisor does

Virtualizing I/O

•  I/O Operations level –  I/O runs in privileged mode –  Trap in user mode –  Difficult to reverse engineer a complete I/O action

•  Device drivers level –  Needs virtual device drivers –  VMM intercepts calls to virtual device drivers –  Must know guest OS device driver implementation –  Real drivers needed for native VMMs

•  System calls level –  Most efficient –  Must know guest OS ABI to I/O and rewrite it taking

care of emulation of everything else not directly related to I/O.