Page table

On this page 7

A page table is the data structure that an operating system maintains to translate virtual page numbers into physical page frame numbers, together with permission and status bits for every mapped page. In memory management, it is the central record of an address space: the memory management unit (MMU) walks it on every translation that misses the translation lookaside buffer, and the kernel edits it whenever memory is allocated, freed, shared or swapped out.

Each process normally has its own page table, which is why two programs can use the same virtual address without touching each other’s data. The page table therefore underpins virtual memory, memory protection and demand paging at the same time.

How a page table translates virtual addresses

Address translation splits a virtual address into a virtual page number and an offset within the page. With the common 4 KiB page size, the lowest 12 bits form the offset and stay unchanged, while the remaining bits select a page table entry (PTE). The PTE supplies the physical frame number, which is combined with the offset to form the physical address.

The hardware performs this lookup without software help on x86-64 and ARMv8, because the MMU reads the page table directly from memory. The kernel only loads the base address of the top-level table into a control register, such as CR3 on x86-64 or TTBR0_EL1 on ARMv8, during each context switch between processes.

The following table shows the fields a typical PTE holds and what each one controls.

FieldSize or formFunction
Present bit1 bitMarks whether the page is in physical memory; clear means a page fault
Frame numberUp to 40 bits on x86-64Physical page frame that backs the virtual page
Read/write bit1 bitAllows or forbids writes to the page
User/supervisor bit1 bitRestricts the page to kernel mode when cleared
Accessed bit1 bit, set by hardwareRecords use for page replacement decisions
Dirty bit1 bit, set by hardwareRecords writes so modified pages are saved before eviction
No-execute bit1 bit (NX or XN)Prevents instruction fetches from data pages
Typical fields of a page table entry

Page table structures: flat, multilevel, inverted and hashed

A flat single-level table is impractical for large address spaces: a 48-bit space with 4 KiB pages would need about 68 billion entries per process. Operating systems therefore use structures that store entries only for regions actually in use.

The dominant design is the multilevel page table, a radix tree in which each level indexes the next. x86-64 uses four levels for 48-bit addresses (PML4, PDPT, page directory, page table) and five levels for 57-bit addresses on processors with LA57. Each table occupies one 4 KiB page and holds 512 eight-byte entries, so each level consumes 9 bits of the address. The table below compares the main structures.

StructureHow it is indexedMemory costTypical use
Single-levelDirect array by page numberProportional to whole address spaceSmall 32-bit or embedded systems
MultilevelRadix tree, one index per levelProportional to used regionsx86-64, ARMv8, RISC-V Sv39 and Sv48
InvertedOne entry per physical frameProportional to physical memoryHistoric IBM POWER and some research systems
HashedHash of virtual page numberProportional to mapped pagesPowerPC hashed page table, sparse 64-bit spaces
Main page table organizations

The trade-off is between memory overhead and lookup cost. A four-level walk can require four memory reads before the data access itself, which is why the result is cached in the TLB and why processors also keep paging-structure caches for upper levels.

How the page table works with the TLB, page faults and huge pages

The page table is the authoritative mapping, while the translation lookaside buffer is a small hardware cache of recent translations. A TLB hit completes in about one cycle; a miss triggers a page walk that may cost tens to hundreds of cycles depending on cache hits. Whenever the kernel changes or removes a PTE, it must invalidate stale TLB entries, on multicore systems through an inter-processor interrupt known as a TLB shootdown.

A cleared present bit causes a page fault, and the kernel decides what it means: a page never loaded under demand paging, a page swapped to disk, a copy-on-write page after fork, or an invalid access that ends in a segmentation fault. The page table is thus also the mechanism the kernel uses to intercept accesses. The table below relates the page table to its closest neighbors.

ConceptRelation to the page tableWhere it lives
Translation lookaside bufferCaches translations read from the page tableInside the CPU core
Memory management unitWalks the page table and enforces its permission bitsCPU hardware
Page faultRaised when a PTE is absent or forbids the accessException handled by the kernel
Huge pagesMap 2 MiB or 1 GiB with one upper-level entrySame page table, shorter walk
Page frameThe physical block a PTE points toPhysical RAM
Page table and related memory management concepts

Huge pages end the walk early: a page directory entry can map 2 MiB directly and a PDPT entry 1 GiB. This reduces TLB pressure and walk depth, which benefits databases and virtual machines with large working sets.

Page tables in virtualization and security

Virtual machines add a second level of translation. With nested paging, called Extended Page Tables (EPT) on Intel and Nested Page Tables (NPT) on AMD, the guest page table maps guest virtual to guest physical addresses, and the hypervisor table maps guest physical to host physical addresses. A worst-case nested walk with four levels each can need up to 24 memory references, which makes huge pages especially valuable for virtual machines.

Page tables also carry security boundaries. Kernel page table isolation (KPTI), introduced against the Meltdown vulnerability, keeps a separate, minimal page table for user mode so that kernel memory is not mapped while user code runs. The no-execute bit enforces W^X policies, which forbid pages that are both writable and executable.

Overheads, limitations and common misconceptions

Page tables consume real memory: a process that maps memory sparsely across a large range can need many megabytes of page tables, and systems with thousands of processes sharing large mappings may spend gigabytes on them. Linux reports this cost as PageTables in /proc/meminfo.

  • Misconception: one table per system. Each process has its own tree, although kernel mappings are shared among them.
  • Misconception: the page table stores data. It stores only mappings and permissions, never page contents.
  • Mistake: ignoring TLB shootdown cost. Frequent munmap or mprotect calls on many cores can dominate runtime.
  • Mistake: assuming a cleared present bit means swapped. It can equally mean not yet allocated or an invalid address.

A plain-language summary

A page table is a directory that tells the computer where each piece of a program really sits in memory. Programs work with imaginary addresses, and the page table converts each one into a real location in the memory chips.

Picture a large office building where every company uses room numbers starting at 1. The reception desk keeps a list that says company A’s room 1 is really room 412. The page table is that list, and it also notes who may enter each room. The main idea is that every program believes it has the building to itself, while the system keeps them safely apart.

An example from practice

A platform engineer operates a Linux host running an in-memory database with a 256 GiB buffer pool. Profiling shows that about 15 percent of CPU cycles go to page walks after TLB misses, and /proc/meminfo reports roughly 500 MiB of page tables, because the pool is mapped with 4 KiB pages across 64 worker processes.

The engineer reserves 1 GiB huge pages at boot and configures the database to allocate its pool from them. Each process now needs only 256 upper-level entries for the pool instead of tens of millions of PTEs. Page table memory falls to a few megabytes, walk overhead becomes negligible and query throughput improves by about 10 percent on the same hardware.