Translation lookaside buffer

Also known as: TLB

On this page 8

A translation lookaside buffer (TLB) is a small, fast hardware cache of recent address translations that the memory management unit consults before walking the page tables. In memory management, it is the component that makes virtual memory practical, because without it every memory access would require several additional reads of page table entries.

The TLB sits inside the processor core, close to the load and store pipeline. Operating systems do not normally fill it directly, but they control its contents indirectly by changing page tables, switching address spaces and issuing explicit invalidation instructions.

How a TLB lookup works

Every load, store and instruction fetch uses a virtual address that must be translated into a physical address. The processor splits the virtual address into a virtual page number and an offset, then searches the TLB for an entry that matches the page number.

  1. The core presents the virtual page number to the TLB, usually in parallel with the first-level cache lookup.
  2. On a TLB hit, the entry supplies the physical frame number and permission bits within about one cycle.
  3. On a TLB miss, a hardware page walker, or on some architectures the operating system, reads the page table levels in memory.
  4. If the walk finds a valid entry, the translation is inserted into the TLB and the access is retried.
  5. If no valid entry exists, the processor raises a page fault and the kernel takes over.

Each entry stores more than the frame number. It also holds permission bits (read, write, execute, user or supervisor), a valid bit, and often an address space identifier that tells which process the translation belongs to. Permission checks therefore happen on every access at no extra cost.

TLB organization and key parameters

Modern processors use a multilevel TLB hierarchy, much like the data cache hierarchy. Small first-level TLBs are extremely fast, while a larger second-level TLB catches most of their misses. Exact sizes vary by microarchitecture, so the values below are typical orders of magnitude rather than fixed specifications.

ParameterTypical rangeWhat it affects
L1 data TLB entries48 to 96 for 4 KiB pagesHit rate of hot data accesses
L1 instruction TLB entries64 to 256Instruction fetch performance
Second-level TLB entries1,024 to 4,096 or moreMiss rate for large working sets
Hit latencyAbout 1 cycle for L1, several cycles for L2Load-to-use delay
Miss penaltyTens to hundreds of cyclesCost of each page walk
AssociativityFully associative to 12-wayConflict misses
Typical TLB parameters in current desktop processors

The most useful derived metric is TLB reach: the number of entries multiplied by the page size. A 1,536-entry TLB with 4 KiB pages covers only about 6 MiB of memory, which is far smaller than the working set of a database or a virtual machine host.

Page size and TLB reach

Larger pages are the main tool operating systems use to extend TLB reach without adding hardware entries. One entry for a large page replaces hundreds of entries for small pages, so the same TLB covers much more memory.

Page sizeReach of 1,000 entriesTypical use
4 KiBAbout 4 MiBDefault for most allocations
2 MiBAbout 2 GiBDatabases, JVM heaps, transparent huge pages
1 GiBAbout 1 TiBHypervisors, very large in-memory datasets
Page sizes on x86-64 and their effect on reach

The trade-off is internal fragmentation and allocation difficulty. A 2 MiB page must be physically contiguous and aligned, and memory fragmentation can make such regions scarce on long-running systems. Huge pages also make copy-on-write and swapping coarser, so the kernel must balance TLB efficiency against memory flexibility.

TLB management by the operating system

Because the TLB caches page table contents, the operating system must keep it consistent whenever translations change. A stale entry could let a process access memory it no longer owns, which makes TLB invalidation a correctness and security requirement, not merely an optimization.

EventRequired actionPerformance impact
Context switchFlush user entries or switch address space identifierLost warm entries after the switch
Unmapping a pageInvalidate the single entrySmall, local cost
Permission changeInvalidate affected entriesRequired for copy-on-write correctness
Change on a multicore systemTLB shootdown via inter-processor interruptsCan cost microseconds per event
Kernel page table isolationSeparate kernel and user tablesExtra switching overhead without identifiers
Events that require TLB maintenance

Address space identifiers (called PCID on x86-64 and ASID on Arm) let entries from several processes coexist, so a context switch no longer requires a full flush. A TLB shootdown is the most expensive case: the initiating core must interrupt every other core that might cache the translation and wait for acknowledgment.

The TLB is easy to confuse with other parts of the memory system. It caches translations, not data, and it is distinct from the structures that define those translations.

ComponentWhat it storesLocation
TLBRecent virtual-to-physical translationsInside the processor core
Page tableComplete translation map of an address spaceMain memory
Memory management unitTranslation logic including the TLB and page walkerProcessor
CPU data cacheCopies of memory contentsProcessor, by cache level
Page cacheFile data held in RAM by the kernelMain memory, managed in software
TLB and neighboring memory management components

Performance problems and common mistakes

TLB effects are often invisible in ordinary profiling because they appear as general memory stalls. Hardware performance counters for data TLB misses and page walk cycles reveal them directly.

  • Random access over huge arrays produces a TLB miss on almost every access; huge pages or better data locality reduce it.
  • Frequent mapping changes in allocators trigger shootdowns that hurt multithreaded throughput.
  • Assuming a flush is free is a mistake: losing warm entries after a context switch can cost more than the switch itself.
  • Disabling address space identifiers to work around firmware issues removes a major mitigation for page table isolation costs.
  • Virtual machines double the walk, because nested paging can require up to about two dozen memory references per miss.

The idea in brief

Programs use made-up addresses, and the computer has to look up where each one really lives in memory. That lookup uses a large directory stored in memory, which is slow to consult every time.

The translation lookaside buffer is like a sticky note of recently used directory entries. If the answer is on the note, the processor gets it instantly. Most lookups hit the note, which is why virtual memory feels fast.

A practical scenario

A database engineer runs an analytics server with 256 GiB of RAM and a 180 GiB in-memory buffer pool on 4 KiB pages. Performance counters show that page walks consume about 15 percent of CPU cycles, because queries touch rows scattered across the whole pool.

The engineer reserves 2 MiB huge pages at boot and configures the database to allocate its buffer pool from them. The number of page table entries needed to map the pool drops by a factor of 512, and the TLB now covers gigabytes instead of megabytes.

After the change, page walk cycles fall to under 3 percent and average query latency improves by roughly a tenth, a measurable gain with no hardware upgrade.