Windows Address space allocation

Source: Internet
Author: User

  

Most of this address space is idle when the system creates a process for it to create its address space at the same time. In order to use this part of the address space, we must call VirtualAlloc to allocate the region. The operation of the assigned area is called a reservation.
When an application is reserving an address space area, the system ensures that the starting address of the predetermined region is exactly the integer multiple of the allocated granularity. The granularity of allocation varies depending on the platform. Now all platforms are allocated with the same granularity. Size is 64KB.
For the size of the intended address space, the system ensures that the size of the area is exactly the number of times the system page size is an integer. The X86 and x64 systems use a page size of 4KB.
If the application is scheduled for a block size of 10KB address space area. The system then takes the request to an integral multiple of the page size. In the x86 and x64 systems, the system will reserve a size of 12KB area.
When the program no longer needs to access the intended address space area, the zone should be freed to call the VirtualFree function to complete.

Allocating physical storage areas
The previously scheduled address space is simply a token that the block space is already in use, and other programs cannot pre-book this block area again. In order to use the predetermined address space area, we must also allocate physical memory and map the memory to the predetermined region. This process is called allocating physical memory.
You can allocate physical memory by calling VirtualAlloc. The allocation of physical memory is on a page-by-unit. There is no need to allocate physical space for all predetermined areas. You can redeploy only the areas you need to use. After allocation, the program can access the memory space.
When the program does not need to access the allocated physical memory in the predetermined area, the physical memory should be released. This process is known as the undo allocation of physical memory. This is done by calling the Virtualfreee function.
Physical memory and page Exchange files
Today's operating systems can virtualize disks to extend memory, a part of which is called a paging file or a paging file that contains virtual memory that can be used by a program.

The memory and the magnetic paging file together form the total memory.

The paging file increases the total amount of available memory for the application. In fact, the operating system works with the CPU, saving a portion of the memory to the paging file, and then loading the corresponding portion of the paging file into memory when the application is in use.
When the application calls the VirtualAlloc function to transfer the physical memory to the address space area, the space is actually obtained from the hard disk's paging file.
In order to be able to use virtual memory, when a thread tries to access a byte in memory, the CPU must know whether the byte is in memory or on disk.
When a thread tries to access an area in the owning process's address space, two things can happen:
One: The area to be accessed is in memory. At this point the CPU maps the virtual address of the data to the physical address of the memory and then accesses the memory.
Two: not in memory, but in the paging file. This unsuccessful visit will trigger a missing pages interrupt. When a page break occurs, the interrupt handler finds an idle sheet in memory and then copies the data from the paging file into memory.

When the user executes a program, the system opens the EXE file for the application. Calculates the size of the code and data for the application. Then the system will book an address space and indicate that the physical memory associated with the area is the EXE file itself. The system does not allocate space from the paging file, but instead takes the exe file as the fallback memory for the program's predetermined space. This way, the program loads quickly, and the paging file can be kept in a reasonable size.

When a program is located on a hard disk with a file image as the physical memory corresponding to the address space area, we call this file image a memory-mapped file. When a DLL or EXE is loaded, the address space is automatically scheduled and the file image is mapped to the region. In addition, the system allows us to manually map data files to the address space.
Windows can use multiple pages to swap files. If more than one paging file is on a different physical hard disk, the system can run faster. We can swap the file size in the Settings page.

Windows Address space 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.