0% found this document useful (0 votes)
7 views

06 Memvirt

Uploaded by

21ug1239
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

06 Memvirt

Uploaded by

21ug1239
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Recap: Memory virtualization problem

Guest Guest Host/Machine


Virtual Addresses (GVA) Physical Addresses (GPA) Physical Addresses (HPA)
Page
Guest “RAM” Address = X’

Address = X
Code/data Address = Y’
Stack
Heap
(guest user Address = Y
process) Address = Z’

Guest OS Address = Z Host RAM

Guest “RAM” is actually memory of the userspace hypervisor process running


on the host, which is mapped to host memory by the host’s page table
Recap: Techniques for memory virtualization
• Guest page table has GVA GPA mapping
• Each guest OS thinks it has access to all RAM starting at address 0
• VMM / Host OS has GPA HPA mapping
• Hypervisor knows mapping between host virtual address (HVA) and guest physical
address (GPA), because it has setup its userspace memory as guest RAM
• Host OS knows mapping from HVA to HPA for all processes, so it knows GPA HPA
• That is, guest “RAM” pages are userspace process pages that are distributed across
host memory and host OS knows the physical locations of these guest “RAM” pages
• Which page table should MMU use?
• Shadow paging: VMM creates a combined mapping GVA HPA and MMU
is given a pointer to this page table
• Used in VMWare workstation (full virtualization)
• Extended page tables (EPT): MMU hardware is aware of virtualization,
takes pointers to two separate page tables
• Used in QEMU/KVM
Extended page tables
Guest page table Host page table/map
GVA GPA GPA HPA
CR3 EPTP

Special EPT
pointer register

MMU

• Page table walk by MMU: Start walking guest page table using GVA
• Guest PTE (for every level page table walk) gives GPA (cannot use GPA to access memory)
• Use GPA, walk host page table to find HPA, then access memory page, then next level access
• Every step in guest page table walk requires walking N-level host page table
• N-level page tables in guest/host result in page table walk of NXN memory accesses
Shadow page tables

Read only

Guest page table Host page table


GVA GPA GPA HPA

Shadow page table


GVA HPA
CR3
Combined mapping
Changes to guest page table trap to VMM constructed by VMM
Shadow page table updated
Maintaining shadow page tables
• Guest writes to CR3, privileged operation traps to VMM
• VMM marks the guest page table pages as read-only
• VMM constructs shadow page table, sets CR3 to it
• Shadow page table can be built on demand
• Start with empty page table, add entries on page faults
• Guest changes page table, traps to VMM, shadow entry updated
• Guest OS keeps multiple page tables of active processes in memory
• On context switch, new page table used, but old page table still in memory
• What about shadow page tables? How many in memory?
• Many design choices exist
• VMM can discard old shadow page table on context switch, and rebuild it later
(overhead during context switch)
• VMM can maintain multiple shadow page tables of active processes (overhead to
track changes to all page table pages)
Demand Paging and Page Faults
Guest Guest Host/Machine
Virtual Addresses (GVA) Physical Addresses (GPA) Physical Addresses (HPA)
Page
Address = X’

Address = X
Address = Y’

Address = Y
• Guest OS may not assign a physical Address = Z’
frame to a page
• No entry in page table, page fault
Address = Z • VMM may not assign frames to all
• VM exit, VMM handles page fault,
guest “RAM” pages due to
injects fault into guest
memory pressure
• Guest assigns physical frame
• Page fault is handled by VMM
• Guest OS not aware of this fault
• “Hidden” page faults
Memory reclamation technqiues
• VMM reclaims memory from guest “RAM” under memory pressure
• Uncooperative swapping: VMM reclaims some guest “RAM” pages and swaps
them to disk
• Page fault and memory assigned when guest accesses the page
• May hurt performance, important pages may be swapped to disk
• Ballooning: VMM opens dummy device, requests pages from VM (“inflating
the balloon”), then swaps these pages out
• Since pages assigned to a device, pages not used by other processes in guest
• Cooperative, guest can assign free pages
• Lesser impact on performance, but reclamation takes time, requires guest changes
• Memory sharing: memory pages with identical content across VMs (OS
images, zero pages etc.) shared between VMs
• One physical frame mapped into page tables of multiple guests
• Scan pages periodically to compute and match hash-based similarity of pages
Summary
• Memory virtualization
• Extended page tables
• Shadow page tables
• Memory reclamation techniques
• Uncooperative swapping
• Ballooning
• Memory sharing

• “Memory Resource Management in VMware ESX Server”, Carl A. Waldspurger.

You might also like