Mit-xv6/jos Hw:lazy Page Allocation

Source: Internet
Author: User

XV6 using lazy allocation

When the process requires more memory, the call to malloc requests more heap memory, and the system calls SBRK () to complete the work

However, some processes will apply for a large amount of memory at a time, but may not be used at all, for example sparse array

So the complex kernel involves deferring the actual allocation work to the actual use, the page fault, and then the actual assignment.

Part1.

The actual implementation of the system call SBRK SYS_SBRK modified, only the memory space of the process to increase n, not the actual allocation

System call malloc use is SBRK


The address returned is the beginning of the newly allocated address space, which is the end of the original address space, where the virtual address

Then the result of running at this point is


Because when you need to run echo in the shell, the code that runs to the following section


That is, when you run malloc, the return is successful, but when the program tries to manipulate the memory area that the CMD points to, it finds that the memory area is not owned by the current process, because it is not assigned at all in SYS_SBRK.

Part2.

Modify the code in the TRAP.C so that the system can handle the above error

In Trap.c, when the discovery is a page fault error, you can follow the current process of the Proc->sz to actually allocate memory, note that this time the SZ size is not the actual size, but the desired size value

So the first should get the virtual address of the page fault moment, the part after that address should be allocated but actually not allocated, and the actual need to allocate how much, should be based on the size of Proc->sz to be determined.

Because the address at the time of page fault is the address that we return to the process after malloc, and this address is the original Proc->sz, so the size of the virtual address should be the actual size of the memory


Mit-xv6/jos Hw: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.