Virtual address space
||It has been suggested that this article be merged into Virtual memory. (Discuss) Proposed since August 2012.|
||This article relies largely or entirely upon a single source. (August 2012)|
||An editor has expressed a concern that this article lends undue weight to certain ideas, incidents, controversies or matters relative to the article subject as a whole. (August 2012)|
In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating systems such as OpenVMS, UNIX, Linux, and Windows NT. This is beneficial for different purposes, one is security through process isolation. An address generated by the process is called logical address (virtual address) and it is mapped to the virtual address space.
Virtual memory is easiest to comprehend if one thinks in terms of the VAS, and not the physical memory of the machine nor the size of its page file. Byte values in the VAS come only from byte values in a file. The OS manages the mapping between the VAS and the files that hold its values.
Each time an application is run on an operating system (OS), the OS creates a new process and a new VAS for this process.
Physical memory comes in various flavors: on-chip cache, off-chip cache, and system memory. As far as the process is concerned, system memory is just another level of cache used by the OS. System memory has a lot to do with performance, but nothing to do with the architecture of a process. The process architecture is based on the VAS. Physical memory is used by the OS to map values from file bytes to VAS addresses: process memory is VAS memory, not physical memory.
- In the following description, the terminology used will be particular to the Windows NT OS, but the concepts are applicable to other virtual memory operating systems.
When you run a new application on a 32-bit OS, the process has a 4 GiB VAS: each one of the memory addresses (from 0 to 232−1) in that space can have a single byte as value. Initially, none of them have values ('-' represents no value). Using or setting values in such a VAS would cause a memory exception.
0 4GB VAS |----------------------------------------------|
Then the application's EXE file is mapped into the VAS. Addresses in the process VAS are mapped to bytes in the exe file. The OS manages the mapping:
0 4GB VAS |---vvvvvvv------------------------------------| mapping |-----| file bytes app.exe
0 4GB VAS |---vvvvvvv----vvvvvv---vvvv-------------------| mapping ||||||| |||||| |||| file bytes app.exe kernel user
The process then starts executing bytes in the exe file. However, the only way the process can use or set '-' values in its VAS is to ask the OS to map them to bytes from a file. A common way to use VAS memory in this way is to map it to the page file. The page file is a single file, but multiple distinct sets of contiguous bytes can be mapped into a VAS:
0 4GB VAS |---vvvvvvv----vvvvvv---vvvv----vv---v----vvv--| mapping ||||||| |||||| |||| || | ||| file bytes app.exe kernel user system_page_file
And different parts of the page file can map into the VAS of different processes:
0 4GB VAS 1 |---vvvv-------vvvvvv---vvvv----vv---v----vvv--| mapping |||| |||||| |||| || | ||| file bytes app1 app2 kernel user system_page_file mapping |||| |||||| |||| || | VAS 2 |--------vvvv--vvvvvv---vvvv-------vv---v------|
On a 32-bit Microsoft Windows installation, by default, only 2 GiB are made available to processes for their own use. The other 2GB are used by the operating system. On later 32-bit editions of Microsoft Windows it is possible to extend the user-mode virtual address space to 3 GiB while only 1 GiB is left for kernel-mode virtual address space by marking the programs as IMAGE_FILE_LARGE_ADDRESS_AWARE and enabling the /3GB switch in the boot.ini file.
On 64-bit Microsoft Windows, processes running 32-bit executables that were linked with the /LARGEADDRESSAWARE:YES option have access to 4 GiB of virtual address space; without that option they are limited to 2GB. By default, 64-bit processes have 8TB of user-mode virtual address space; Linking with /LARGEADDRESSAWARE:NO artificially limits the user-mode virtual address space to 2 GB.
- "Advanced Windows" by Jeffrey Richter, Microsoft Press