本文转载是网络,只叙述方法,,,
第一问:Turn off page allocation in xv6
修改sysproc.c中的sys_sbrk()函数即可:
1 int sys_sbrk(void) 2 { 3 int addr; 4 int n; 5 if(argint(0, &n) < 0) 6 return -1; 7 addr = proc->sz; 8 proc->sz += n; 9 //if(growproc(n) < 0) 10 // return -1; 11 return addr; 12 }
重新编译后就OK了。
第二问:Implement lazy page allocation
1.由于我们需要在trp.c中调用vm.c中的int mappages(pde_t pgdir, voidva, uint size, uint pa, int perm)函数,所以要去除原本的static!!!
2..在trp.c中声明int mappages(pde_t pgdir, voidva, uint size, uint pa, int perm)函数,注意要在调用之前声明!
3.在trap.c中的void trap(struct trapframe *tf)的defaut部分添加以下代码,注意要在放在原本就存在的if模块后!
1 char *mem; 2 uint a; 3 a = PGROUNDDOWN(rcr2()); //rcr2() is the call to get the start memory address of this process 4 uint newsz = proc->sz; //newsz is the cheated memory address (the amount of memory needed by the process) 5 for(; a < newsz; a += PGSIZE){ 6 mem = kalloc(); 7 memset(mem, 0, PGSIZE); 8 mappages(proc->pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U); 9 } 10 return;
重新编译,大功告成!
时间: 2024-10-03 21:53:31