liveBook · Manning

Translation lookaside buffer

As explained in Rust in Action: Systems programming concepts and techniques

A translation lookaside buffer is a processor cache of recently used virtual-to-physical address translations.

A translation lookaside buffer, or TLB, is the CPU’s cache of recently translated memory addresses. Programs use virtual addresses, but accessing RAM requires physical addresses. The CPU’s memory management unit (MMU) performs the translation using mappings managed by the operating system. section 6.4.1 section 6.4.3

Without a cached translation, a memory access can require one lookup for the mapping and another for the requested data. Keeping recent translations in fast CPU memory helps avoid that worst case. Addresses are grouped into pages, typically 4 KB, so a mapping is not needed for every variable. section 6.4.3

Why data layout can matter

An x86 TLB might hold translations for around 100 pages. A program that reaches beyond that capacity can pay a performance cost. This is one reason to keep data structures lean and avoid deeply nested structures; the precise behavior depends on the CPU and operating system. section 6.4.3

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Defines the cache and explains its purpose through memory lookups and page capacity, without detailing its internal operation.
Examples
Uses a two-lookup worst case, typical 4 KB pages, and an approximate 100-page x86 capacity.
What it assumes
Introduces the MMU, page tables, and address translation while assuming only a basic notion of programs accessing memory.
What you can do after
Evaluate/understand why memory-access patterns and deeply nested data structures can make address translation costly.
How it connects
Links the TLB to virtual memory, the memory management unit, page tables, pages, and data-structure layout.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.