What is Store buffer?

A small buffer in which a core holds writes temporarily. The core can move on without waiting for writes to complete, but other cores see the writes later.

Field: Multicore & Synchronization

Japanese name: ストアバッファ

Why cores buffer their stores

When a core executes a store, the target cache line may be missing or held by another core, and gaining write ownership through the coherence protocol can take many cycles. Rather than stall, the core places the address and data in a store buffer and continues executing. Entries drain into the L1 cache later, typically in program order on x86. In out-of-order processors the store buffer also holds speculative stores, which cannot be written to the cache until the store instruction commits and is known not to be squashed.

Store-to-load forwarding

Because recent stores may still be sitting in the buffer, every load checks it for a matching address. If it finds one, the load takes the data from the newest matching entry instead of from the cache, a mechanism called store-to-load forwarding. This keeps single-threaded behavior intact: a core always sees its own writes immediately, in program order. Forwarding works best when the load reads exactly the bytes a single earlier store wrote; partial overlaps between a load and buffered stores often force the load to wait until those stores drain.

Why other cores see writes late

Other cores cannot look into a core's store buffer, so a buffered write is invisible to them until it drains. Consider x and y both 0, with core 1 running x = 1 then r1 = y, and core 2 running y = 1 then r2 = x. Under sequential consistency at least one load must see 1. With store buffers, both stores can wait in their buffers while both loads read 0 from the caches, so r1 = r2 = 0 occurs on real x86 machines. A memory barrier between the store and the load, which waits for the buffer to drain, forbids this result.

Store buffers and memory consistency models

The x86 model, total store order (TSO), essentially describes a first-in, first-out store buffer: stores stay ordered with stores and loads with loads, and only a later load to a different address may appear to pass an earlier store. Weaker models such as those of Arm and RISC-V also allow stores to become visible out of order, among other reorderings, so they need fences or acquire/release instructions more often. Programmers normally rely on language-level atomics, which the compiler maps to the right fences.

Try it: questions about Store buffer

What does a memory consistency model define?

  1. AThe cache line size and the number of sets
  2. BThe kind of transistors used in main-memory DRAM
  3. CIn what order a core's reads and writes to multiple addresses may be observed by other cores
Show answer and explanation

Answer: C. In what order a core's reads and writes to multiple addresses may be observed by other cores

For performance, CPUs may reorder memory operations, for example by holding writes in a store buffer or performing reads early. They are designed so that results within one core are unchanged, but other cores may observe the operations in a different order. A memory consistency model defines which reorderings can occur and is the contract that lets programmers write correct synchronization.

What is a characteristic of the x86 memory consistency model (TSO, total store order)?

  1. AIt is the weakest model, allowing every combination of reordering
  2. BIt is exactly sequential consistency, allowing no reordering at all
  3. CIt is a relatively strong model that allows only a later read of a different address to appear before an earlier write
Show answer and explanation

Answer: C. It is a relatively strong model that allows only a later read of a different address to appear before an earlier write

Under TSO, writes stay ordered with writes, reads with reads, and a write after a read stays ordered; only a read of a different address may overtake an earlier write. This model directly reflects the presence of a store buffer. Many programs behave intuitively within these limits, so barriers are needed relatively rarely on x86.

FAQ

What is store-to-load forwarding?

It is when a load finds a matching earlier store still waiting in the store buffer and takes its data directly from there, so the core sees its own pending writes without waiting for them to reach the cache.

Why can both threads read 0 in the store buffering litmus test?

Each core's write sits in its own store buffer, invisible to the other core, while its following load reads the old value from cache; a memory fence between the store and load prevents this.

How does the store buffer relate to TSO?

Total store order is essentially the behavior of a FIFO store buffer: the only reordering it allows is a later load to a different address completing before an earlier store becomes visible.

Questions that mention Store buffer (1)

Store buffer appears in 3 practice questions across 1 topic, including Multicore & Synchronization.

  1. The two threads above run simultaneously on different cores (assume no compiler reordering). Which outcome cannot occur under sequential consistency but can occur on real CPUs such as x86?

Books on Multicore & Synchronization 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