MIT6.S081 lab3 page tables
lab3主要是帮助复习页表、PTE、物理页之间的关系。
Speed up system calls
When each process is created, map one read-only page at USYSCALL (a VA defined in memlayout.h
). At the start of this page, store a struct usyscall
(also defined in memlayout.h
), and initialize it to store the PID of the current process.
实验指导已经很直白了,在进程创建时映射一块共享页,用来存储进程id。过程:从freelist分配一页空间,然后映射到用户进程指定地址,然后初始化这个页(存入当前进程的pid)。
Print a page table
实际上就是熟悉三级页表的过程。
1 | void recursive_vmprint(pagetable_t pagetable, int level){ |
从PTE到PA的过程 uint64 child = PTE2PA(pte);
,然后将它用作页表入口地址(pagetable_t) child
。
1 | typedef uint64 pte_t; |
xv6中的指针就是64位无符号整数。
Detecting which pages have been accessed
阅读手册可以知道PTE的第6位是访问标志位,通过观察这个标志就可以知道这个页面是否被访问。
硬件在执行访存指令后就会自动把相应页的PTE_A置为1.
注意:Be sure to clear PTE_A
after checking if it is set. Otherwise, it won’t be possible to determine if the page was accessed since the last time pgaccess()
was called (i.e., the bit will be set forever).
1 | int pgaccess(pagetable_t pagetable, uint64 addr, int n, uint64 uaddr) { |
MIT6.S081 lab3 page tables