Today we’re going to dig into Pages and Page Tables. If you are new to Memory Management, or need a quick refresher on the basics, I strongly recommend reviewing our Demystifying /3GB and x86 Virtual Address Space posts first.
When a program is first loaded, the logical memory address range of the application is divided into fixed size units called pages. As each page is referenced by a program, it is mapped to a physical page that resides in physical memory. The mapping is dynamic which ensures that logical addresses that are frequently referenced reside in physical memory. Remember that each individual process that is launched is allocated its own virtual address space and application program threads are only permitted to directly access the virtual memory locations that are associated with their parent process’ address space. This is where Page Tables come into play.
Page Tables are built for each process address space. The Page Table maps logical virtual addresses for a process to physical memory locations. The location for a set of Page Tables for a process is passed to the processor hardware during a context switch. The processor refers to the Page Tables to perform virtual to physical address translation as the process threads are executed. At this point, there are a few terms to become familiar with when dealing with Pages and Page Tables:
- Working Set Pages: The active pages of a process currently backed by RAM (also known as Resident Pages)
- NonResident Pages: Virtual memory addresses that are allocated, but not backed by RAM
- Committed Pages: Pages that have Page Table Entries. Committed Pages may be either resident or nonresident