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.
Japanese name: ダイレクトマップ方式
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.
Japanese name: ダイレクトマップ方式
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.
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.
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.
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.
Answer: C. 17 bits
A 64-byte line = 2⁶, so the offset is 6 bits. The number of lines is, 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.
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.
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.
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.
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.
Direct-mapped cache appears in 3 practice questions across 1 topic, including Memory Hierarchy.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.