xv6-----lazy page allocation

本文转载是网络,只叙述方法,,,

 

第一问: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;

 

重新编译,大功告成!

 

转载于:https://www.cnblogs.com/tjulym/p/4976163.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值