MIT 6.S081 Lecture 7: Page faults
Reading
Implenment VM features using page fault
-
lazy allocation
-
copy on write fork
-
demand paging
-
memory mapped files
Virtual Memory benefits
-
Isolation
-
level of indirection
- trampline page
- guard page
Information needed
-
the faulting VA -> stval register
-
type pf fault -> scause register
- load
- store
- pc
-
the VA of Instruction that cause fault -> sepc register | trampframe?
lazy allocation
-
sbrk()原本应为进程改变堆的大小,分配内存

-
sbrk()系统调用基本不做事情,只p->size + n
-
当要使用这一部分内存时,触发Page Fault
- allocate 1 page
- zero page
- map the page
- restart instruction
zero fill on demand
-
初始化的page VA共用一个PA,即映射到同一个物理地址上(Read Only)

-
当要写这些page时,触发Page Fault
- copy
- upgrade
- restart instruction
copy on write fork
-
fork()时child使用parent的内存空间,即子进程映射到父进程的物理空间上(Read Only)

-
当要写子进程,触发Page Fault
- copy page
- map
- restart instruction
- usrret
demand page
-
当执行exec()系统调用时,load text data segment,eagarly pagetable,但是只在VA中分配,PTE不分配

-
当要执行程序时,触发Page Fault
- read block/page from file into memory
- map men into pgtbl
- restart instruction
-
当内存耗尽时

- evict a page -> file
- use the just free page
- restart intruction
-
驱逐什么page? LRU and non-dirty
-
使用PTE中自定义的RW位实现LRU和dirty

memory mapped files
-
当执行ld,sd指令时

-
mmap(VA, len, protection, flags, fd, offset)映射PA到VA
-
unmap(VA, len) write back dirty block
Summary for Page Table
-
page tables + traps/page fault -> powerful elegent VM features
