XV6-----Lazy Page Allocation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.