What is TLB (translation lookaside buffer)?

A small cache that holds recent virtual-to-physical address translations. It avoids walking the page tables in memory on every access, speeding up address translation.

Field: CPUs and architecture

Japanese name: TLB(変換索引バッファ)

How a TLB lookup works

On every fetch, load and store, the memory management unit (MMU) splits the virtual address into a virtual page number and a page offset; with 4 KB pages the low 12 bits are the offset and pass through untranslated. On a TLB hit, the stored physical page number is joined to the offset and permissions are checked in the same step. On a miss, a page-table walk reads the tables in memory, up to four levels for 48-bit addresses with 4 KB pages, and refills the entry. A page fault occurs only if the page-table entry is invalid or forbids the access.

TLB reach and huge pages

TLB reach is entries times page size: 64 entries of 4 KB cover only 256 KB, while the same 64 entries holding 2 MB huge pages cover 128 MB. Because TLBs hold only tens to thousands of entries, programs with large or scattered working sets, such as databases and virtual machines, can spend a noticeable share of time walking page tables. Remedies include huge pages, a larger second-level TLB behind small first-level ones, keeping page-table entries in the data caches, and better locality.

TLB vs. page table vs. data cache

The page table is the authoritative mapping, built by the operating system per process and stored in memory; the TLB caches recently used entries from it, so it holds translations, not data. Data caches are separate but cooperate closely: many L1 caches are virtually indexed and physically tagged (VIPT), selecting the set with untranslated offset bits so the set read and TLB lookup run in parallel, then comparing the physical tag. A cache miss is handled in hardware, whereas a page fault is an exception serviced by the OS.

Context switches, ASIDs and virtualization

Processes reuse the same virtual addresses, so stale translations must not survive an address-space change. Without tags the TLB is flushed on every switch, causing a burst of misses; tagging entries with an address space identifier (ASID) lets them be reused when a process returns. Mapping the kernel into every address space means system calls need no switch. When the OS changes a mapping, it must invalidate matching entries on every core that may hold them. With nested paging and four-level tables in both guest and host, one miss can cost up to 24 memory accesses.

Try it: questions about TLB (translation lookaside buffer)

With 64 TLB entries and a 4 KB page size, how much memory can be accessed without TLB misses (the TLB reach)?

  1. A64 KB
  2. B256 KB
  3. C4 MB
Show answer and explanation

Answer: B. 256 KB

Each TLB entry holds the translation for one page, so TLB reach = entries × page size = 64 × 4 KB = 256 KB. Programs that frequently touch a wider range suffer more TLB misses. With 2 MB huge pages, for example, the same 64 entries reach 64 × 2 MB = 128 MB. 64 KB results from mistaking the page size for 1 KB, and 4 MB from mistaking it for 64 KB.

FAQ

What happens on a TLB miss?

The MMU (or an OS handler on some architectures) walks the page tables in memory to find the translation, installs it in the TLB and retries the access. If the page-table entry is invalid or the access is not allowed, a page fault is raised instead and the OS takes over.

How do you calculate TLB reach?

Multiply the number of TLB entries by the page size. For example, 64 entries × 4 KB = 256 KB, while 64 entries × 2 MB = 128 MB, which is why huge pages reduce TLB misses.

Is the TLB part of the CPU cache?

It is a cache, but of address translations rather than data. It sits beside the L1 caches and is usually looked up in parallel with them, but it never holds the memory contents themselves.

Questions that mention TLB (translation lookaside buffer) (6)

TLB (translation lookaside buffer) appears in 7 practice questions across 3 topics, including Memory Hierarchy, CPUs and architecture, Performance Analysis.

  1. Which cache holds the results of translating virtual addresses into physical addresses to speed up address translation?
  2. Scanning the 2D C array a[i][j] with j in the inner loop, as above, tends to be faster than with i in the inner loop. Why?
  3. Why are L1 caches often virtually indexed and physically tagged (VIPT)?
  4. Which pair correctly states the main advantage and drawback of using large pages (huge pages)?
  5. Running two programs alternately on the same core can make each slower than running alone. What is the best explanation from a cache perspective?
  6. Which is an example of what CPU performance counters (the PMU) can count?

Books on CPUs and architecture Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary