MIT 6.S081 Lab pgtbl
Compulsory exercises
Preparation
-
reading
-
To start the lab, switch to the pgtbl branch:
1 | git fetch |
Speed up system calls (easy)
-
getpid()作为系统调用,每次调用时需要跳入内核并跳出,为加速pid的获取,ugetpid()函数可以通过分配虚拟地址将pid存入其中,从而实现不跳转不trap获取pid
-
修改内核函数实现ugetpid()
-
map one read-only page at USYSCALL in proc_pagetable()
1 | if(mappages(pagetable, USYSCALL, PGSIZE, |
-
allocate and initialize the page in allocproc()
1 | // Allocate a usyscall page before creating a new pagetable |
-
free the page in freeproc()
1 | if(p->usyscall) { |
-
umap USYSCALL in proc_freepagetable()
1 | uvmunmap(pagetable, USYSCALL, 1, 0); |
Print a page table (easy)
-
RISC-V架构中的三级页表需要通过递归打印
-
添加内核函数vmprint()
-
prototype for vmprint in defs.h
1 | void vmprint(pagetable_t); |
-
put vmprint() in vm.c
1 | // help function |
Detecting which pages have been accessed (hard)
-
探测页表中的页是否被访问过
-
添加pgaccess系统调用
-
implementing sys_pgaccess() sysproc.c
1 |
|
-
define PTE_A, the access bit, in riscv.h 参考下图PTE_A的位置
1 |
-
add pgaccess() in vm.c
- 注意第一个page对应mask最低有效位
- 注意探测一个带有PTE_A的page过后要消除PTE_A
1 | uint64 |
Optional challenge exercises
-
Use super-pages to reduce the number of PTEs in page tables.
-
Unmap the first page of a user process so that dereferencing a null pointer will result in a fault. You will have to start the user text segment at, for example, 4096, instead of 0.
-
Add a system call that reports dirty pages (modified pages) using PTE_D.
MIT 6.S081 Lab pgtbl