Page table基本概念
Page table的功能是用來做virtual address to physical address轉換. Virtual address space是一個4G的連續記憶體位址, 專屬於某一個process, 但其所指到的實體記憶體其實是分散在不同physical memory 上, 甚至有可能不在physical memory裡面 (swap out). Modern OS利用Page table的功能提供了讓process之間有自己的連續記憶體區塊, 並提供process address space之間的isolation.
Page fault
Page fault的發生有兩種可能, 第一個是當要去查詢某個virtual address時發現沒有此entry在page table裡面, 此時會發生segmentation fault.
第二種是查詢到的entry不在physical memory裡面, (page table entry裡面有個present bit = 0), 此時表示此區記憶體已經swap out, 必須要在被load進memory.
Paravirtualization
需要修改guest OS code to call hypercall. 只有Linux能用 因為需要改OS
不然則需要利用binary translation (ex: windows), 直接修改binary, overhead較高 (called: full virtualization)
From Xen wiki about hypercall:
A hypercall is to a syscall what a hypervisor is to an OS. Alternatively, a hypercall is to a hypervisor what a syscall is to a kernel. A hypercall is a software trap from a domain to the hypervisor, just as a syscall is a software trap from an application to the kernel. Domains will use hypercalls to request privileged operations like updating pagetables.
Shadow page table
- guest virtual to host physical
當host要做context switching時, cr3會指向下一個page table. 當此情形發生在VM時, hypervisor會trap 此 instruction, 並將此cr3重新指向在host physical底下的page table. Hypervisor因此需要管理一個mapping, 從guest page table 轉到 host page table.
Host會將此page table設定成read-only, 當guest對pte (page table entry)做修改時, host 會trap此情況, 然後將修改後的直sync回guest page table.
因為修改cr3, trap instruction, synchronize需要較多的overhead, 因此有了EPT.
Extended page table
EPT是x86提供給虛擬畫技術的功能, 主要目的在加強MMU做VM和PM之間memory address的轉換("Extend" from guest physical to host physical). 當有EPT support時, VM的 physical address可以直接經由MMU轉換到PM的 physical address (因此不需要像shadow page table利用trap, 造成overhead). 此時cr3指到guest VM的 address, 因此Guest VM可以直接修改 page table( guest physical address) 然後MMU會直接寫到 host physical address.
Intel x86提供兩個instruction: vmentry and vmexit. 當vmentry時, MMU extended page table 功能被啓動, 因此VM可值接寫入host physical.
Reference:
http://en.wikipedia.org/wiki/Page_tables
沒有留言:
張貼留言