Explore windows virtual memory

Source: Internet
Author: User

For the use of virtual memory in the process address space, the userProgramYou must go through the reserve and commit stages to use an address range. The intention of "retaining an address range" is to keep the address range, but it is not actually used because the address range does not occupy any physical memory or other external storage space, therefore, there is no substantial overhead. This makes sense for some programs that require continuous address space. They can retain a large range of addresses at the beginning and will be used later. The "Submit address range" means that the address will consume physical memory after all. Because Windows supports switching between physical memory and page files, the amount of memory that can be submitted is, the total available physical memory removes the amount of physical memory used by the system, plus the size of the page file.

In Windows API, the application uses virtualalloc or virtualallocex to retain or submit the address range. Later, the virtualfree or virtualfreeex function is used to remove the submitted address range or completely release the address range. The release status indicates that the instance is retained. Therefore, any page address range in the process address space must be in one of the three States: idle, reserved, or submitted.

For submitted pages, the System Schedules them based on the total memory usage. When the physical memory is insufficient, the system will select some pages to swap them out to the memory file and change them back when they are used again. Generally, applications do not need to intervene in the system's page scheduling mechanism. In some special cases, applications can also use the virtuallock function to lock submitted pages so that they are always in the physical memory. In the future, they will stop using the virtualunlock function.

The following is an example to illustrate some windows virtual memory management problems.


The output result is 0.

Status 1: at the beginning of the first system ("pause") Statement, the program has not been allocated virtual memory.
Status 2: The second system ("pause") Statement has been retained and submitted to the virtual memory. The submit size has changed, increasing by about 1 GB, but the memory (dedicated working set ), that is, the number of physical memory pages in use by the process does not increase by 1 GB. That is to say, when a commit address range is reached, the system does not actually allocate physical memory pages. Analyze the work done by retaining and submitting the system. Virtual address space management records the status of virtual address segments through the VAD tree and VaD bitmap. During the retention process, the system searches for a qualified range and returns the starting address based on the usage of the virtual address space, and updates the VAD tree and VaD bitmap. Currently, access is unavailable, and access violations occur. The submission process records the usage overhead of the physical storage, and assigns and sets the attributes of the page Directory and the PTE (page table item. A physical page is accessible but not assigned to a process. When a page error occurs during access, the page processing routine allocates the actual physical page.
Status 3: after the third system ("pause") Statement is accessed on each page, a page error occurs during each access according to the number of page errors, the page error processing routine allocates physical memory pages. The system allocates physical memory pages to the entire address segment only after all pages are accessed.
The output result shows that all pages allocated by the system are initialized to 0.


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.