Memory Hierarchy and Caches

Learn why a computer combines small, fast memories with large, slow ones, and how caches keep the data a program needs close to the processor. Compare SRAM, DRAM and flash, find blocks in direct-mapped and set-associative caches, classify misses and compare write policies. Calculate hit rates, average memory access time and the cost of memory stalls, see how virtual memory and the TLB translate addresses, and write loops and data structures that make good use of the cache.

IntermediateLesson 5 of 6 in Computer Organization and Architecture Course

What you will learn

  1. Describe how programs reuse data and code, compare the memory technologies that store it, and explain how fast small levels and slow large levels work together.
    • Recognize temporal and spatial locality in programs
      Identify the two kinds of locality in code and data accesses and explain why they let a small, fast memory serve most accesses.
    • Compare SRAM, DRAM and flash memory
      Describe how SRAM, DRAM and flash store bits and compare their speed, density, cost per bit, volatility and typical place in the hierarchy.
    • Describe how the levels of the hierarchy work together
      Name the levels from registers to storage, use the vocabulary of hits and misses, and explain how the hierarchy gives the illusion of a large, fast memory.
  2. Use the tag, index and offset fields of an address to locate a block, trace sequences of accesses, and compare cache organizations from direct-mapped to fully associative.
    • Split an address into tag, index and offset
      Work out the field sizes of a direct-mapped cache from its capacity and block size, divide an address into its fields and count the storage the cache needs.
    • Trace accesses through a direct-mapped cache
      Follow a sequence of addresses through a small direct-mapped cache, record each hit or miss and the cache contents, and spot blocks that evict each other.
    • Use set-associative and fully associative caches
      Locate blocks in n-way set-associative and fully associative caches, choose a victim with a replacement policy, and weigh lower miss rates against hardware cost and hit time.
  3. Describe what happens on a miss, classify misses by cause, relate cache size, block size and associativity to the miss rate, and compare the ways caches handle writes.
    • Handle cache misses and classify their causes
      Describe the steps of a cache miss, sort misses into compulsory, capacity and conflict misses, and explain how cache size, block size and associativity change each kind.
    • Compare write policies for caches
      Explain how write-through and write-back caches keep memory up to date, what write buffers and dirty bits do, and how write-allocate and no-write-allocate handle write misses.
  4. Compute hit rates, average memory access time and memory-stall cycles, include them in CPI and execution time, and analyze systems with several levels of cache.
    • Compute hit rate and average memory access time
      Calculate hit and miss rates and the average memory access time of a cache, including mixes of instruction and data accesses, and use it to compare designs.
    • Include memory stalls in CPI and execution time
      Add memory-stall cycles to the CPU performance equation, find how much a cache costs a program, and explain why faster processors suffer more from slow memory.
    • Analyze multilevel caches
      Explain why processors use several cache levels, distinguish local and global miss rates, and compute average memory access time and CPI for two- and three-level hierarchies.
  5. Describe how virtual addresses are translated to physical addresses with a page table, why a page fault is a miss handled by the operating system, and how the TLB makes translation fast.
    • Translate a virtual address with a page table
      Explain what virtual memory provides, split a virtual address into page number and offset, translate it through a page table entry, and describe what happens on a page fault.
    • Speed up translation with a TLB
      Explain how the translation lookaside buffer caches translations, follow an access through the TLB, page table and cache, and see how caches and translation overlap.
  6. Organize loops and data structures so that programs use the memory hierarchy well, and apply blocking and prefetching to reuse data while it is cached.
    • Arrange loops and data for locality
      Order loops to match how arrays are stored, avoid harmful strides, and choose data layouts that bring only useful data into the cache.
    • Block computations and use prefetching
      Restructure loops into blocks (tiles) that stay in the cache while they are reused, choose a block size, and explain how hardware and software prefetching hide memory latency.

Memory Hierarchy and Caches study guide

6 chapters

1

Explain why computers use a memory hierarchy

Programs repeatedly use a small part of their code and data. That reuse explains why a small cache can serve most accesses even when the whole program is much larger. Follow the difference between reuse in time and nearby addresses, compare the cells behind SRAM, DRAM, and flash, and connect those technologies to hits, misses, and transfers through the hierarchy. The same access pattern will later determine whether a cache design or a loop transformation helps.

1.1 How programs reuse nearby data

A cache works because the next memory access is often related to a recent one. During a short interval, most programs use only a small part of their address space. This pattern is locality. A cache keeps that active part close to the processor, where it can serve accesses quickly.

Reuse in time and space

Temporal locality means reusing an item soon after accessing it. A loop repeatedly fetches its body instructions. A running total is read and updated many times. Keeping those items available avoids fetching them again from a slower level.

Spatial locality means accessing items at nearby addresses. An array scan reads adjacent elements, and straight-line code fetches successive instructions. A cache exploits this by fetching an entire block, also called a cache line, on a miss. Nearby bytes arrive before the program asks for them.

These patterns can occur together. A loop's instructions are adjacent and run repeatedly, so the instruction stream has both spatial and temporal locality. An array element read exactly once has no temporal reuse, even though the surrounding array scan has spatial locality.

Count blocks in an array scan

Consider this C loop with 4-byte integers and 64-byte cache blocks:

for (int i = 0; i < 1000; i++) {
    sum += a[i];
}

A block holds 64/4=16 integers. The array occupies 1000×4=4000 bytes. If its first element is block aligned, the scan touches ⌈4000/64⌉=63 blocks: 62 full blocks and one partial block.

In a cold cache without prefetching or interference, the first access to each block misses. The remaining elements in that block hit. Thus the array causes 63 misses in 1000 accesses, or about 6.3%. Counting one miss per element would overlook all the useful neighboring data fetched with each miss.

The source variables sum and i are reused frequently. A compiler usually keeps them in registers, however, so their source-level reuse need not produce data-cache accesses. Analyze the memory accesses executed by the compiled program when estimating cache traffic.

The working set must fit and coexist

The working set is the collection of blocks used during a chosen time window. If they fit in the cache and the placement rules allow them to coexist, repeated accesses mostly hit after the initial loads. The time window matters: a whole program can be huge while one active loop uses only a few blocks.

Capacity alone is insufficient. Two busy blocks can map to one direct-mapped entry and evict each other while other entries remain empty. A working set can therefore fit by byte count yet fail to stay cached.

Scattered linked-list nodes and random probes of a large hash table often have poor spatial locality. A column walk through a row-major array also skips over many nearby elements. These patterns bring in bytes that may go unused before eviction. Hardware exploits the locality supplied by the access pattern; changing the program's layout or traversal can make more of each fetched block useful.

Key Takeaways

  • Temporal locality reuses an item; spatial locality accesses nearby addresses.
  • Fetching a whole block makes later accesses to nearby bytes hit.
  • A working set must fit in capacity and coexist under the cache placement rules.
  • Source variables kept in registers do not generate data-cache accesses.

1.2 Memory cells, transfers, and trade-offs

Memory technologies trade speed against density, cost, and persistence. The processor needs quick access to a small amount of data and affordable space for much more. SRAM, DRAM, and flash meet different parts of that need.

Compare the cells
TechnologyHow a bit is storedRefresh and powerMain role
SRAMA stable circuit, typically six transistorsNo refresh; loses data without powerOn-chip caches
DRAMCharge on a capacitor, accessed through a transistorPeriodic refresh; loses data without powerMain memory
NAND flashA nonvolatile cell whose state is electrically programmedRetains data without power; limited write enduranceStorage

An SRAM cell is fast but occupies substantial area, making SRAM relatively expensive per bit. DRAM cells are smaller, so DRAM provides more capacity at a lower cost per bit. Their charge leaks away. Refresh reads and restores rows within a fixed window; normal-temperature DDR4 uses a 64 ms window. “Static” in SRAM means no refresh, not persistence after power loss.

Why DRAM access time varies

DRAM is organized into banks, with rows and columns in each bank. Activating a row copies it into a row buffer. Reads and writes then select columns from that open row. To open a different row in the same bank, the bank must first be precharged. An access to an already open row avoids that row-switching work.

Consecutive columns can be transferred in a burst, which suits fetching a cache block. Distributing requests across banks and channels lets transfers overlap. DDR memory transfers on both clock edges. These features increase the rate of data delivery without eliminating the wait for the first data.

Separate latency from bandwidth

Latency is the delay until the first data arrives. Bandwidth is the amount transferred per unit time. A high-bandwidth interface can still have a long initial delay.

For example, a DDR5-4800 channel with an aggregate 64-bit data path carries 8 bytes per transfer. Its peak rate is 4800×106×8=38.4×109 bytes/s, or 38.4 GB/s. Sustained application bandwidth can be lower because commands, row changes, and other work consume time.

If a request waits 60 ns and then receives a 64-byte block at 16 GB/s, the transfer rate is 16 bytes/ns. Transfer takes 64/16=4 ns, giving about 64 ns altogether. Improving only bandwidth reduces the 4 ns part, not the initial 60 ns.

Flash keeps data but handles writes differently

NAND flash reads and programs pages of several KiB. Reusing a programmed page requires erasing its larger erase block, which contains many pages. Page reads typically take tens of microseconds, programming hundreds of microseconds to a few milliseconds, and erasing milliseconds.

Program/erase cycles wear cells out. Dense multi-bit flash often supports a few thousand cycles, while single-bit cells can support around 100,000. Controllers use wear leveling to spread writes across blocks.

For scale, SRAM access is roughly 1 ns, DRAM roughly 50–100 ns, NAND reads roughly 25–100 µs, and disk access roughly 5–10 ms. Actual devices vary. The hierarchy combines these technologies because a single one cannot provide their speed, capacity, and price advantages together.

Key Takeaways

  • SRAM and DRAM are volatile; flash retains data without power.
  • DRAM refresh restores leaking charge, while row buffers and bursts improve access efficiency.
  • Latency measures initial waiting time; bandwidth measures transfer rate.
  • Flash programs pages and erases larger blocks.
  • Wear leveling spreads program/erase wear across flash blocks.

1.3 Follow an access through the hierarchy

The memory hierarchy places small, fast storage near the processor and progressively larger storage farther away. Locality lets the small levels serve a large fraction of requests, while the lower levels supply capacity.

Levels and transfer units

A typical path is registers, L1, L2, L3, main memory, and storage. L1 commonly has separate instruction and data caches of around 32–64 KiB each per core. L2 is often hundreds of KiB to a few MiB per core, while L3 is often shared and holds several to tens of MiB. Main memory holds many GiB, and storage holds hundreds of GB or more. Designs differ in size and sharing.

On a processor near 3 GHz, representative load latencies are about 4–5 cycles for L1, 12–15 for L2, 30–50 for L3, and 200–300 for DRAM. An L1 may accept a new request each cycle even when one request needs several cycles to complete: throughput and latency describe different properties.

Data travels through caches in blocks, commonly 64 bytes. Virtual memory uses pages, commonly 4 KiB, when moving page contents between memory and storage. A cache line and a page serve similar grouping purposes at different scales; they are not the same transfer unit.

Hits, misses, and timing

A hit means a level contains the requested data. A miss means it must obtain the data from below. Both words refer to the level being checked: an L1 miss can still be an L2 hit.

The hit rate is hits divided by accesses, and the miss rate is one minus the hit rate. Hit time includes checking the level and deciding whether the request hits. The miss penalty is the additional time needed on a miss to obtain and deliver the block.

Suppose a simplified cache has a 1-cycle hit time, a 97% hit rate, and a 100-cycle extra miss penalty. Every access pays 1 cycle, while 3% pay another 100:

1+0.03×100=4 cycles.

A miss takes 101 cycles in this example. Using 100 as the complete miss time would charge the hit lookup inconsistently. Even a high hit rate leaves expensive misses visible in the average.

Who manages each level?

The compiler assigns suitable values to registers. Cache hardware moves blocks automatically as loads, stores, and instruction fetches run. Programs name addresses; they do not select cache entries. The operating system manages virtual-memory mappings with hardware support and handles pages that must be brought into main memory.

Splitting L1 instructions from data allows a pipeline to fetch an instruction and access data together without competing for one cache port. Lower caches are usually unified, storing both instruction and data blocks.

Some hierarchies are inclusive: a block present above also has a copy below. Others are exclusive or non-inclusive, so a copy in every lower cache is not guaranteed. Draw a hierarchy as a search and transfer path, not a promise that all levels contain identical subsets.

Making L1 larger can reduce misses but increase access delay and energy. Adding larger lower caches allows the design to keep L1 fast while rescuing many of its misses before DRAM. Evaluate that trade-off with access time, not capacity alone.

Key Takeaways

  • A hit or miss is relative to the level being checked.
  • Hit time is paid on every lookup; miss penalty is additional time on misses.
  • Caches transfer blocks, while virtual memory uses pages.
  • Separate L1 instruction and data caches support simultaneous pipeline accesses.
  • Cache inclusion is a design choice.
  • Larger capacity must be weighed against hit time and energy.
2

Find data in direct-mapped and set-associative caches

A memory address must tell a cache where to look and which bytes to return. Divide addresses into fields, track how requests replace blocks, and then give each block more placement choices through sets and ways. Small traces make the hardware rules visible: a different byte can hit in a loaded block, while a repeatedly used block can miss after a conflict. These lookup rules also determine how many tags and control bits the cache must store.

2.1 Find tag, index, and offset

A byte address identifies one byte in memory. A cache fetches a whole block, so lookup first identifies that block and then selects the requested bytes within it. In a direct-mapped cache, each block has exactly one possible entry.

Divide the address by purpose

For a block size of 2b bytes, the low b address bits form the offset. Dividing the byte address by the block size and discarding the remainder gives the block address. The remainder is the offset.

If the cache has E entries, the entry index is

index=block address mod E.

With a power-of-two entry count, the index is the group of address bits immediately above the offset. The remaining high bits form the tag, which tells the cache which of the many blocks sharing an index is present.

The field order from high bits to low bits is tag | index | offset. For an address width of A bits:

b=log⁡2(block bytes),s=log⁡2E,t=A−s−b.

Use the number of entries for the index calculation. Taking the logarithm of capacity in bytes would count the offset bits a second time.

Work a 16 KiB example

A 16 KiB direct-mapped cache with 64-byte blocks has 16384/64=256 entries. The offset takes 6 bits, the index 8 bits, and the tag 32−8−6=18 bits for 32-bit addresses.

For byte address 0x1234ABCD, the low 6 bits give offset 13, or 0x0D. Removing those bits gives block address 0x48D2AF. Its low 8 bits are 0xAF, so the index is 175. The remaining bits give tag 0x48D2.

The byte address can be reconstructed from these fields: concatenate the tag, the 8-bit index, and the 6-bit offset. Field widths matter because a hexadecimal digit represents 4 bits; the boundaries need not fall between hex digits.

A matching tag needs a valid entry

Each entry stores data, a tag, and a valid bit. The index selects the entry. A hit requires both a set valid bit and equality between its stored tag and the requested tag. At startup, an entry can contain arbitrary bits; the valid bit prevents those bits from being mistaken for a loaded block.

Once the block is present, accesses to other bytes in that block hit too. A hit does not require the identical byte address used to fetch the block.

Count metadata separately

Quoted cache capacity normally counts data only. Here each entry contains 512 data bits, 18 tag bits, and 1 valid bit, or 531 bits. Total storage is

256×531=135936 bits.

The data alone uses 131072 bits. Tags and validity add 4864 bits, about 3.7% of data storage. A write-back design also needs dirty bits; more complex designs need further control state.

The index uses low block-address bits so successive blocks spread across successive entries. A wider address leaves offset and index widths unchanged when capacity and block size stay fixed; the extra bits extend the tag.

Key Takeaways

  • Compute entry count from data capacity divided by block size.
  • The low address bits select the byte offset; the next bits select the entry.
  • A hit requires a valid entry and matching tag.
  • Advertised data capacity excludes tags and control bits.

2.2 Trace a direct-mapped cache

A cache trace records how each access changes the stored blocks. Keep a separate state for each entry, and update that state immediately after every miss. The next request uses the updated cache, not the cache as it looked at the beginning.

Set up the trace

Take a 64-byte direct-mapped cache with four 16-byte entries. It starts empty. For each byte address, divide by 16 to find the block, then compute block modulo 4 for the index. The tag is the block number divided by 4, with its fractional part discarded. There are 4 offset bits and 2 index bits.

On a read, inspect the selected entry. If it is valid and the tag matches, record a hit. Otherwise record a miss, replace that entry's block and tag, and set its valid bit. No replacement choice is available in a direct-mapped cache.

Follow all eight accesses
Byte addressBlockIndexTagResultBlock left in selected entry
0x00000Miss0
0x04000Hit0
0x40401Miss4
0x00000Miss0
0x14110Miss1
0x44401Miss4
0x08000Miss0
0x84802Miss8

The first access fills entry 0 with block 0. The next address, 0x04, is still inside that 16-byte block, so it hits despite naming a different byte. 0x40 belongs to block 4. It has the same index as block 0 but a different tag, so it replaces block 0.

The second 0x00 therefore misses. Earlier use alone cannot guarantee a hit: the block must still be present. The request to 0x14 loads block 1 into entry 1, leaving entry 0 unchanged.

Next, 0x44 loads block 4 into entry 0 again. 0x08 needs block 0 and evicts block 4. Finally, 0x84 loads block 8 into that same entry. At the end, entry 0 holds block 8 and entry 1 holds block 1; entries 2 and 3 remain invalid.

Interpret the behavior

There is one hit and seven misses, so the hit rate is 1/8=12.5%. Blocks 0, 4, and 8 compete for entry 0. The cache has four entries, yet this access pattern uses only two of them. The repeated evictions are caused by mapping conflicts, not a shortage of total storage for the four distinct blocks.

A block fill makes all of that block's bytes available. In a sequential scan, one miss can therefore serve many following elements. Here the conflicting accesses repeatedly remove that benefit before the next nearby byte is requested.

For reliable tracing, label byte addresses and block numbers explicitly. Applying modulo 4 directly to the byte address skips the division by block size and sends requests to the wrong entries. Record the replacement even when the new block has been loaded before: every miss installs the requested block and its tag in the selected entry.

Key Takeaways

  • Update cache contents after every miss.
  • Different byte addresses in one resident block hit.
  • A previously accessed block can miss after eviction.
  • Mapping conflicts can cause misses while other entries remain empty.
  • The example has one hit in eight accesses, a 12.5% hit rate.

2.3 Give blocks more placement choices

A set-associative cache gives a block several possible entries without searching the entire cache. The index selects a set, and the block can occupy any way in that set. This reduces conflicts between blocks that share an index.

Compute sets and fields

For data capacity C, block size B, and associativity n:

blocks=C/B,sets=C/(Bn).

The set index is block address modulo the number of sets. The offset still depends only on block size. The tag contains the remaining high bits.

A 32 KiB, 8-way cache with 64-byte blocks has 512 blocks and 64 sets. With 32-bit addresses, its offset, index, and tag widths are 6, 6, and 20 bits. Address 0x1234ABCD has offset 13, set 47, and tag 0x1234A.

At fixed capacity and block size, doubling associativity halves the number of sets. One index bit becomes a tag bit; no data capacity is added.

OrganizationAllowed placementIndex
Direct-mappedOne entrySelects that entry
n-wayAny of n ways in one setSelects that set
Fully associativeAny entry in the cacheNo index field

Lookup compares the tag with all valid tags in the chosen set in parallel. A matching way supplies the data through a selector. More ways require more comparisons and selection hardware, which can increase hit time and energy.

Replace a block only when the set is full

Use an invalid way first. When every way is occupied, LRU, or least recently used, evicts the block whose most recent access is oldest. Update recency on hits as well as fills. A 2-way set needs only one bit to track its LRU way; larger sets often use pseudo-LRU approximations.

FIFO evicts the block loaded earliest, even if it was recently accessed. Random replacement chooses a victim without maintaining full recency information. It is simple and can perform close to LRU in large caches.

Revisit the small trace with two ways

The 64-byte cache with 16-byte blocks now has two sets of two ways. Blocks 0, 4, and 8 map to set 0, while block 1 maps to set 1. For 0x00, 0x04, 0x40, 0x00, 0x14, 0x44, 0x08, 0x84, the results are miss, hit, miss, hit, miss, hit, hit, miss.

Blocks 0 and 4 can coexist, so their repeated accesses hit. Just before the last access, block 0 was used more recently than block 4. Loading block 8 evicts block 4 under LRU. Four of eight accesses hit, compared with one in the direct-mapped version.

Associativity cannot remove compulsory misses or make a working set larger than capacity fit. It also cannot prevent conflicts when more than n busy blocks compete for one n-way set. A repeating cycle of n+1 such blocks can make LRU miss every time. Padding arrays can change their set mappings; choosing more ways is only one possible response to a conflict problem.

Key Takeaways

  • Set count equals data capacity divided by block size and ways.
  • More associativity changes placement flexibility, not data capacity.
  • LRU tracks accesses; FIFO tracks insertion order.
  • Fill invalid ways before replacing valid blocks.
  • Fully associative caches have no index field but still have cold and capacity misses.
  • More ways can reduce conflict misses at a hardware and timing cost.
3

Explain cache misses and write policies

A miss can come from first use, limited capacity, or blocks competing for the same locations. Identifying its cause helps explain which design changes can reduce it. Stores add a second problem: the hierarchy must decide when changed data reaches the next level and what happens if the block is absent. Follow read-miss service, write policies, buffers, and dirty evictions to connect cache state with the traffic and delays it produces.

3.1 Explain what caused a miss

A cache miss is an event with both a mechanism and a cause. The mechanism describes how the request is served. The cause explains why the needed block was absent and which design change might help.

Handle a read miss

In a simple in-order pipeline, the cache detects an invalid entry or a tag mismatch, and the processor stalls. The cache requests the block from the next level. If the chosen victim is dirty, its changed data must be preserved by writing it back. The arriving block is installed with its tag and valid bit, and the waiting access completes. An instruction-cache miss similarly waits for the instruction's block and then fetches the instruction again.

Critical word first requests the needed word first in the returning block. Early restart lets execution resume as soon as that word arrives. A nonblocking cache can serve other hits and track outstanding misses while an out-of-order processor does independent work. These mechanisms reduce waiting; they do not make the original data dependency disappear.

Use the three Cs
Miss classWhy the block is absentDiagnostic test
CompulsoryThis is its first accessIt would miss even with unlimited capacity
CapacityThe active blocks exceed available spaceA same-size fully associative LRU cache also misses
ConflictPlacement restrictions evicted itA same-size fully associative LRU cache hits

Apply the first-access test first. A block's first access is compulsory even if its destination entry is already occupied. For later misses, compare the actual cache with a fully associative LRU cache of equal data capacity and block size, both receiving the same access history.

In the earlier four-entry trace, blocks 0, 4, 1, and 8 each cause one compulsory miss. The direct-mapped cache also misses on the repeated accesses to blocks 0 and 4. A four-entry fully associative cache can retain all four distinct blocks, so those three repeat misses are conflicts. There are no capacity misses.

Choose a change that addresses the cause

Increasing capacity can retain a larger working set. Increasing associativity can let conflicting blocks coexist. Increasing block size can exploit spatial locality by bringing in more useful neighbors with each fill.

Block size has competing effects. At fixed data capacity, larger blocks mean fewer resident blocks. Unused bytes consume cache space, unrelated useful blocks can be displaced, and each transfer can take longer. Miss rate often falls initially as block size grows, then rises when these costs outweigh useful spatial locality.

A larger cache can also have a longer lookup, and additional ways require more comparison hardware. Judge changes through average access time, including hit time and miss penalty, instead of assuming that a lower miss rate guarantees a faster design.

In multicore systems, invalidation after another core writes can cause coherence misses. Prefetching can bring a first-use block in before its demand access, hiding a demand miss that additional capacity alone cannot avoid.

Key Takeaways

  • Classify first accesses as compulsory before checking other causes.
  • Use a same-size fully associative LRU cache to distinguish capacity from conflict misses.
  • Larger blocks trade useful spatial locality against fewer resident blocks and longer transfers.
  • Early restart, critical word first, and nonblocking caches reduce waiting in different ways.
  • Compare full access time when judging a miss-rate improvement.

3.2 Decide when stores reach the next level

A store changes a value, so the hierarchy needs a rule for passing that change downward. Two separate choices are involved: what to do when a store hits, and what to do when it misses.

Write-through and write-back
PolicyAction on a write hitEffect on the next level
Write-throughUpdate the cache and send the store downwardEvery store generates a lower-level update
Write-backUpdate the cache and mark its block dirtyA dirty block is sent down when evicted

A dirty bit records that a write-back block contains changes not yet written to the next level. A clean victim needs no write-back. A dirty victim must have its changed data preserved before its entry can be reused. The processor's loads obtain the new value from the cache even while the lower copy is older.

For 100 stores to one cached 4-byte variable, unmerged write-through sends 100 writes, or 400 bytes of data payload. Write-back can combine those changes into one 64-byte block write on eviction. This comparison counts update payload, excluding the initial fill and protocol overhead.

The benefit depends on reuse. Repeated writes to one block give write-back a chance to combine updates; writes scattered across many blocks may lead to many dirty evictions. Lower caches commonly use write-back to limit traffic toward DRAM. L1 data caches can use either policy.

A write buffer hides waiting, not traffic

A write buffer queues pending lower-level writes. Under write-through, the processor can proceed once a store has entered the buffer instead of waiting for the lower memory to finish. The lower level catches up as buffered stores drain; it can temporarily lag behind the cached value.

The buffer has finite capacity. If stores arrive faster than the lower level accepts them for long enough, it fills and the processor stalls. A buffer changes when the processor waits, not the sustainable bandwidth of the destination.

Without buffering or overlap, if 10% of instructions store and every store adds 100 wait cycles, a base CPI of 1 becomes 1+0.1×100=11. Buffering can hide much of this delay when the destination keeps up on average.

Treat a write miss separately

Write-allocate fetches the missing block into the cache and then applies the store. It pairs naturally with write-back because later accesses and writes can reuse that block. No-write-allocate, also called write-around, sends the store downward without filling this cache. It pairs naturally with write-through and can avoid displacing useful blocks during a one-time output stream.

These are independent policy choices. Knowing that a cache is write-through does not by itself tell you whether a write miss allocates a line; a trace must specify both policies.

A write-back miss that selects a dirty victim involves outgoing data as well as the incoming fill, raising the penalty unless buffers or overlap hide part of the work. Other cores and I/O devices also need a consistent view when lower memory is stale. Coherence and system mechanisms coordinate that visibility; a dirty bit alone only records pending changes.

Key Takeaways

  • Write-through sends each store downward; write-back delays changes until dirty-block write-back.
  • A dirty bit distinguishes modified blocks from clean ones.
  • Write buffers hide latency until they fill; they do not create bandwidth.
  • Write-allocate and no-write-allocate specify write-miss behavior independently of the hit policy.
  • A dirty eviction adds outgoing traffic to the miss path.
  • Buffered write-through can leave the lower level temporarily behind.
4

Calculate cache performance

A cache design is useful only if its hits and misses lead to better execution time. Combine lookup time, miss frequency, and extra miss delay, then connect access costs to stalls per instruction. Separate instruction and data traffic, keep cycles consistent with clock time, and nest lower-cache costs using the fraction of requests that reaches each level. These calculations show why a lower miss rate or faster clock can give a smaller benefit than expected.

4.1 Calculate average memory access time

A high hit rate is useful, but it is not a complete performance measure. A small number of expensive misses can dominate the average, and a design that avoids more misses can still lose if its lookup becomes too slow.

Start with rates and timing definitions
hit rate=hitsaccesses,miss rate=missesaccesses.

The two fractions sum to one. Convert percentages to fractions before multiplying: 5% is 0.05.

Average memory access time, or AMAT, is

AMAT=hit time+miss rate×miss penalty.

Every request checks the cache, including requests that miss. The penalty is the extra delay after that lookup. Equivalently, weight hit time by the hit fraction and total miss time by the miss fraction; expanding gives the same formula.

With a 1-cycle hit time, 5% misses, and a 100-cycle additional penalty, AMAT is 1+0.05×100=6 cycles. At 2 GHz, each cycle lasts 0.5 ns, so this is 3 ns. Do all arithmetic in cycles or all in time, then convert the final result if needed.

Compare complete designs

Cache A has a 1.0 ns lookup and 5% misses. Cache B has a 1.2 ns lookup and 3.5% misses. With a 50 ns penalty:

A=1+0.05×50=3.5 ns, B=1.2+0.035×50=2.95 ns.

B wins because avoiding expensive misses more than repays its slower lookup. If the penalty falls to 10 ns, A takes 1.5 ns and B takes 1.55 ns. Now A wins. A miss-rate improvement has value in proportion to the penalty it avoids.

Weight instruction and data accesses correctly

Suppose each instruction produces one instruction fetch and 0.3 data accesses on average. The instruction miss rate is 2%, and the data miss rate is 4%. In 100 instructions, there are 100 fetches and 30 data accesses. Expected misses are 100×0.02+30×0.04=3.2 out of 130 accesses.

The combined miss fraction is therefore 0.02+0.3×0.041.3. With equal 1-cycle hit times and 100-cycle penalties, AMAT is about 3.46 cycles per memory access. Averaging 2% and 4% directly would wrongly give the two access types equal weight.

Estimate a transfer penalty

A block request can include initial latency followed by transfer time. With 60 ns latency, a 64-byte line, and 16 GB/s bandwidth, transfer takes 4 ns, making the additional penalty about 64 ns. At 3 GHz, there are 3 cycles/ns, so that is 192 cycles.

Check what a problem's timing includes. If it gives a complete miss access time, subtract the hit lookup before treating that number as an additional miss penalty. Charging the lookup twice overstates AMAT.

Key Takeaways

  • AMAT adds the hit lookup to the expected extra miss cost.
  • Use decimal miss fractions and one consistent timing unit.
  • Weight instruction and data rates by their access counts.
  • A lower miss rate can lose to a sufficiently slower hit time.

4.2 Turn misses into execution time

AMAT measures time per memory access. CPI measures cycles per executed instruction. To connect them, count how many instruction and data requests each instruction produces and how many stall cycles those requests add.

Add the stall terms

For a simple in-order processor whose cache hits are included in the base CPI, a nonoverlapped miss adds its extra penalty. With instruction miss rate mI, data accesses per instruction fD, data miss rate mD, and penalty P in cycles:

stall CPI=mIP+fDmDP, CPU time=instruction count×(base CPI+stall CPI)×cycle time.

Every instruction has one instruction-fetch request in this model. Only loads and stores make data requests, so multiply their miss rate by their frequency. If their penalties differ, use a separate penalty in each term.

Work from requests to stalls

Let base CPI be 1.0, instruction miss rate 2%, load/store frequency 30%, data miss rate 4%, and miss penalty 100 cycles. Instruction stalls are 0.02×100=2.0 cycles per instruction. Data stalls are 0.3×0.04×100=1.2. Total CPI is 4.2.

With a perfect cache, CPI would return to 1.0. At the same clock and instruction count, that would be a 4.2-fold speedup. The data miss rate is twice the instruction miss rate, yet instruction misses cost more total time because every instruction is fetched and only 30% access data.

Do not insert AMAT directly as CPI. AMAT is per access, and it includes the hit service time. The CPI calculation here adds only stalls beyond the base execution already counted.

A faster clock makes each memory wait cost more cycles

DRAM latency in nanoseconds does not shrink when the processor clock increases. Doubling the clock converts the same 100-cycle memory wait into 200 cycles at the new clock. The example's CPI becomes

1+0.02×200+0.3×0.04×200=7.4.

Each new cycle is half as long, so relative execution time changes from 4.2 old cycles per instruction to the equivalent of 3.7 old cycles. Speedup is 4.2/3.7≈1.14, far below two.

Improvements shift the bottleneck

If the base CPI drops from 1.0 to 0.5 while memory stalls remain 3.2, total CPI becomes 3.7. Stalls now consume 3.2/3.7≈86% of cycles. Improving the core makes the unchanged memory delay a larger share of runtime, an example of Amdahl's law.

The simple model counts all miss delays as stalls. Out-of-order execution and nonblocking caches can overlap misses with useful work or other misses. Hardware counters and runtime measurements are needed to assess that overlap on a real machine. When comparing designs with this model, keep the same instruction stream and state which delays are already included in the base CPI.

Key Takeaways

  • Count instruction misses for every instruction and data misses only for data accesses.
  • Add extra miss stalls to a base CPI that already includes hits.
  • Convert memory time to cycles again when the clock rate changes.
  • Compare runtime through CPI times cycle time, not CPI alone.
  • Overlap can make actual stalls smaller than the simple sum of miss penalties.

4.3 Nest the costs of several cache levels

A lower cache reduces the penalty paid when L1 misses. It has its own lookup time and miss rate, so the hierarchy's expected cost must follow the fraction of requests that reaches each level.

Keep the denominator with the rate

A level's local miss rate is its misses divided by requests to that level. Its global miss rate is its misses divided by all processor memory requests.

If L1 misses 4% of the time and L2 misses on 25% of those requests, only 0.04×0.25=0.01, or 1% of original requests, reach memory. A 25% local L2 miss rate says nothing by itself about the fraction of all requests reaching memory: L1 filtered the stream first.

For two sequentially checked levels:

AMAT=H1+m1(H2+m2P).

Here H1 and H2 are lookup times, m1 and m2 are local miss fractions, and P is the additional memory penalty. Only L1 misses pay the L2 lookup. Only misses in both levels pay the memory penalty.

Evaluate from the inside outward

Use L1 hit time 1 cycle, L1 miss rate 4%, L2 hit time 12 cycles, local L2 miss rate 25%, and memory penalty 200 cycles. A request that reaches L2 takes an average of 12+0.25×200=62 extra cycles. Thus

AMAT=1+0.04×62=3.48 cycles.

Without L2, AMAT would be 1+0.04×200=9 cycles. The L2 lookup adds work to each L1 miss but prevents most of those requests from paying the much larger memory delay.

Do not substitute the 1% global L2 miss rate for m2 inside the parentheses. That would multiply by the L1 miss fraction twice. An equivalent expanded form uses the global rate directly:

AMAT=H1+m1H2+(m1m2)P.
Add L3 using the same logic

With L3 hit time 40 cycles and local miss rate 40%, the L3 service term is 40+0.4×200=120 cycles. The L2 term becomes 12+0.25×120=42 cycles. Overall AMAT is 1+0.04×42=2.68 cycles.

The full expression is H1+m1(H2+m2(H3+m3P)). L3 is charged only to requests that miss both upper levels. A level with a very slow lookup or very few hits can add more delay than it saves.

Use rates per instruction for CPI

Suppose base CPI is 1, L1 produces 0.032 misses per instruction, and memory adds 100 cycles. With no L2, CPI is 1+0.032×100=4.2. Add a 10-cycle L2 whose local miss rate is 25%:

CPI=1+0.032×10+0.032×0.25×100=2.12.

At the same clock, speedup is 4.2/2.12≈1.98. The 0.032 figure is already misses per instruction, so another access-frequency multiplier would count that frequency twice.

Key Takeaways

  • Local and global miss rates have different denominators.
  • Multiply local miss fractions to find the fraction reaching a lower level.
  • Evaluate nested service times from the lowest level upward.
  • Charge lower-level lookup time only to requests that reach that level.
  • Use misses per instruction directly when calculating stall CPI.
  • Adding a cache helps only when avoided delay exceeds its added lookup work.
5

Explain how virtual memory and TLBs fit into the hierarchy

Programs issue virtual addresses, while caches ultimately identify physical data. Page tables supply the mapping and access rights, and a TLB keeps recently used translations close to the processor. Work through an address translation, distinguish a missing translation from a page fault, and see how cache indexing can overlap translation. The same hierarchy ideas apply here, but translation entries, data blocks, and pages have different jobs.

5.1 Translate pages and check permissions

Virtual memory separates the addresses a program uses from the locations holding its data in main memory. Each process gets its own virtual address space. Hardware translates addresses using operating-system mappings and checks whether each requested access is permitted.

Replace the page number, preserve the offset

A page is a fixed-size region of virtual addresses. A page frame is a page-sized slot in physical memory. With 4 KiB pages, each page contains 4096 bytes, so the page offset needs 12 bits. The remaining high virtual-address bits form the virtual page number, or VPN.

A page table entry, or PTE, maps a VPN to a physical page number, or PPN. Translation replaces the page number but preserves the offset: the same byte position is selected inside the physical frame.

For virtual address 0x00403A7C, the low 12 bits give offset 0xA7C, and the VPN is 0x00403. If that VPN maps to PPN 0x02F1C, the physical address is 0x02F1CA7C. Appending a 12-bit offset is equivalent to multiplying the PPN by 4096 and adding the offset; adding the unshifted PPN would give the wrong address.

A mapping includes permissions

A PTE records validity, a physical page number, and permissions such as read, write, execute, and user access. Accessed and dirty bits record use and modification. A privileged processor register identifies the page table; RISC-V uses satp. User programs cannot freely rewrite these mappings.

Separate page tables let the same virtual address refer to different physical data in different processes. They also allow selected sharing: two processes can map virtual pages to the same physical frame, for example to share read-only library code. Isolation and sharing are both consequences of controlled mappings.

A page fault needs operating-system attention

A page fault is an exception raised when translation or its permission checks cannot complete normally. A store to a read-only mapping can fault even if the page is already in memory.

When a needed page is absent from main memory, the operating system obtains a physical frame, reads the page from storage, updates the mapping, and restarts the instruction. A modified victim page may first need a write-back. Some faults are resolved without storage, such as setting up a mapping to an existing page or handling copy-on-write. An access the system cannot permit can instead end in a process error.

Storage-backed faults are expensive. At 3 GHz, a 50 µs delay costs 150000 cycles, and 1 ms costs 3000000. Large pages spread transfer costs across many bytes. A virtual page can occupy any suitable frame, and dirty pages use write-back because forwarding every store to storage would be too slow.

Page tables also consume memory

A flat table for 32-bit virtual addresses and 4 KiB pages needs 232−12=220 entries. At 4 bytes per entry, that is 4 MiB per process. Real designs use multi-level tables to avoid allocating one huge flat table for sparse address spaces; RISC-V Sv39 uses three levels.

Virtual memory includes address translation, protection, and sharing even when every used page fits in DRAM. Storage-backed paging is one use of that machinery, not its whole purpose.

Key Takeaways

  • Translation changes the page number and preserves the page offset.
  • PTE permissions control reads, writes, execution, and user access.
  • A page fault can mean a missing page or a permission problem.
  • Some page faults are resolved without reading storage.
  • Page tables support process isolation and deliberate sharing.
  • A flat table has one entry per virtual page, so its storage cost can be large.

5.2 Cache translations with a TLB

Address translation can require several page-table reads before a data access proceeds. Page-table entries can hit in ordinary caches, but those reads still add work. The translation lookaside buffer, or TLB, caches recently used translations so most accesses can avoid a page-table walk.

Follow an allowed access

The virtual page number is looked up in the TLB. A matching entry supplies the physical page number and permission information. After permission checks, the physical address identifies the data in the cache hierarchy.

On a TLB miss, a page-table walk obtains the translation. If the mapping is valid and permits the request, the translation is installed in the TLB and the access continues. RISC-V and x86-64 normally use hardware walkers; some architectures use software handlers. If the mapping cannot serve the request, the processor raises a page fault for the operating system.

A TLB miss can therefore accompany either a data-cache hit or a data-cache miss. It says that the translation was absent from the TLB, not that the page was absent from DRAM. Conversely, a TLB hit can accompany a cache miss, or a permission fault for a prohibited access. Translation and data residency answer different questions.

Count the memory covered by translations

TLB reach is entries multiplied by page size. A 64-entry TLB with 4 KiB pages covers 256 KiB at once. With 2 MiB pages, 64 entries cover 128 MiB. Accessing many different pages can exhaust translation capacity even when only a few bytes of each page are used.

First-level TLBs often contain tens of entries; lower TLB levels can contain hundreds or thousands. Their entries include page-number tags, physical mappings, permissions, and often address-space identifiers. Locality within pages and reuse across nearby accesses keep translation hit rates high.

For example, if 1% of accesses require a 30-cycle walk and TLB-hit time is otherwise hidden, walks add 0.01×30=0.3 cycles per access on average. This example assumes the walks complete normally and excludes page-fault service.

Overlap indexing with translation

A physically indexed, physically tagged cache waits for a physical address before selecting its set. A virtually indexed, physically tagged cache, or VIPT cache, starts reading a set while the TLB translates, then compares physical tags.

The simple VIPT design takes all index and block-offset bits from the page offset, because translation preserves those bits. This requires

cache capacityways≤page size.

With 4 KiB pages, a 32 KiB 8-way cache has 4 KiB per way and fits. A 48 KiB 12-way cache also fits. A 64 KiB 8-way cache has 8 KiB per way and needs a page-number bit for indexing, so it requires more ways or additional handling.

Keep cached mappings current

Translations belong to address spaces. A context switch can flush old entries or distinguish them with address-space identifiers, or ASIDs. Changes to mappings require the corresponding translation-cache maintenance; RISC-V provides sfence.vma. When a page is evicted from memory, its old translation must not remain usable in the TLB. The TLB holds mappings and access rights, while ordinary caches hold the program's data and instructions.

Key Takeaways

  • A TLB stores translations and permissions, not program data.
  • A successful page-table walk resolves a TLB miss without a page fault.
  • TLB reach equals entry count times page size.
  • Simple VIPT indexing fits index and block-offset bits inside the page offset.
  • ASIDs and translation invalidation prevent use of mappings from the wrong address space or an old mapping.
6

Write cache-aware programs

Loops and data layouts decide which bytes a processor asks for next. Follow those addresses to improve spatial locality, preserve useful data through blocking, and understand when prefetching can hide a wait. Compare row and column traversals, layouts for records, and tile footprints before measuring a change. Capacity, set conflicts, translation coverage, and memory bandwidth all help explain why a transformation works on one workload and helps less on another.

6.1 Choose loops and layouts that use each line

Cache-aware code makes fetched bytes useful before their block is evicted. Start with the addresses generated by the inner loop. Then ask which data is reused, how far apart accesses are, and whether those blocks can coexist in the cache.

Traverse arrays in storage order

C and C++ store rectangular arrays in row-major order. Adjacent columns of one row are adjacent in memory. Fortran, MATLAB, and Julia use column-major order; NumPy arrays default to row-major order. The efficient inner traversal follows the actual layout.

A C array double a[1024][1024] occupies 8 MiB. Each row takes 8192 bytes. With 64-byte cache lines, each line holds eight doubles. A row walk can use all eight before moving on, giving roughly one cold miss per eight accesses in a simple demand-fetch model.

A column walk steps 8192 bytes between consecutive accesses. It touches 1024 distinct lines before revisiting nearby data in the next column. Those lines occupy 64 KiB, exceeding a 32 KiB L1. They also conflict: in a 64-set cache, a stride of 128 lines preserves the set index. An 8-way set cannot hold 1024 competing lines.

Padding a row to 1032 doubles makes its stride 8256 bytes, or 129 lines. Successive rows then advance by one set modulo 64, spreading the requests. Padding addresses mapping conflicts; the amount of data still matters.

Interchange loops when the result is preserved

Loop interchange changes which loop runs inside another. For row-major matrix multiplication, the i, j, k order streams a row of A but a column of B. In a large streaming model with little reuse between passes, this costs about 1/8+1=1.125 misses per inner iteration.

With i, k, j, the inner loop streams rows of B and C, while one A element is reused. Counting a fresh stream for both rows gives about 1/8+1/8=0.25 misses per iteration, 4.5 times fewer. If the repeatedly updated row of C stays resident, the count approaches 0.125. Cache capacity and conflicts decide which reuse survives.

Interchange must preserve required computation behavior. Dependencies, overlapping pointers, and floating-point evaluation order can constrain transformations; compilers need proof that a change is allowed.

Fetch the fields you use

An array of structures groups all fields of one object. A structure of arrays groups one field across objects. If a particle record holds eight doubles in one 64-byte line, summing only x across one million aligned records fetches about 64 MB. A separate contiguous x array fetches about 8 MB, using every double brought in. Code using every particle field together may favor the original structure layout.

Linked nodes can be scattered, and each next address may depend on a pointer just loaded. Contiguous arrays or node pools can improve locality. Compact hot fields also let more active data fit within each level.

Measure runtime and relevant hardware counters before and after a change. Cache misses can explain a slow loop, but computation, bandwidth, or branches may be the limiting factor. Keep the input and results comparable so a speed difference reflects the change being evaluated.

Key Takeaways

  • Match the inner loop to the array storage order.
  • Large power-of-two strides can concentrate requests in one set.
  • Padding changes mapping; compact layouts reduce the bytes fetched.
  • Loop interchange must preserve required computation behavior.
  • Choose arrays of structures or structures of arrays according to which fields are used.
  • Measure the bottleneck and verify results when changing code.

6.2 Reuse tiles and fetch ahead

Loop interchange improves access order. Blocking, also called tiling, goes further by keeping a small region of data active until its useful reuse is complete. Prefetching moves a future transfer earlier so its delay overlaps useful work.

Keep a group of tiles resident

In blocked multiplication of square matrices, one tile of A and one tile of B contribute to one tile of C. A tile of side b contains b2 elements. Working repeatedly on these small tiles reuses data before moving to the next region.

For 8-byte doubles, three tiles require 3b2×8=24b2 bytes. In a 32 KiB cache, the capacity limit is

24b2≤32768,b≤32768/24≈36.9.

Choosing a side of 32 uses 24576 bytes, or 24 KiB, leaving some space for other data. Choosing 36 merely because the arithmetic permits it leaves much less room and can expose conflicts. Capacity is a starting estimate; actual tile sizes are tuned by measurement.

A blocked traversal steps the outer loop by the tile size. Its inner bounds stop at the smaller of the tile end and matrix size. For example, if a dimension is 70 and tiles have side 32, the final tile has only six elements along that dimension. A full-size final tile would access beyond the array.

Estimate what reuse saves

In a simplified large-matrix model with 64-byte lines, the naive i, j, k order has about 1.125N3 misses when streamed rows are no longer cached on the next pass. A blocked version can reduce this to about N3/(4b), assuming the three working tiles stay cached and ignoring conflicts.

For N=1024 and b=32, these estimates are about 1.2 billion and 8.4 million misses, a factor of 144. Both versions still perform about 2N3 floating-point operations. The saving is in repeated data movement, not in the multiplication's arithmetic count. The model describes ideal reuse; measured speedup also depends on bandwidth, execution, and other overhead.

Prefetch early enough to hide latency

Hardware prefetchers recognize streams such as sequential or constant-stride accesses. They request lines before demand accesses need them. Software can also request advance fetches, for example with GCC or Clang's __builtin_prefetch.

The timing matters. A request made too late leaves the demand waiting. A request made too early can bring a line in only to have it evicted before use. An inaccurate request consumes bandwidth and cache space without helping the program. Pointer chasing is harder to prefetch because the next address often becomes known only after the current node arrives.

Timely prefetching can turn later demand misses into hits, but the lines still travel through the hierarchy. It hides latency rather than reducing the required payload of a streaming pass. Blocking helps when values are reused; a one-time sweep has no repeated data to retain and may already be limited by memory bandwidth.

Key Takeaways

  • Blocking keeps reused tiles active while their data is useful.
  • Estimate tile storage for all simultaneously needed arrays.
  • Handle partial edge tiles with bounded loop limits.
  • Blocking reduces data movement while preserving the arithmetic workload.
  • Prefetching needs useful addresses and enough lead time; inaccurate requests waste bandwidth.

Memory Hierarchy and Caches examples

6 Walkthroughs

1

From an array scan to a memory hierarchy

13 steps
Connect program locality with memory technologies and the costs of hits and misses.
  1. 1
    IntroductionWhy keep a small memory close?

    A processor can issue work much faster than a large memory can answer every request. A cache helps when a program returns to recent data or uses nearby addresses; that reuse is called locality. Follow one array scan to see how much a single line fill can serve, then connect that reuse to the technologies and levels that supply the data, the memory hierarchy.

  2. 2
    ExplanationSeparate two kinds of locality

    Temporal locality reuses an item soon: a loop body executes repeatedly, and a running total is updated each iteration. Spatial locality uses nearby addresses: a sequential array scan reads adjacent elements.

    A loop can have both in its instruction stream even when every array element is read only once. Identify what is being accessed before assigning a kind of locality.

  3. 3
    ExampleHow much does one line supply?

    A block-aligned array holds 1000 integers of 4 bytes each. Cache lines contain 64 bytes. Each fill supplies 64/4=16 consecutive integers. After the first integer misses, the next 15 can hit. The last line need not be full: the 4000-byte array needs ⌈4000/64⌉=63 lines.

  4. 4
    ChallengePredict a smaller scan

    An aligned array holds 320 four-byte integers. In a cold demand-fetch cache with 64-byte lines, no interference, and room for the array, how many array reads miss? What locality supplies the remaining hits?

    ---reveal---

    There are 16 integers per line and 320/16=20 lines, so 20 reads miss. The other 300 hit through spatial locality. Each element is used once; these hits do not require temporal reuse of the elements.

  5. 5
    Key InsightA working set needs usable places

    The working set is the blocks used during a time window. A small active set can stay close even when the whole program is large.

    Both capacity and placement matter. If two active blocks are allowed only one shared entry, they can evict each other while other entries remain empty. Register-held loop variables also need no data-cache space, even if the source reads them repeatedly.

  6. 6
    ExplanationCompare powered memory cells

    SRAM holds a bit in a stable powered circuit, typically using six transistors. It needs no refresh and is fast, but costs substantial area per bit. DRAM holds charge on a capacitor; leakage requires refresh. Its denser cells make it suitable for large main memory.

    Both are volatile. “Static” describes how SRAM holds its state while powered, not whether it survives a power loss.

  7. 7
    ExampleWait first, then transfer

    DRAM activates a row into a bank's row buffer and serves selected columns from it. Bursts and overlapping banks increase delivery rate. They do not remove initial access delay.

    With 60 ns initial latency, a 64-byte line transferred at 16 bytes/ns needs another 4 ns. Total service is about 64 ns. Most of that wait precedes the transfer, even though the interface moves bytes quickly.

  8. 8
    ExplanationChoose storage that keeps its contents

    NAND flash keeps data without power. It reads and programs pages, while erasing larger blocks before programmed space can be reused. Those operations take much longer than SRAM or DRAM access.

    Program/erase wear limits a block's life. Wear leveling spreads updates across blocks so frequently changed logical data does not wear out one physical location early.

  9. 9
    ChallengeDistinguish persistence and refresh

    A device must keep records after power is removed. Would replacing DRAM with SRAM meet that requirement? Explain.

    ---reveal---

    No. SRAM avoids refresh but still loses its data without power, just as DRAM does. Nonvolatile storage such as flash meets the persistence requirement. Its slower page operations and erase requirements explain why it serves a different role from on-chip cache memory.

  10. 10
    ExplanationPlace the levels in order

    Registers sit closest to execution, followed by L1, L2, L3, DRAM, and storage. Caches move blocks, commonly 64 bytes, while virtual memory uses pages, commonly 4 KiB.

    L1 often separates instruction and data caches so the pipeline can access both together. A miss in one level continues the search below; an L1 miss can still be an L2 hit.

  11. 11
    ExamplePrice the occasional miss

    Use a simplified 1-cycle lookup, 97% hits, and a 100-cycle extra miss penalty. Every request pays the lookup, and 3% pay the penalty:

    1+0.03×100=4 cycles.

    A miss costs 101 cycles here. The 100-cycle figure is additional time, so charging it as the entire miss time would omit the lookup on misses.

  12. 12
    ChallengeConnect the program with its average

    Two programs use the same 1-cycle cache and 80-cycle extra penalty. One has 2% misses; the other has 20%. Find their average times and explain why identical hardware gives different results.

    ---reveal---

    The averages are 1+0.02×80=2.6 and 1+0.20×80=17 cycles. Different access patterns produce different miss rates. The cache exploits the locality each program supplies; its capacity and technology alone do not fix the result.

  13. 13
    RecapRead an access at three scales

    When examining memory behavior, identify the item being reused, the block transferred with it, and the level serving it. Locality explains likely reuse, memory technology explains cost and capacity, and hit/miss timing turns those observations into an access-time estimate. For a concrete program, begin with the actual address stream.

2

Build and trace a cache lookup

15 steps
Split addresses, follow replacement state, and compare direct mapping with multiple ways.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionAn address must answer two questions
  2. 2
    ExplanationRemove the byte offset first
  3. 3
    ExplanationCount entries before index bits
  4. 4
    ChallengeCheck a new field split
  5. 5
    ExampleAccount for the stored tag
  6. 6
    ExampleBegin with an empty cache
  7. 7
    ExampleWatch one entry change owners
  8. 8
    ExampleFinish the replacement sequence
  9. 9
    ChallengeTrace without confusing bytes and blocks
  10. 10
    ExplanationTurn entries into sets and ways
  11. 11
    ExampleTrack recency on every access
  12. 12
    ChallengeDistinguish LRU from FIFO
  13. 13
    Key InsightKnow what more ways can buy
  14. 14
    ChallengeCompare equal-capacity designs
  15. 15
    RecapCarry state through the lookup
3

Diagnose a miss and preserve changed data

12 steps
Classify misses, follow dirty victims, and separate write-hit from write-miss policies.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionA miss has a cause and a service path
  2. 2
    ExplanationServe a waiting read
  3. 3
    ExplanationClassify by the right comparison
  4. 4
    ChallengeSeparate spare capacity from conflicts
  5. 5
    ConnectionChoose which cost to improve
  6. 6
    ExplanationTrack a write-back block
  7. 7
    ExplanationQueue write-through stores
  8. 8
    ExplanationSet a separate rule for write misses
  9. 9
    ChallengeFollow a store and a later read
  10. 10
    ExampleCount both directions of traffic
  11. 11
    ChallengeConnect classification with write traffic
  12. 12
    RecapKeep the decisions separate
4

Calculate the cost of a hierarchy

16 steps
Work from one cache to weighted traffic, CPI, clock changes, and several cache levels.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionAttach a denominator and a unit
  2. 2
    ExampleCalculate one-level AMAT
  3. 3
    TipConvert after calculating
  4. 4
    ChallengeInclude a stated complete miss time
  5. 5
    ExampleWeight the requests that exist
  6. 6
    ExampleChange from accesses to instructions
  7. 7
    ExampleFinish with runtime
  8. 8
    ChallengeIncrease the processor clock
  9. 9
    ConnectionCheck whether delays overlap
  10. 10
    ExampleKeep local and global rates distinct
  11. 11
    ExampleCompute the lower service cost
  12. 12
    ExampleReturn to the original stream
  13. 13
    ChallengeDiagnose a denominator error
  14. 14
    ExampleInsert one more conditional level
  15. 15
    ChallengeCombine cache traffic with CPI
  16. 16
    RecapChoose the correct level of accounting
5

Translate an address without confusing lookups

15 steps
Follow page offsets, permissions, TLB walks, and the indexing constraint in a VIPT cache.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionOne address, two lookup problems
  2. 2
    ExampleFind the unchanged part
  3. 3
    ExampleUse the page-table entry
  4. 4
    ChallengeTranslate a different byte
  5. 5
    ExplanationA valid page still has access rights
  6. 6
    ExplanationHandle a missing page
  7. 7
    ExampleEstimate a flat table
  8. 8
    ExplanationReuse translations in the TLB
  9. 9
    Key InsightFollow independent hit outcomes
  10. 10
    ChallengeDecide whether storage is needed
  11. 11
    ExampleCompute translation reach
  12. 12
    ExplanationStart cache indexing during translation
  13. 13
    ChallengeCheck a proposed L1 design
  14. 14
    ConnectionRetire stale translations
  15. 15
    RecapKeep translation state and data state separate
6

Make each fetched line useful

13 steps
Analyze strides, choose a data layout, size reusable tiles, and decide what prefetching can hide.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionBegin with the inner loop's addresses
  2. 2
    ExampleUse all the doubles in a line
  3. 3
    ExampleSee capacity and conflicts together
  4. 4
    TipChange the row stride
  5. 5
    ChallengeChoose a layout for the access
  6. 6
    ExplanationInterchange to expose streams
  7. 7
    ExplanationKeep three tiles active
  8. 8
    ExampleLeave room beyond the capacity estimate
  9. 9
    ChallengeStop edge tiles at the array bound
  10. 10
    Key InsightDistinguish fewer transfers from less arithmetic
  11. 11
    ExplanationFetch while useful work continues
  12. 12
    ChallengeExplain a smaller-than-expected speedup
  13. 13
    RecapTest a concrete change

Memory Hierarchy and Caches practice questions

50 Practice Questions in 5 sets

Set 1: Placement, misses, and stores10 Practice Questions

Question 1 of 10

A program accesses a block for the first time, and the demand access misses. How is that miss classified in the three-Cs model?
  1. Conflict
  2. Capacity
  3. Compulsory
  4. Coherence
Show answerHide answer
Answer: C
First use is a compulsory miss because the block has not been brought in by an earlier access. Even if its destination set is full, first-use classification comes first. A conflict miss instead identifies a later miss caused by placement restrictions compared with an equal-capacity fully associative reference.

Question 2 of 10

A write-back cache evicts a valid block whose dirty bit is clear. What must happen to that victim?
  1. It must be written down before replacement.
  2. It can be discarded without a write-back.
  3. Its replacement must use write-through.
  4. Its dirty bit must be set before eviction.
Show answerHide answer
Answer: B
A clear dirty bit means the cache has no changes to preserve for that block, so the clean victim can be overwritten. Writing every valid victim down would waste traffic by treating validity as evidence of modification. Validity establishes that an entry holds a usable block; dirtiness records pending changes.

Question 3 of 10

A 12 KiB cache has 64-byte lines and three ways per set. How many sets does it have?
  1. 32
  2. 192
  3. 64
  4. 256
Show answerHide answer
Answer: C
The cache contains 12288/64=192 data lines. Dividing those lines among three ways gives 64 sets. The 192-set choice counts individual lines as sets, which would describe a direct-mapped cache and would triple the intended data capacity if each set then had three ways.

Question 4 of 10

One full 2-way set uses LRU and initially contains P and Q, with P least recent. The accesses are Q, P, R, Q, where R is absent. Which blocks are evicted on the two misses?
  1. Q, then P
  2. P, then R
  3. P, then Q
  4. Q, then R
Show answerHide answer
Answer: A
The hits to Q and then P leave Q least recent, so loading R evicts Q. The later request to Q misses; P is now older than R and is evicted. Choosing P for the first victim preserves the initial recency order instead of updating it after the intervening hits.

Question 5 of 10

A no-write-allocate cache starts empty. A store to address 0x80 is followed by a read of 0x80, with no intervening accesses. What happens at this cache?
  1. Store misses; read hits.
  2. Store hits; read hits.
  3. Store hits; read misses.
  4. Store misses; read misses.
Show answerHide answer
Answer: D
The store misses and is sent downward without installing the line because the policy is no-write-allocate. The following read therefore misses and can fetch the line. A read hit would require allocation on the store or another fill, neither of which occurs in this sequence.

Question 6 of 10

A repeated demand access misses in a direct-mapped cache but hits in a same-size fully associative LRU cache receiving the same history. What caused the miss under the three-Cs test?
  1. A first access to the block
  2. A restriction on block placement
  3. Too little fully associative capacity
  4. A lower-level write-buffer overflow
Show answerHide answer
Answer: B
The reference cache retains the block with the same data capacity, so flexible placement would have avoided this repeat miss. That makes it a conflict miss. A capacity miss would also occur in the fully associative reference; the comparison rules that cause out for this particular access.

Question 7 of 10

A write-through cache has a finite write buffer. Stores arrive faster than the lower level can accept them for a sustained interval. What eventually happens?
  1. The cache switches to write-back.
  2. The lower level drops queued writes.
  3. The processor stalls when the buffer fills.
  4. The buffer removes the bandwidth limit.
Show answerHide answer
Answer: C
The buffer absorbs a temporary mismatch but has finite space, so sustained excess arrivals eventually fill it and stall further stores. It can hide write latency while space remains. It cannot raise the lower level's sustained acceptance rate or turn write-through into a different policy.

Question 8 of 10

An empty two-line fully associative LRU cache receives block reads 1, 2, 3, 1, 2. How many compulsory, capacity, and conflict misses occur?
  1. 2 compulsory, 3 capacity, 0 conflict
  2. 3 compulsory, 0 capacity, 2 conflict
  3. 3 compulsory, 1 capacity, 1 conflict
  4. 3 compulsory, 2 capacity, 0 conflict
Show answerHide answer
Answer: D
The first three distinct blocks give three compulsory misses. With only two lines, loading 3 evicts 1, and reloading 1 then evicts 2, so both later reads miss for capacity. No placement restriction exists in this fully associative cache, so calling those repeat misses conflicts would misidentify the cause.

Question 9 of 10

An empty one-line write-back, write-allocate cache has 32-byte lines. It receives stores to 0x00, 0x04, 0x20, and 0x24, then a read of 0x40. Counting fills and victim write-backs only, how many bytes move between this cache and the next level?
  1. 160 bytes
  2. 96 bytes
  3. 128 bytes
  4. 192 bytes
Show answerHide answer
Answer: A
The stores allocate blocks 0 and 1, and the final read fills block 2: three 32-byte fills. Both store-modified blocks are evicted dirty, adding two 32-byte write-backs, for 160 bytes total. The 96-byte choice counts incoming fills but loses the outgoing data needed to preserve the modified victims.

Question 10 of 10

An empty 2-way cache has two sets and LRU replacement. Block reads repeat 0, 2, 4 indefinitely. What is the hit rate after warm-up, and what would a four-line fully associative cache do?
  1. Two-thirds; it would also miss one-third.
  2. Zero; it would hit after its first three misses.
  3. One-third; it would hit after four misses.
  4. Zero; it would also miss on every access.
Show answerHide answer
Answer: B
All three even-numbered blocks map to set 0, which has only two ways. LRU evicts each block before its next turn, so every repeated access misses. A four-line fully associative cache holds all three after their first uses; total capacity is sufficient, and the restricted set placement causes the continuing misses.
Set 2: Memory behavior and cache lookup10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A program reads each element of a contiguous array once, in address order. Which kind of locality explains why fetching a whole line helps?
  1. Temporal locality in each element
  2. Spatial locality between elements
  3. Temporal locality between pages
  4. Spatial locality in repeated values
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Which property makes DRAM require refresh while SRAM does not?
  1. DRAM sends data on both clock edges.
  2. DRAM retains data when power is removed.
  3. DRAM stores each bit in a stable latch.
  4. DRAM stores charge that gradually leaks.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A request misses L1 and hits L2. Which statement describes this access?
  1. L2 supplies a block absent from L1.
  2. DRAM supplies a block absent from L2.
  3. The instruction raises a page fault.
  4. The TLB must reload a translation.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A direct-mapped cache has 8 KiB of data, 32-byte blocks, and 30-bit byte addresses. What are the tag, index, and offset widths?
  1. 17, 8, 5 bits
  2. 12, 13, 5 bits
  3. 18, 7, 5 bits
  4. 17, 5, 8 bits
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A direct-mapped cache has eight 16-byte entries. For byte address 0x2B6, which pair gives the entry index and byte offset?
  1. Index 6, offset 3
  2. Index 2, offset 6
  3. Index 3, offset 6
  4. Index 3, offset 11
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

An empty direct-mapped cache has two 8-byte entries. Reads access byte addresses 0x00, 0x07, 0x10, 0x04, in that order. What is the hit rate?
  1. 0%
  2. 25%
  3. 50%
  4. 75%
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

An aligned array contains 192 eight-byte values. A cold cache uses 64-byte lines, has room for the entire array, and performs no prefetching. With no other accesses, how many misses occur in a sequential scan?
  1. 12
  2. 64
  3. 192
  4. 24
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A memory request has 45 ns of initial latency, followed by a 128-byte transfer at 32 GB/s. What is its total service time in this model?
  1. 49 ns
  2. 45 ns
  3. 77 ns
  4. 41 ns
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A 4 KiB direct-mapped write-back cache has 32-byte lines and 24-bit byte addresses. Count data, tags, one valid bit and one dirty bit per line, with no other metadata. How many bits are stored?
  1. 34304 bits
  2. 34944 bits
  3. 34560 bits
  4. 33024 bits
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

An empty direct-mapped cache has four 16-byte entries. Reads access 0x24, 0x28, 0x64, 0x34, 0x2C, 0x68. What hit rate and final block at index 2 result?
  1. 50%; block 2
  2. 25%; block 6
  3. 16.7%; block 2
  4. 16.7%; block 6
Show answerHide answer

Save this lesson to see this answer.

Set 3: Access time and program speed10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

Cache A has a 0.8 ns lookup and 6% misses. Cache B has a 1.1 ns lookup and 4% misses. Both use the same additional miss penalty. At what penalty do their AMATs become equal?
  1. 5 ns
  2. 10 ns
  3. 15 ns
  4. 30 ns
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A cache serves 184 hits in 200 accesses. What is its miss rate?
  1. 8%
  2. 16%
  3. 92%
  4. 0.08%
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A report gives L2 misses divided by all requests that reached L2. Which rate is reported?
  1. Global L2 miss rate
  2. Global L1 miss rate
  3. Local L2 miss rate
  4. Local memory access rate
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A cache has a 2-cycle lookup, 6% misses, and an additional 75-cycle penalty per miss. At 2.5 GHz, what is its AMAT?
  1. 6.5 ns
  2. 1.8 ns
  3. 3.0 ns
  4. 2.6 ns
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Base CPI is 1.2, instruction misses are 1%, 40% of instructions make one data access, data misses are 5%, and all misses add 80 cycles without overlap. What is total CPI?
  1. 6.0
  2. 3.6
  3. 2.8
  4. 2.4
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

L1 misses 8% of requests. L2 has a local miss rate of 15%. What fraction of original requests misses both caches?
  1. 1.2%
  2. 15%
  3. 23%
  4. 0.12%
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A cache lookup takes 1 ns. Its miss rate is 10%, and a complete miss access takes 41 ns, including that lookup. What is AMAT?
  1. 5.1 ns
  2. 4.1 ns
  3. 5.0 ns
  4. 4.0 ns
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

Each instruction makes one fetch and an average of 0.5 data accesses. Instruction and data miss rates are 1% and 7%. Both caches have a 2-cycle lookup and a 60-cycle extra miss penalty. What is AMAT per memory access?
  1. 4.7 cycles
  2. 3.8 cycles
  3. 4.4 cycles
  4. 2.7 cycles
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

L1 lookup is 2 cycles and misses 5%. L2 lookup is 8 cycles and locally misses 20%. L3 lookup is 30 cycles and locally misses 10%. Memory adds 150 cycles after an L3 miss. What is AMAT?
  1. 2.45 cycles
  2. 4.35 cycles
  3. 3.95 cycles
  4. 2.85 cycles
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A program has base CPI 1.5 and 2.5 nonoverlapped memory-stall cycles per instruction at 2 GHz. The clock rises to 4 GHz; instruction count, base CPI, miss counts, and memory delays in nanoseconds stay fixed. What is the speedup?
  1. About 1.23 times
  2. About 2.00 times
  3. About 0.62 times
  4. About 1.60 times
Show answerHide answer

Save this lesson to see this answer.

Set 4: Pages, TLBs, and cache indexing10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

Which part of an address passes unchanged through ordinary page translation?
  1. The virtual page number
  2. The physical page number
  3. The page-table base
  4. The byte offset within the page
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

An access misses the TLB, and a page-table walk finds a valid mapping that permits the access. What is the normal next step?
  1. Read the page from storage.
  2. Install the translation and continue.
  3. Terminate the process for a bad address.
  4. Invalidate the data-cache line.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

With 8 KiB pages, virtual address 0x12345 maps to physical page number 0x2A. What is the physical byte address?
  1. 0x54345
  2. 0x2A345
  3. 0x54045
  4. 0x16345
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A fully associative TLB holds 96 translations, all for 16 KiB pages. What is its reach?
  1. 96 KiB
  2. 1536 MiB
  3. 1.5 MiB
  4. 6 MiB
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A process stores to a resident page. The TLB hits, but its current mapping grants read access only. What happens?
  1. The store succeeds because translation hit.
  2. The TLB must miss before a fault can occur.
  3. The page must be loaded again from storage.
  4. The processor raises a permission page fault.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A simple VIPT cache uses 64-byte lines and 4 KiB pages. Its data capacity is 64 KiB. What is the smallest power-of-two associativity that keeps all set-index and block-offset bits inside the page offset?
  1. 8-way
  2. 16-way
  3. 32-way
  4. 4-way
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A flat page table covers a 36-bit byte-addressed virtual space using 16 KiB pages and 8-byte entries. How much memory does one complete table require?
  1. 4 MiB
  2. 16 MiB
  3. 32 MiB
  4. 64 MiB
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

An empty four-entry fully associative LRU TLB uses 4 KiB pages. A loop repeatedly reads one 8-byte value at each address 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, in that order. All pages are resident. What happens after warm-up?
  1. Every translation lookup misses; faults are unnecessary.
  2. Only the first lookup of each loop misses; faults are unnecessary.
  3. Every translation lookup misses; each requires a storage read.
  4. All translation lookups hit; only 40 bytes are accessed.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A permitted access has a 2-cycle data-cache hit. A TLB lookup always costs 1 cycle before the cache lookup. TLB misses occur on 2% of accesses and add a 40-cycle walk; data-cache misses occur on 5% and add 80 cycles. No costs overlap and no faults occur. What is average access time?
  1. 6.8 cycles
  2. 4.8 cycles
  3. 7.6 cycles
  4. 7.8 cycles
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Processes P and Q map different virtual pages to physical frame 7. P may write; Q may only read. P changes a byte, and visibility is correctly coordinated by the system. What follows when Q later reads or stores to that mapped byte?
  1. Q reads its own separate copy and may store.
  2. Q can read the change but a store faults.
  3. Q faults on both operations because P wrote.
  4. Q reads the change and inherits P's write right.
Show answerHide answer

Save this lesson to see this answer.

Set 5: Code changes and hierarchy trade-offs10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

Which traversal visits adjacent elements of a normal rectangular C array a[i][j]?
  1. Increase i while j stays fixed.
  2. Decrease i while j stays fixed.
  3. Increase j while i stays fixed.
  4. Increase both i and j together.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

An aligned array has 600 records of 48 bytes each. A loop reads only one 8-byte field per record. Which layout minimizes transferred data for that field in a cold scan with 64-byte lines and no prefetching?
  1. A separate contiguous array for the field.
  2. The same records in their original order.
  3. The same records traversed in reverse order.
  4. The same records with 16 padding bytes each.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Three square tiles of 8-byte values must fit in a 48 KiB cache. Which listed tile side fits while leaving at least 8 KiB unused?
  1. 48
  2. 44
  3. 42
  4. 40
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Software prefetching lowers demand-cache misses in a one-time scan but runtime stays the same. The memory interface was already transferring at its sustained limit. Which explanation fits?
  1. Only scans that reuse each element can hide transfer latency.
  2. The scan still needs the same bandwidth-limited transfers.
  3. The lower demand-miss rate proves that fewer bytes now move.
  4. Prefetched data can bypass the interface's bandwidth limit.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A cache has 32 sets, 64-byte lines, and enough total capacity for the active data. A column traversal steps between rows of 256 doubles, all row starts line aligned. Which padding spreads successive row starts across every set?
  1. Pad to 264 doubles per row.
  2. Pad to 272 doubles per row.
  3. Pad to 288 doubles per row.
  4. Pad to 320 doubles per row.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A matrix dimension is 94 and tile side is 24. Each tile coordinate identifies one region, including partial edges. How many tile regions are there, and how many elements are in the bottom-right region?
  1. 16 regions; 576 elements
  2. 9 regions; 484 elements
  3. 16 regions; 484 elements
  4. 9 regions; 576 elements
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A blocked matrix kernel uses three square tiles of doubles in a 32 KiB cache. A proposal changes tile side from 16 to 40 and predicts 2.5 times fewer misses using the resident-tile model. Which assessment is justified?
  1. Three tiles need 12.5 KiB; the predicted reduction is justified.
  2. Three tiles need 37.5 KiB; the residency premise fails.
  3. Three tiles need 37.5 KiB; misses must fall by 6.25 times.
  4. Three tiles need 37.5 KiB; unchanged arithmetic fixes misses.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A fixed program has 0.04 L1 misses per instruction, base CPI 1, and a 120-cycle memory penalty with no L2. A proposed L2 adds a 12-cycle lookup and locally misses 10%, with all stalls sequential. What is the speedup at the same clock?
  1. About 1.25 times
  2. About 3.92 times
  3. About 2.00 times
  4. About 2.96 times
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A row-major matrix multiply changes from i-j-k to i-k-j. In the streaming model, the former has 1.125 misses per inner iteration. In the new order, B streams at one miss per eight iterations and the C row remains cached after warm-up. Ignoring other traffic, what steady-state miss reduction factor follows?
  1. 4.5 times
  2. 8 times
  3. 9 times
  4. 0.25 times
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A cache holds 128 data lines. A loop repeatedly cycles through five blocks that all map to one set. Compare a 4-way LRU design with an 8-way LRU design of equal line size and data capacity; the five blocks share a set in both. What changes after warm-up?
  1. The 4-way misses each time; the 8-way hits each time.
  2. Both hit each time because five is below 128.
  3. The 4-way hits once per cycle; the 8-way hits twice.
  4. Both miss each time because the set index is shared.
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

80 Key Terms, each with its definition

A

Amdahl's law
Amdahl's law limits total speedup by the fraction of execution time that an improvement affects and the time left unchanged.
Reducing core execution cost leaves memory waits as a larger share of runtime when those waits stay fixed.
Array of structures
An array of structures stores records contiguously with each record's fields together, favoring access to several fields of one record.
A particle update using position and velocity together can use much of the line fetched for one particle.
ASID
An address-space identifier, or ASID, distinguishes translations belonging to different address spaces when their TLB entries coexist.
Two processes can reuse a virtual page number without using one another's translation when entries carry appropriate ASIDs.
Average memory access time
Average memory access time is the expected delay per memory request, combining lookup time and the probability-weighted extra miss cost.
A slower lookup can erase the benefit of fewer misses when the saved lower-level penalty is small.

B

Bandwidth
Bandwidth is the amount of data a memory path can transfer per unit time, commonly expressed in bytes per second.
A 16 GB/s transfer path moves 64 bytes in 4 ns once the data stream begins after its initial latency.
Base CPI
Base CPI is the cycles per instruction already required before the additional memory stalls being modeled, including normal cache hits.
A stall model adds miss delays to base CPI instead of counting the cache hit time a second time.
Block offset
A block offset is the byte position within a cache line, represented by the lowest address bits for a power-of-two line size.
The low six bits of a byte address select one of the 64 byte positions within a 64-byte cache line.
Blocking
Blocking, or tiling, organizes a computation around small data regions that remain cached while their values are repeatedly reused.
Three matrix tiles can be reused for many multiply-adds before the algorithm moves to the next tile group.
Byte addressing
Byte addressing assigns a distinct memory address to each byte, so block numbers are found by removing byte-offset information.
Addresses differing only in low offset bits can select different bytes from the same resident line.

C

Cache hit
A cache hit occurs when the level being checked already holds the requested block in a valid entry with a matching tag.
A request can miss in L1 yet hit in L2, so its outcome must be named separately for each level.
Cache index
A cache index is the address field selecting the entry or set in which a memory block is allowed to reside.
In a four-entry direct-mapped cache, blocks 0 and 4 both select index 0 despite having different tags.
Cache line
A cache line, also called a block, is the fixed-size unit of data stored and transferred by a cache.
A 64-byte line supplies eight adjacent doubles even when the access that caused its fill requested only one.
Cache miss
A cache miss occurs when the checked cache level lacks a usable copy of the requested block and must obtain it from below.
Two alternating blocks can miss repeatedly when direct mapping makes each one replace the other.
Cache pollution
Cache pollution is displacement of useful resident blocks by data that provides little benefit, such as inaccurate or premature prefetches.
An overly early prefetch can occupy a line needed by current work and itself be evicted before use.
Cache trace
A cache trace is an ordered record of accesses and resulting state changes used to determine hits, misses, and evictions.
Updating each entry immediately after a fill lets the next row of the trace use the correct resident block.
Capacity miss
A capacity miss is a later miss that also occurs in an equal-capacity fully associative LRU cache receiving the same access history.
A two-line fully associative cache misses when a three-block cycle returns to the block just evicted.
Clock cycle time
Clock cycle time is the duration of one processor cycle, equal to the reciprocal of clock frequency and used to convert CPI into time.
Doubling clock frequency halves cycle time but doubles the cycles consumed by an unchanged DRAM delay.
Coherence miss
A coherence miss occurs when a block is absent because another core's write caused its cached copy to be invalidated.
A core can miss on recently used shared data after another core modifies the corresponding cache line.
Compulsory miss
A compulsory miss is a miss on a block's first access in the history, which increased cache capacity alone cannot avoid.
The first demand access to each line of a cold sequential array scan is compulsory without advance fetching.
Conflict miss
A conflict miss is a later miss avoided by an equal-capacity fully associative LRU cache because flexible placement retains the block.
A direct-mapped entry can alternate between two tags while a same-size associative reference retains both blocks.
Critical word first
Critical word first is a fill strategy that transfers the requested word before other words in the cache block to shorten its wait.
A request for a word near the end of a line can receive that word first instead of waiting for earlier words.

D

Direct-mapped cache
A direct-mapped cache permits each memory block to occupy exactly one entry, determined by its block address and the entry count.
When two active blocks share an entry, loading either one evicts the other even if other entries are empty.
Dirty bit
A dirty bit records that a cached block contains modifications not yet propagated to the next level of the hierarchy.
A clean valid victim can be discarded, while a dirty valid victim requires preservation of its changed data.
DRAM
DRAM is volatile memory that stores bits as capacitor charge requiring periodic refresh, providing dense and affordable main memory.
A large program can keep its active pages in DRAM while smaller caches retain the most frequently accessed lines.

E

Early restart
Early restart resumes the waiting access when its requested word arrives during a block fill, before the entire line is received.
The processor can continue with the needed word while the remainder of a long line is still transferring.

F

FIFO replacement
FIFO replacement evicts the block that entered a set earliest, without changing insertion order when that block is hit.
Repeated hits can make the oldest-loaded block very useful, yet FIFO still selects it before newer arrivals.
Fully associative cache
A fully associative cache has one set containing all entries, allowing any block to occupy any entry without an index field.
An equal-capacity fully associative LRU cache provides the reference used to separate conflict and capacity misses.

G

Global miss rate
A global miss rate divides a cache level's misses by the original processor memory requests, including requests served above that level.
L1 misses of 5% and local L2 misses of 20% produce a global L2 miss rate of 1%.

H

Hit rate
A hit rate is the number of accesses that find their block in the checked level divided by all accesses to that level.
Ninety hits in a hundred cache requests give a 90% hit rate and a complementary 10% miss rate.
Hit time
Hit time is the delay to access a cache level and establish its hit outcome, including the lookup performed on misses.
A 2-cycle lookup contributes two cycles to every request before any additional miss delay is counted.

L

Latency
Latency is the elapsed time from issuing a memory request until its first requested data becomes available.
A wide memory interface can deliver many bytes per second while a single dependent load still waits tens of nanoseconds.
Local miss rate
A local miss rate divides misses at one cache level by only the accesses that reached that level after upper-level filtering.
An L2 local miss rate of 20% describes its harder request stream, not 20% of all processor accesses.
Locality
Locality is the tendency of a program to concentrate its accesses within a relatively small part of its address space over a short time.
A loop can repeatedly use a small active region even when the program has allocated many gigabytes.
Loop interchange
Loop interchange swaps the nesting order of loops to change traversal while preserving the computation's required behavior.
Changing which matrix index runs fastest can turn a column stream into a row stream without reducing arithmetic.
LRU replacement
LRU replacement evicts the block whose most recent access is oldest among the valid entries in the selected set.
A hit changes recency even though it loads no new block, which can change the victim chosen on the next miss.

M

Memory bank
A memory bank is a separately controlled DRAM array of rows and columns whose operations can overlap those of other banks.
Interleaving requests across banks can increase delivered bandwidth while one bank waits on a row operation.
Memory hierarchy
A memory hierarchy is a set of storage levels combining small fast memories with larger slower ones to exploit program locality.
An L1 miss can be served by L2 before the request incurs the much longer delay of a DRAM access.
Memory-stall CPI
Memory-stall CPI is the additional cycles per instruction attributed to memory waits, with overlap treated according to the timing model.
A 0.02 miss count per instruction and 100-cycle nonoverlapped penalty add two cycles to total CPI.
Miss penalty
A miss penalty is the extra delay after the cache lookup required to fetch, install, and deliver a block from a lower level.
A 2-cycle lookup with an 80-cycle additional penalty makes a complete miss access take 82 cycles in a sequential model.
Miss rate
A miss rate is the fraction of a specified request population that does not find its block in the cache being measured.
A 4% miss rate is entered as 0.04 when multiplying it by an additional penalty in an AMAT calculation.
Multilevel cache
A multilevel cache combines a small fast upper cache with larger lower caches that serve many upper-level misses before main memory.
A request pays the L2 lookup only when it misses L1, so nested AMAT weights that lookup by the L1 miss fraction.

N

NAND flash
NAND flash is nonvolatile storage that reads and programs pages, erases larger blocks, and has limited program/erase endurance.
An SSD controller maps updated logical data to available flash space instead of treating flash like byte-writable DRAM.
No-write-allocate
No-write-allocate is a write-miss policy that sends the store downward without installing its block in the checked cache.
A one-time output stream can avoid displacing reusable cached data when its write misses bypass allocation.
Nonblocking cache
A nonblocking cache permits other hits or further misses to proceed while one or more block requests remain outstanding.
An out-of-order processor can serve an independent cached load while another load waits for a DRAM fill.

P

Padding
Padding adds unused storage between logical data regions, potentially changing address strides and how those regions map to cache sets.
Adding eight doubles to a power-of-two row length can spread successive row starts across different sets.
Page fault
A page fault is an exception caused when page translation or permission checks cannot complete normally for an access.
A prohibited store can fault on a resident page, while some absent mappings are resolved without reading storage.
Page frame
A page frame is a page-sized slot in physical main memory that can hold the contents mapped by a virtual page.
Two processes can deliberately share data by mapping selected virtual pages to the same physical frame.
Page offset
A page offset is the byte position within a page, preserved when its virtual page number is translated to a physical page number.
Two addresses in the same page share one translation while their different offsets select different bytes.
Page table entry
A page table entry records translation information such as a physical page number, validity, permissions, and access or dirty state.
A resident page can still reject a store when its PTE permits reads but does not grant write access.
Page-table walk
A page-table walk reads the mapping entries needed to translate an address after a TLB miss and checks whether the mapping permits access.
A successful walk refills the TLB while a missing or unpermitted mapping can raise a page fault.
Physical page number
A physical page number identifies the physical frame used by a mapping and forms the high part of the translated byte address.
The physical byte address is the frame base plus the unchanged page offset, not the unshifted frame number plus offset.
Prefetching
Prefetching requests data before a demand access needs it, allowing transfer latency to overlap useful work when the request is timely.
A stream prefetcher can prepare later array lines, but inaccurate requests still consume bandwidth and cache space.
Pseudo-LRU
Pseudo-LRU is an approximate replacement method that tracks less state than exact LRU while trying to favor recently used blocks.
Highly associative caches often approximate recency because recording a complete ordering costs more hardware.

R

Refresh
Refresh is the periodic restoration of charge in DRAM cells so leakage does not erase the values they store.
Normal-temperature DDR4 refresh covers its rows within a 64 ms window, with tighter timing at higher temperatures.
Row buffer
A row buffer is circuitry that holds an activated DRAM row so accesses can select columns without reopening that row.
Repeated requests to an already open row avoid the precharge and activation needed to switch rows in that bank.
Row-major order
Row-major order stores the elements of each rectangular array row contiguously, placing consecutive rows one after another.
In a C array a[i][j], varying j in the inner loop walks adjacent elements of one row.

S

Set-associative cache
A set-associative cache maps a block to one set but allows it to occupy any of several entries, called ways, within that set.
Two blocks sharing an index can coexist in a two-way set, avoiding evictions that direct mapping would require.
Spatial locality
Spatial locality is the tendency to access addresses near a recently accessed address, making neighboring bytes useful.
A sequential array scan can use the remaining values in a cache line after the first value brings it in.
SRAM
SRAM is volatile memory that holds bits in stable powered circuits without periodic refresh and is commonly used for fast caches.
An on-chip cache uses SRAM to provide low latency while keeping a small amount of frequently used data.
Stride
A stride is the address difference between successive accesses in a traversal, measured in bytes or in elements with the unit specified.
A column walk in a row-major matrix advances by a row's byte length instead of one element's size.
Structure of arrays
A structure of arrays stores each record field in its own contiguous array, favoring scans of that field across many records.
Summing only horizontal positions can fetch a packed position array without loading every particle's other fields.

T

Tag
A tag is the high address information stored with a cache entry to identify which block occupies the selected entry or set.
The same index can refer to many memory blocks, so a tag comparison distinguishes the currently cached one.
Temporal locality
Temporal locality is the tendency to access the same instruction or data item again soon after a previous access.
The instructions inside a short loop are fetched repeatedly as the loop processes successive elements.
Thrashing
Thrashing is repeated eviction and reloading of actively needed blocks, producing many misses because they cannot remain resident together.
Cycling through three blocks in a two-way LRU set can evict every block just before its next use.
Tile footprint
A tile footprint is the storage occupied by all tiles that must coexist for a blocked computation to retain its intended reuse.
Three 32-by-32 tiles of doubles occupy 24 KiB, leaving some room in a 32 KiB cache for other active data.
TLB
A translation lookaside buffer, or TLB, caches recent virtual-page translations and associated permissions to avoid repeated table walks.
A TLB hit can still accompany a data-cache miss because mapping residency differs from data-line residency.
TLB reach
TLB reach is the total address range represented by the available translations, calculated as entry count times page size for equal-size pages.
A 64-entry TLB covers 256 KiB with 4 KiB pages, even if a loop touches only a few bytes from each page.
Translation invalidation
Translation invalidation prevents cached mappings from remaining usable after relevant changes to page tables or address-space assignments.
RISC-V uses sfence.vma to coordinate translation-cache state with mapping updates.

V

Valid bit
A valid bit is entry metadata recording whether the stored tag and data describe a usable cached block.
An entry with matching tag bits still misses when its valid bit is clear after startup or invalidation.
VIPT cache
A virtually indexed, physically tagged cache starts set lookup with virtual address bits and checks identity with a translated physical tag.
A 32 KiB eight-way L1 can fit its set and line-offset bits within the offset of a 4 KiB page.
Virtual memory
Virtual memory maps process addresses to physical memory while supporting protection, controlled sharing, and storage-backed pages.
A process still uses virtual memory when all its active pages fit in DRAM and it performs no swapping.
Virtual page number
A virtual page number is the high part of a virtual address that identifies the page whose mapping translation must obtain.
With 4 KiB pages, removing the low 12 offset bits leaves the virtual page number used for translation.

W

Way
A way is one of the available cache entries within a set, each capable of holding a separately tagged data block.
An eight-way set can retain eight competing blocks before a new fill must choose a valid victim.
Wear leveling
Wear leveling is a controller technique that distributes flash writes and erasures across physical blocks to spread cell wear.
Repeated updates to one logical record can be placed in different physical blocks to avoid wearing out one location.
Weighted miss rate
A weighted miss rate combines request classes by adding their expected miss counts and dividing by their combined access count.
Instruction and data rates need access-count weighting when each instruction produces fewer than one data request.
Working set
A working set is the collection of blocks or pages a program actively uses during a particular time window.
Two working-set blocks can conflict in one entry even when their total size is below cache capacity.
Write buffer
A write buffer is a finite queue holding pending lower-level writes so execution can continue before those writes finish.
A long burst of stores fills the buffer if the destination cannot drain updates as quickly as they arrive.
Write-allocate
Write-allocate is a write-miss policy that fetches the missing block into the cache and then applies the store to that block.
A later read can hit in the line installed by an earlier allocating store to another byte of the same block.
Write-back
Write-back is a cache policy that records stores in a dirty cached block and sends that block downward when it is evicted.
Many stores to one resident line can be combined into one outgoing block transfer when the line is replaced.
Write-through
Write-through is a cache policy that sends each store to the next level as well as updating a cached hit, often using a write buffer.
A write buffer may hold the lower-level update temporarily even though the store has already changed the cached value.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started