Lab 3 Page Table
题目链接
我的问题:
1 每个进程的kernel stack是干啥的来着?在何时初始化的?
题目2:A kernel page table per process (hard)
1 一些题目要求
Your first job is to modify the kernel so that every process uses its own copy of the kernel page table when executing in the kernel. Modify struct proc to maintain a kernel page table for each process, and modify the scheduler to switch kernel page tables when switching processes.
思路:
1 首先得修改每个proc的结构体,在里面新添加一份page table,还得找地方给这个page table初始化。
2 Make sure that each process’s kernel page table has a mapping for that process’s kernel stack.
XV6原来代码中 procinit函数中把每个process的kernel stack初始化映射到kernel page table中
// initialize the proc table at boot time.
void
procinit(void)
{
struct proc *p;
initlock(&pid_lock, "nextpid");
for(p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
// Allocate a page for the process's kernel stack.
// Map it high in memory, followed by an invalid
// guard page.
char *pa = kalloc();
if(pa == 0)
panic("kalloc");
uint64 va = KSTACK((int) (p - proc));
kvmmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
p->kstack = va;
p->kstack_pa = pa;
}
kvminithart();
}
// Switch h/w page table register to the kernel's page table,
// and enable paging.
void
kvminithart()
{
w_satp(MAKE_SATP(kernel_pagetable));
sfence_vma();
}
在XV6操作系统中,kalloc 和 kfree 是内核中用于物理内存页管理的核心函数。它们负责分配和释放物理内存页(每个页的大小为4KB),为内核其他模块(如进程创建、文件系统、页表等)提供动态内存支持。