1. Basic layout of memory and virtual memory
When talking about virtual storage, You can say a few things.
For 32-bit systems, most operating systems will move a part of the 4 GB memory space to the kernel for use, and applications cannot directly access this section of memory, which is called the kernel space. By default, Windows allocates 2 GB of High-address space to the kernel (OR 1 GB). By default, Linux allocates 1 GB of High-address space to the kernel. For details, see Chapter 10th "Programmer self-cultivation-links, loading and libraries"-memory
Linux Process address space distribution chart]:
Shows the Windows Process address space distribution chart:
2. Overview of virtual storage on Windows
Taking windows as an example, applications can call heap APIs ,. net garbage collector or C Runtime malloc APIs to allocate virtual memory, but all these implementations depend on the implementation of virtualalloc API. When the application uses up the address space, it then calls virtualalloc, and then may report an error (return NULL address). Use testlimit tool, http://download.sysinternals.com/files/TestLimit.zip,
This tool uses the command line parameter-R to continuously call virtualalloc until an error occurs. When running in a 32-bit operating system, the entire 2 GB address space is consumed:
We noticed that Mb is not equal to 2 GB, but other code and data of testlimit, including executable code and system DLL, should be the cause of different results, using Process Manager, you may see the actual storage consumption:
Some applications, such as SQL Server or Microsoft's Active Directory, manage a large amount of data structures. The more data loaded into the address space, the better the performance. Therefore, the boot option/3 GB is introduced in Windows NT4 SP3, which allows 3 GB of 4 GB address space to be provided to the user State, that is, to make the system (kernel) the address space is reduced by 1 GB. Windows XP and win2003 also introduced option/userva to migrate memory fragments between 2 GB and 3 GB. For details, see:
To make full use of space larger than 2 GB, the process must set a large address ID in the EXE file. Because the height of 2 GB space is always 0, this height is also the identifier of the user State. If 2G is exceeded, the high position will be 1. If there is no relevant processing, an error will occur.
Examples, lsass.exe (the directory service will be used by users, smss.exe (Session Manager Process), esentutl.exe (directory Jet Database Repair Tool). We can use dumpbin to check the flag value in exe. dumpbin is a tool provided by Visual Studio, as shown in:
Testlimit also uses the big address identifier:
3. virtual storage in a 64-bit environment
In 64-bit windows, the address space is much more than 4 GB. In this case, Windows can use the maximum 4 GB of 32-bit programs, while the remaining address space is left to the virtual memory of the operating system. If you run testlimit in 64-bit windows, you can see that it uses all the 32-bit address spaces:
The 64-bit program uses 64-bit long pointers. Their theoretical maximum address space is 2 ^ 64, however, Windows does not provide a relatively average address space for users to enter programs and operating systems. Instead, it divides some areas into user processes, and the other part into different system memory resources, for example, the system page table entry (PTE), File Cache, page buffer pool, and non-page buffer pool.
The size of the process address space in IA64 and x64 systems varies depending on the application's overall needs for memory to support the address space (pages in the page table and the buffer translation table TLB ). For x64 systems (AMD), 8 TB is used, while for IA64 systems, 7168 GB (7 TB) is used. The difference is 1 TB in the middle, mainly due to IA64, 1 TB space is used for the top-level page Directory to reserve the wow64 ing table of the system. For Windows of IA64 and x64 versions, the address space of various resources is about 128 GB (for example, a non-page pool is allocated with a 28 GB address space), with only one exception, file buffering, it allocates 1 TB of address space. In general, the address space of a 64-bit process looks like this:
It can be seen that there is a large space gap in the figure, which may be used for future address extension. When you run the 64-bit version testlimit, it will consume 8 TB, which will be the address space range that it can manage: