課程影片連結:
Page Fault
回顧 virtual memory 的特性
- isolation
- level of indirection 在原先 xv6 的設計中 pagetable 的設計是 static 現在在 page fault 的時候做一些動作,可以設計為 dynamic 的 mapping
Information neede
- 造成 page fault 的 virtual memory
stvalregister
- The type of page fault
scause: R/W/Instruction
- Virtual address of instruction that cause page fault
- 這是為了在處理完 page fault 之後,可以回到原本的地方繼續執行
trampframe->epc
Allocation: sbrk()
- 原先的方式:eager allocatoin
- 可變更為:Lazy Allocation
1. Lazy Allocation
先把 sys_sbrk() 變更為:
p->sz = p->sz + n;
- allocate one page
- zero the page
- map the page
- restart instruction
??: what if no more memory
sys_sbrk()
p->sz = p->sz + n;
usertrap()
if (scause == 15)
uvmunmap()
continue;
Zero fill on demand
多個 page map 到同一個 zero page 並且用 read only
page fault: someone whant to write
- make a new page with write
- restart instruction
less pa useage
2. Copy-on-Write fork
跟前面的 zero fill on demand 有一點像 這裡需要用一個 counter 計算每一個 physical page 正在被多少個 process map 到
3. Demand Paging
If out of memory
- evict a page to file system
- use the page just free
- restart instruction
如何選擇要被 evict 的 page
- least recently used
- not dirty page??
4. Memory-Mapped Files
mmap() map va to a file discriptor
multiple process???
file walking
Summary
page tables + traps/pagefault =
- powerful
- elegant virtual feature