Module 13: Cache Memory Principles & Mapping Architectures
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Hardware Modeling #◇Cache Memory Principles & Mapping Architectures
◇Overview
Cache memory is high-speed on-chip SRAM situated directly between the CPU execution core and main memory, designed to transparently intercept memory requests. To service an access in a single clock cycle, cache hardware must rapidly map an incoming -bit memory address to an internal storage frame and verify whether the requested data is present. This module examines the three canonical cache mapping architectures: Direct Mapping, Fully Associative Mapping, and -Way Block Set-Associative Mapping. We formalize the mathematical bit-partitioning formulas for TAG, SET/LINE, and WORD/OFFSET fields, and derive total hardware bit-capacity equations including tag and status bit overheads.
◇Key Definitions
- Cache Line / Block: The fundamental atomic unit of data transfer between cache and main memory, typically 32, 64, or 128 bytes in size.
- Tag Store: A specialized memory array within the cache holding the high-order address bits corresponding to the memory block currently occupying each cache frame.
- Valid Bit (): A 1-bit status flag per cache line indicating whether the stored line contains valid, initialized data () or uninitialized garbage ().
- Dirty Bit (): A 1-bit status flag per cache line in write-back caches indicating whether the line has been modified by the CPU () and must be written to main memory upon eviction.
- Direct Mapping: A rigid mapping function where each main memory block maps to exactly one predetermined cache line index, given by .
- Fully Associative Mapping: A flexible mapping architecture where any main memory block can reside in any arbitrary cache frame, requiring parallel comparison across all tags.
- -Way Set-Associative Mapping: A hybrid architecture where the cache is partitioned into sets, each consisting of lines. A memory block maps to a unique set index (), but can occupy any of the lines within that set.
◇Theoretical Framework / Core Concepts
1. The Anatomy of a Cache Entry
Every cache line frame contains both the payload data and architectural metadata:
+---+---+-------------------------+-----------------------------------------+
| V | D | TAG Field | DATA BLOCK PAYLOAD |
|1b |1b | (t bits) | (Block Size * 8 bits) |
+---+---+-------------------------+-----------------------------------------+
^ ^
| +-- Dirty Bit (1 = Modified in cache, 0 = Clean)
+------ Valid Bit (1 = Frame holds valid data, 0 = Cold/Invalid)
2. Direct Mapping Architecture
In Direct Mapping, main memory block maps strictly to cache line index :
where is the total number of cache lines.
Direct-Mapped Address Partitioning (n bits total):
+-------------------------------+-----------------------+-----------------------+
| TAG (t bits) | LINE (k bits) | WORD (w bits) |
+-------------------------------+-----------------------+-----------------------+
n - k - w bits k = log2(Lines) w = log2(Bytes/Block)
Direct-Mapped Hardware Matching:
Address: [ TAG ] [ LINE ] [ WORD ]
|
v (k-bit Decoder)
Select Line k
|
+-----------v-----------+
Line k: | V | TAG_k | DATA_k |
+---+-------+-----------+
| | |
| v |
V=1? -+-> [ =? ] <----+ (Compare incoming TAG with TAG_k)
|
Hit / Miss
- Pros: Minimal hardware complexity; requires only 1 comparator; fastest hit time.
- Cons: Extremely vulnerable to conflict misses (thrashing) if a program repeatedly accesses two different memory blocks that map to the same line index.
3. Fully Associative Mapping Architecture
In Fully Associative Mapping, a main memory block can be placed in any vacant or evicted line. There is no line index in the address.
Fully Associative Address Partitioning (n bits total):
+-------------------------------------------------------+-----------------------+
| TAG (t bits) | WORD (w bits) |
+-------------------------------------------------------+-----------------------+
t = n - w bits w = log2(Bytes/Block)
Fully Associative Hardware Matching:
Address: [ TAG ] [ WORD ]
|
+------------+------------+ ... (Broadcast TAG to ALL lines)
| | |
v v v
+---------+ +---------+ +---------+
Line 0: | Comp #0 | | Comp #1 | | Comp #N | Line N-1
+---------+ +---------+ +---------+
| | |
+------------+------------+
|
OR Reduction Tree ---> Hit / Miss
- Pros: Completely eliminates conflict misses; maximizes storage utilization.
- Cons: Requires parallel comparators (), incurring high power, silicon area, and capacitive routing delay for large caches.
4. -Way Block Set-Associative Mapping Architecture
-Way Set-Associative mapping combines the search efficiency of direct mapping with the conflict resilience of associativity:
k-Way Set-Associative Address Partitioning (n bits total):
+-------------------------------+-----------------------+-----------------------+
| TAG (t bits) | SET (s bits) | WORD (w bits) |
+-------------------------------+-----------------------+-----------------------+
t = n - s - w bits s = log2(Sets) w = log2(Bytes/Block)
5. Mathematical Summary of Address Bit-Splitting
For a memory system with bytes of addressable physical memory, a cache capacity of bytes, and a block size of bytes:
| Parameter | Direct Mapping | Fully Associative | -Way Set-Associative |
|---|---|---|---|
| Total Cache Blocks () | |||
| Total Sets () | (Each line is a set) | (Single set) | |
| Offset Bits () | |||
| Index Bits | (No index field) | ||
| Tag Bits () | |||
| Comparators Required | 1 |
Total Cache Hardware Sizing Formula:
◇Worked Examples / Calculations / Hardware Traces
Example 1: Address Bit Splitting Across All Three Architectures
Problem: A system has a 32-bit physical address space (), a data cache, and a block size of . Calculate the exact bit widths for TAG, LINE/SET, and WORD fields for:
- Direct Mapping
- Fully Associative Mapping
- 4-Way Set-Associative Mapping
Solution:
- Address width .
- Block size .
- Cache size .
- Total cache blocks .
-
Direct Mapping:
- Index bits .
- Offset bits .
- Tag bits .
- Format: .
-
Fully Associative Mapping:
- Index bits .
- Offset bits .
- Tag bits .
- Format: .
-
4-Way Set-Associative Mapping ():
- Total sets .
- Set bits .
- Offset bits .
- Tag bits .
- Format: .
Example 2: Total Hardware Cache Sizing Calculation
Problem: For the 4-Way Set-Associative cache in Example 1, calculate:
- The raw data capacity (in bits and bytes).
- The total silicon storage capacity including Tag store, Valid bit, and Dirty bit for all lines.
- The percentage overhead introduced by metadata bits.
Solution:
-
Raw Data Capacity:
-
Total Hardware Storage Bits:
- Number of lines .
- Bits per line
- Total Cache Bits .
-
Metadata Overhead:
◇Complexity Analysis / Common Pitfalls
- Byte vs. Word Addressing Offset: When a memory problem specifies that addresses reference 32-bit words rather than bytes, the offset bits must be calculated as instead of . Forgetting this produces an off-by-2 bit allocation error.
- Calculating Sets vs. Blocks in Associative Caches: A common student mistake is using the total number of cache blocks () instead of the number of sets () when deriving the SET index field width .
- Direct Mapped Thrashing in Loops: Placing two arrays accessed simultaneously in a loop at memory addresses that share the same LINE index causes a cache miss on every single access, dropping system performance by over .
◇References & Navigation
- Previous Topic: ◇Memory System Organization & Hierarchy
- Next Topic: ◇Cache Replacement Policies & Write Strategies
- Related Notes: ◇Virtual Memory & Address Translation (Paging & TLB), ◇Functional Units & Performance Fundamentals
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
A 32-bit byte-addressable system uses a Direct-Mapped cache with 512 lines and a block size of 32 bytes. What is the bit configuration of the address fields?
How many tag comparators operate in parallel during a cache lookup in an 8-Way Set-Associative cache?
What is the primary advantage of Fully Associative cache mapping over Direct Mapping?
In a -Way Set-Associative cache with 2,048 total lines and , how many bits are required for the SET index field?
What is the function of the Valid bit () in each cache line?