What is Direct-mapped cache?

A cache organization in which each address can be placed in exactly one location. It is simple with short hit time, but prone to conflict misses when addresses compete for the same slot.

Field: Memory Hierarchy

Japanese name: ダイレクトマップ方式

How an address is split

A direct-mapped cache divides each address into three fields. The offset selects a byte within a line, the index selects the one line where the block may live, and the remaining high bits form the tag stored with the line. For a 32-bit address, a 32 KB cache and 64-byte lines, the offset is 6 bits, there are 512 lines so the index is 9 bits, and the tag is 32 − 9 − 6 = 17 bits. A hit occurs when the stored tag matches and the valid bit is set.

Why the hit time is short

Because a block has only one possible location, a lookup reads one tag and one data entry and uses a single comparator. No multiplexer is needed to choose among ways, and the data can be forwarded speculatively while the tag check finishes, since there is only one candidate. No replacement policy is needed either: on a miss, the block in that line is simply replaced. This simplicity gives short hit time, small area and low energy per access, which is why small, speed-critical caches have sometimes been direct-mapped.

The conflict miss problem

Misses are often classified as compulsory (first access), capacity (working set larger than the cache) and conflict misses. In a direct-mapped cache, any two addresses that differ by a multiple of the cache size map to the same line. If a loop alternates between two such blocks, for example two arrays aligned on the same power-of-two boundary, each access evicts the other even though most of the cache is empty. Padding or offsetting one array, or adding a small fully associative victim cache for recently evicted lines, reduces this thrashing.

Direct-mapped vs. set-associative

A direct-mapped cache is simply a one-way set-associative cache, and a fully associative cache is the opposite extreme with a single set. Moving from direct-mapped to n-way associativity lets n blocks with the same index coexist, cutting conflict misses, but requires comparing n tags in parallel and selecting the matching way, which tends to lengthen hit time and raise power. For the same capacity, a 4-way cache has four times fewer sets, so the index shrinks by 2 bits and the tag grows by 2 bits. The right choice depends on average memory access time.

Try it: questions about Direct-mapped cache

For a direct-mapped cache with 32-bit addresses, 32 KB capacity and 64-byte lines, how many tag bits are there?

  1. A15 bits
  2. B19 bits
  3. C17 bits
Show answer and explanation

Answer: C. 17 bits

A 64-byte line = 2⁶, so the offset is 6 bits. The number of lines is32 KB64 B=32,76864=512=2932 KB ÷ 64 B = 32,768 ÷ 64 = 512 = 2⁹, and in a direct-mapped cache each line is its own set, so the index is 9 bits. The rest is the tag: 32 − 9 − 6 = 17 bits. 19 bits would apply to a 4-way set-associative cache, where the index shrinks by 2 bits, not to a direct-mapped one.

In a direct-mapped cache, elements of two arrays map to the same cache location and evict each other on every alternating access. How is this miss classified?

  1. ACompulsory miss
  2. BCapacity miss
  3. CConflict miss
Show answer and explanation

Answer: C. Conflict miss

Misses where two pieces of data fight over the same set and evict each other, even though the cache as a whole has room, are conflict misses. Raising associativity so a set can hold both, or offsetting one array so it maps to different sets, reduces them. Capacity misses arise because the working set exceeds the whole cache and persist even with full associativity. Compulsory misses happen on first access and do not describe repeated accesses.

FAQ

How do you calculate the tag bits of a direct-mapped cache?

Subtract the offset bits (log2 of the line size) and the index bits (log2 of the number of lines) from the address width; for example, with 32-bit addresses, 32 − 6 − 9 = 17 bits for a 32 KB cache with 64-byte lines.

Why does a direct-mapped cache have more conflict misses?

Each block can go in only one line, so any blocks sharing an index evict each other even when other lines are free; associative caches give each index several slots.

Is a direct-mapped cache faster than a set-associative cache?

Its hit time is usually shorter because only one tag is compared, but its higher miss rate can make the overall average access time worse, so the comparison depends on the workload and miss penalty.

Questions that mention Direct-mapped cache (1)

Direct-mapped cache appears in 3 practice questions across 1 topic, including Memory Hierarchy.

  1. What changes when a cache is switched from direct-mapped to set-associative?

Books on Memory Hierarchy Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

Semiconductor, Electronics and Computing Calculators

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary