This article reprinted is the network, only the narrative method,,,
First question: Turn off page allocation in XV6
Modify the sys_sbrk () function in sysproc.c to:
1 intSYS_SBRK (void)2 {3 intaddr;4 intN;5 if(Argint (0, &n) <0)6 return-1;7addr = proc->sz;8Proc->sz + =N;9 //if (Growproc (n) < 0)Ten //return-1; One returnaddr; A}
After recompiling, it's OK.
Second question: Implement lazy page allocation
1. Because we need to call the int mappages in vm.c (pde_t pgdir, voidva, uint size, uint PA, int in trp.c) Perm) function, so to remove the original static!!!
2:declare int mappages (pde_t pgdir, voidva, uint size, uint PA, int perm) functions in trp.c , Note to declare before the call!
3. Add the following code to the Defaut portion of the void Trap (struct trapframe *tf) in trap.c , and note that it should be placed after the existing if module!
1 Char*Mem;2 UINTA;3A =Pgrounddown (Rcr2 ()); Rcr2 () is the call to get the start memory address of this process4 UINTNewsz = proc->sz; Newsz is the cheated memory address (the amount's memory needed by the process)5 for(; a < newsz; A + =pgsize) {6MEM =Kalloc ();7memset (Mem,0, pgsize);8Mappages (Proc->pgdir, (Char*) A, pgsize, v2p (MEM), pte_w|Pte_u);9 }Ten return;
Recompile, you are done!
XV6-----Lazy Page Allocation