/microarchitecture-and-memory-systems:uarch-caches-coherence-consistency-and-virtual-memoryfrom microarchitecture-and-memory-systems
Explains cache organization (associativity, line size, replacement), MESI-family coherence protocols, memory consistency models, virtual memory with TLBs and page-table walks, and hardware prefetching. Useful when memory behavior drives performance.
Ships in microarchitecture-and-memory-systems. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Part 2 of 6 of the CPU, GPU, NPU and Memory Microarchitecture reference (plugin
microarchitecture-and-memory-systems), covering §6–§10. Sibling skills:uarch-pipelining-out-of-order-branch-prediction-and-simd(§0–§5),uarch-gpu-npu-dataflow-and-numeric-formats(§11–§14),uarch-dram-memory-controllers-power-and-security(§15–§19),uarch-isa-simulation-measurement-roofline-and-specialization(§20–§24),uarch-reference(§25–§30). Section numbers are shared across the set; a reference written as §N →skillpoints into that sibling skill.Currency: The principles are stable. Two areas moved. See §25 →
uarch-referencefor low-precision numeric formats, and next-generation memory standards.
⚠️ SCOPE, because this sits between two neighbours. ⚠️ A semiconductor reference covers device physics and fabrication — how a transistor works and how it's made. A computer-hardware reference covers system integration — components, builds, facilities. ⚠️ THIS file is the layer in between: how billions of transistors are ORGANIZED into something that executes instructions fast, and why memory systems are the hard part. ⚠️ It assumes the other two rather than repeating them.
⚠️ GOTCHA boxes mark where architectural intuition is wrong and where the abstraction leaks.
The three ideas that organize this document:
- ⚠️ THE PROCESSOR LIES TO YOU, DELIBERATELY (§2–§4 →
uarch-pipelining-out-of-order-branch-prediction-and-simd). Instructions do not execute in program order, memory operations do not become visible in program order, and the architecture works hard to maintain the illusion that they do. Every performance surprise and several security disasters live in the gap.- ⚠️ MOVING DATA COSTS FAR MORE THAN COMPUTING ON IT (§6, §13 →
uarch-gpu-npu-dataflow-and-numeric-formats, §23 →uarch-isa-simulation-measurement-roofline-and-specialization). Energy per arithmetic operation has fallen enormously; energy per byte moved has not. Modern architecture is organized around minimizing data movement, and that single fact explains caches, dataflow accelerators, quantization and HBM alike.- ⚠️ PARALLELISM IS EXTRACTED AT EVERY LEVEL, AND EACH HAS A DIFFERENT LIMIT (§3 →
uarch-pipelining-out-of-order-branch-prediction-and-simd, §11 →uarch-gpu-npu-dataflow-and-numeric-formats, §14 →uarch-gpu-npu-dataflow-and-numeric-formats). ILP is limited by dependencies and branches, DLP by divergence and memory, TLP by synchronization and coherence traffic. Knowing which one you're hitting is the entire diagnostic skill.
⚠️ See a computer-hardware reference for the latency ladder. Here, the mechanism.
⚠️ THE STRUCTURE address splits into TAG / INDEX / OFFSET
⚠️ Direct-mapped (fast, conflict-prone) · fully associative
(no conflicts, impractical) · ⚠️ N-WAY SET ASSOCIATIVE (the
real answer, typically 8–16 way at L2/L3)
⚠️ THE THREE Cs of misses ⚠️ COMPULSORY (first touch) ·
CAPACITY (working set too big) · ⚠️ CONFLICT (set collisions —
fixable by associativity or by changing the access stride)
⚠️ Plus COHERENCE misses in multiprocessors (§7)
⚠️ REPLACEMENT LRU is the reference; ⚠️ real caches use
approximations (pseudo-LRU, RRIP) because true LRU is
expensive at high associativity
⚠️ WRITE POLICY write-through vs ⚠️ WRITE-BACK (dominant) ·
write-allocate vs no-write-allocate · ⚠️ WRITE COMBINING buffers
⚠️ INCLUSIVE vs EXCLUSIVE vs NINE hierarchies — ⚠️ affects
effective capacity and coherence probe cost
⚠️ ⚠️ THE PATHOLOGIES WORTH KNOWING BY NAME
⚠️ FALSE SHARING two threads writing different variables in
the SAME LINE — coherence traffic destroys performance
with no logical sharing at all
⚠️ CACHE THRASHING from a stride that maps everything to one set
(⚠️ powers-of-two array dimensions are the classic cause —
which is why padding arrays can produce large speedups)
⚠️ 4K ALIASING between loads and stores
⚠️ How multiple caches maintain a consistent view of memory — and the source of multicore scaling limits.
⚠️ MESI and relatives each line is Modified / Exclusive / Shared /
Invalid. ⚠️ MOESI adds Owned; MESIF adds Forward
⚠️ THE INVARIANT: one writer OR many readers, never both
⚠️ PROTOCOL FAMILIES ⚠️ SNOOPING (every cache watches a shared
bus — simple, doesn't scale) vs ⚠️ DIRECTORY-BASED (a directory
tracks who holds each line — scales, adds latency and storage)
⚠️ ⚠️ THE COST a write to a SHARED line requires INVALIDATING every
other copy and waiting. ⚠️ A contended line ping-ponging between
cores can be orders of magnitude slower than uncontended access
⚠️ THEREFORE ⚠️ atomics and locks are expensive not because of the
instruction but because of the COHERENCE TRAFFIC. ⚠️ An
uncontended atomic is cheap; a contended one is not, and the
difference is enormous
⚠️ SCALABLE SYNCHRONIZATION ⚠️ MCS and ticket locks queue waiters
to avoid all-cores-spinning-on-one-line; ⚠️ RCU and per-CPU
data avoid sharing altogether — which is the real answer
⚠️ NUMA ⚠️ coherence across sockets is far more expensive again
⚠️ The most conceptually difficult topic here, and the one most often misunderstood. COHERENCE (§7) is about a single location; CONSISTENCY is about the ORDER of operations across different locations.
⚠️ SEQUENTIAL CONSISTENCY ⚠️ the intuitive model — as if all
operations from all threads interleaved in some global order
consistent with each program's order. ⚠️ NO REAL HARDWARE
PROVIDES THIS, because it forbids too many optimizations
⚠️ ⚠️ WHAT REAL HARDWARE DOES
⚠️ x86-TSO ⚠️ relatively strong: stores are buffered, so a
LOAD MAY BE REORDERED BEFORE AN EARLIER STORE to a
different address. ⚠️ That one relaxation is enough to break
naive Dekker-style algorithms
⚠️ ARM and RISC-V ⚠️ WEAKLY ORDERED — loads and stores can be
reordered much more freely. ⚠️ Code that is correct on x86
can be BROKEN on ARM with no source change, and this
surprises people porting between them
⚠️ FENCES / BARRIERS ⚠️ explicitly constrain reordering; acquire,
release, and full barriers
⚠️ LANGUAGE MEMORY MODELS ⚠️ C++11 and Java define their own
models so portable concurrent code is possible at all.
⚠️ memory_order_relaxed / acquire / release / seq_cst map onto
whatever the hardware needs
⚠️ ⚠️ THE COMPILER REORDERS TOO. ⚠️ A hardware fence without a
compiler barrier is not enough, and "volatile" is NOT a
synchronization primitive in C/C++
⚠️ The practical guidance: ⚠️ use the language's atomics and locks rather than hand-rolled fences; ⚠️ if you write lock-free code, TEST ON WEAK HARDWARE, because x86 hides bugs that ARM exposes.
⚠️ Multi-level page tables (⚠️ four or five levels on x86-64), ⚠️ so a TLB miss can
cost several memory accesses — a "page walk."
⚠️ The TLB caches translations, ⚠️ and TLB reach — entries × page size — is frequently
the hidden limit on large working sets.
⚠️ HUGE PAGES (2 MB, 1 GB) ⚠️ multiply TLB reach and are one of the highest-value and
least-used tunings for memory-intensive server workloads; ⚠️ the costs are internal
fragmentation and allocation difficulty.
⚠️ Cache indexing interaction: ⚠️ VIPT (virtually indexed, physically tagged) caches
let translation and lookup proceed in parallel, which constrains L1 size to page size ×
associativity — a genuine architectural reason L1 caches are small.
⚠️ ASIDs/PCIDs avoid flushing the whole TLB on context switch, ⚠️ which became much
more important after §19 → uarch-dram-memory-controllers-power-and-security's mitigations increased switching costs.
⚠️ Fetch data before it's requested, to hide latency. ⚠️ Hardware prefetchers detect sequential streams and constant strides, and increasingly more complex patterns; ⚠️ they cannot follow pointer chasing, which is why linked lists and trees perform so badly relative to arrays. ⚠️ Software prefetch instructions exist and ⚠️ are difficult to use well — too early and the line is evicted, too late and you gained nothing. ⚠️ The costs: ⚠️ useless prefetches consume bandwidth and can EVICT useful data, so an aggressive prefetcher can make a bandwidth-bound workload slower. ⚠️ The design implication: ⚠️ data structures with predictable access patterns are fast almost for free; ⚠️ this is a large part of why structure-of-arrays beats array-of- structures in performance-critical code.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub the-vibey-project/vibey --plugin microarchitecture-and-memory-systems6 skills in this plugin
/uarch-dram-memory-controllers-power-and-securityUse for the memory system and its side effects: DRAM internals with banks, rows, timings and refresh, memory controllers and scheduling, the emerging memory interfaces including CXL and high-bandwidth stacks, power and clocking with DVFS and thermal limits, and microarchitectural security — speculative execution attacks, side channels and Rowhammer-class problems./uarch-gpu-npu-dataflow-and-numeric-formatsUse for accelerators: GPU microarchitecture including warps, occupancy and divergence, GPU memory systems with coalescing and the bandwidth hierarchy, NPUs and dataflow architectures such as systolic arrays and why they suit tensor workloads, and numeric formats from FP32 down to FP8 and the block-scaled formats with their accuracy and throughput trade-offs./uarch-isa-simulation-measurement-roofline-and-specializationUse when evaluating or reasoning about performance rather than building hardware: ISA design and what the choice actually determines, simulation and modelling, measuring microarchitectural behaviour honestly with performance counters and the traps in them, roofline analysis and the fundamental limits that bound any optimisation, and specialization and when a fixed-function unit wins./uarch-pipelining-out-of-order-branch-prediction-and-simdUse for the core execution engine: the distinction between architecture and microarchitecture and why it governs what is portable, pipelining and hazards, out-of-order execution with register renaming, the reorder buffer and speculation, branch prediction and the cost of a misprediction, and execution units and SIMD. Includes the router for the whole microarchitecture reference./uarch-referenceUse when correcting a microarchitecture misconception, looking up a latency, bandwidth, cache-size, timing or throughput figure, finding the books, or needing a quick-reference picker — plus the current state of low-precision numeric formats and next-generation memory standards. Companion to the other microarchitecture skills.