arthrop0d

Brief articles on varied topics.

TLB Shootdowns and Cross-Core Page-Table Invalidation

operating systemsperformancecomputer science

A TLB shootdown is the process of telling other CPU cores to discard cached virtual-memory translations after a page table changes. The operating system sends those cores an interrupt, each core invalidates the affected entries in its translation lookaside buffer (TLB), and the cores report that they are safe to continue.

The mechanism exists because page tables are shared memory, but TLBs are usually private to each core. Changing a page table does not automatically erase a stale translation already cached elsewhere.

The problem: page tables are not consulted on every access

A process uses virtual addresses: addresses generated by its code. The hardware translates each one to a physical address, the location in RAM, using page tables maintained by the operating system.

A page-table entry can say, for example:

Walking the page-table structure for every load and store would be too slow. The processor therefore caches recent translations in a translation lookaside buffer, or TLB. On a TLB hit, the processor can translate the address without reading the page tables.

This creates a consistency problem. Suppose a process is running on two cores and both cores have cached this translation:

Virtual page A → physical page X

The operating system then unmaps page A, perhaps because the process called munmap, grew a different mapping over that address, or changed a page’s permissions. It updates the page table to remove or replace the mapping.

Core 0 sees the new page table when it next walks it. Core 1 might still have the old mapping in its TLB and could continue accessing physical page X. If physical page X has been returned to an allocator and given to another process, that stale translation is a correctness and security failure.

Updating the page table is therefore not enough. Every relevant cached translation must be removed before the old mapping can safely be used again.

How a shootdown works

The details vary by processor architecture, but the usual sequence is:

  1. The operating system changes the page-table entry.
  2. It determines which other cores might have cached the old translation.
  3. It sends those cores a inter-processor interrupt (IPI), an interrupt generated by one processor for another.
  4. Each receiving core pauses its current work and enters a small kernel handler.
  5. The handler invalidates the relevant TLB entry, or performs a broader flush.
  6. Each core acknowledges completion.
  7. The initiating core proceeds once the required acknowledgements arrive.

On x86, instructions such as INVLPG can invalidate a translation for a particular virtual address. Newer mechanisms can invalidate sets of translations while preserving some unrelated entries. Other architectures provide their own TLB-invalidation instructions; ARM systems, for example, use TLBI operations.

The operating system does not necessarily interrupt every core in the machine. It can target cores currently running the same process, or cores that could have used the affected address space. A core that is not using that process’s page tables may not need an immediate flush. Operating systems track this state and may defer work for a core that cannot currently observe the mapping.

A shootdown also is not required for every page-table write. If the change affects an entry that no core could have cached, or if the old and new state are safe to coexist, the operating system may avoid one. But changes such as unmapping memory, changing permissions, or replacing a physical page commonly require invalidation.

Why the interrupt is necessary

There is generally no ordinary cache-coherence protocol that notices a page-table write and automatically invalidates matching TLB entries on every core. Cache coherence keeps ordinary data caches consistent; a TLB is a processor’s cached interpretation of memory-management metadata, and it needs explicit architectural operations.

The interrupt is a coordination mechanism. It makes another core stop running user code at a known point, execute the invalidation instruction locally, and confirm that it has done so. The initiating core can then rely on a global ordering such as:

after the shootdown completes, no participating core can use the old translation.

This matters even when the other core is not currently accessing that address. It may execute the access immediately afterward, and the stale TLB entry could otherwise still be valid.

Some processors support an address-space identifier, called an ASID or, on x86, a process-context identifier (PCID). It tags TLB entries with the address space that owns them, allowing entries from multiple processes to remain cached across context switches. These features reduce unnecessary flushing, but they do not remove the need to invalidate a changed mapping in every core that might hold it.

Where the performance cost appears

A shootdown has several costs beyond the invalidation instruction itself:

The effect is especially visible on machines with many cores. A change made by one thread can cause work on dozens of other cores, even if those cores rarely touch the changed page. A workload that repeatedly maps and unmaps memory, changes permissions, creates processes, or rapidly grows and shrinks heaps can therefore spend measurable time handling TLB invalidations.

This is why performance reports sometimes mention TLB shootdown IPIs, remote TLB flushes, or time in memory-management kernel code. The problem is not that translating one address is inherently expensive. It is that keeping many private translation caches correct requires cross-core coordination.

Operating systems and allocators reduce the cost by batching changes, invalidating ranges where the architecture supports it, avoiding unnecessary permission changes, and delaying reclamation until old translations can no longer be used. The fundamental trade-off remains: page-table changes are flexible and safe, but making that new view visible to every relevant core has a real synchronization cost.

← All articles