Hardware Reference
In-Depth Information
Windows 7 Virtual Memory
In Windows 7, every user process has its own virtual address space. In the
32-bit version of Windows 7, virtual addresses are 32 bits long, so each process has
4 GB of virtual address space. The lower 2 GB are available for the process' code
and data; the upper 2 GB allow (limited) access to kernel memory, except in Server
versions of Windows, in which the split can be 3 GB for the user and 1 GB for the
kernel. The virtual address space is demand paged, with a fixed page size (4 KB
on the Core i7). The address space for the 64-bit version of Windows 7 is similar,
however, the code and data space is the lower 8 terabytes of the virtual address
space.
Each virtual page can be in one of three states: free, reserved, or committed. A
free page is not currently in use and a reference to it causes a page fault. When a
process is started, all of its pages are in free state until the program and initial data
are mapped into its address space. Once code or data is mapped onto a page, the
page is said to be committed . A reference to a committed page is mapped using
the virtual memory hardware and succeeds if the page is in main memory. If the
page is not in main memory, a page fault occurs and the operating system finds and
brings in the page from disk. A virtual page can also be in reserved state, meaning
it is not available for being mapped until the reservation is explicitly removed. Re-
served pages are used when a run of consecutive pages may be needed in the fu-
ture, such as for the stack. In addition to the free, reserved, and committed attrib-
utes, pages also have other attributes, such as being readable, writable, and ex-
ecutable. The top 64 KB and bottom 64 KB of memory are always free, to catch
pointer errors (uninitialized pointers are often 0 or
1).
Each committed page has a shadow page on the disk where it is kept when it is
not in main memory. Free and reserved pages do not have shadow pages, so refer-
ences to them cause page faults (the system cannot bring in a page from disk if
there is no page on disk). The shadow pages on the disk are arranged into one or
more paging files. The operating system keeps track of which virtual page maps
onto which part of which paging file. For (execute only) program text, the ex-
ecutable binary file contains the shadow pages; for data pages, special paging files
are used.
Windows 7, like System V, allows files to be mapped directly onto regions of
the virtual address spaces (i.e., runs of pages). Once a file has been mapped onto
the address space, it can be read or written using ordinary memory references.
Memory-mapped files are implemented in the same way as other committed
pages, only the shadow pages can be in the disk file instead of in the paging file.
As a result, when a file is mapped in, the version in memory may not be identical
to the disk version (due to recent writes to the virtual address space). However,
when the file is unmapped or is flushed, the disk version is updated from memory.
Windows 7 explicitly allows two or more processes to map in the same file at
the same time, possibly even at different virtual addresses. By reading and writing
 
Search WWH ::




Custom Search