Introduction
Cache Basics Direct Mapped Cache Direct Mapped Example 1 Direct Mapped Example 2 Direct Mapped Problem 1 Direct Mapped Problem 2 Direct Mapped Problem 3 Direct Mapped Problem 4 Direct Mapped Comparators Direct Mapped Disadvantages Direct Mapped Locality Direct Mapped UVM Example Associative Mapped Cache Associative Mapped Problem 1 Associative Mapped Problem 2 Associative Mapped Problem 3 Associative Mapped Problem 4 Set Associative Mapped Cache Set Associative Mapped Comparators Set Associative Mapped Problem 1 Set Associative Mapped Problem 2 Set Associative Mapped Problem 3 Set Associative Mapped Problem 4 Set Associative Mapped Problem 5 Other Mapping Problem - Example 1 Cache Replacement Algorithms LRU Cache Replacement Algorithm FIFO Cache Replacement Algorithm MRU Cache Replacement Algorithm PLRU Cache Replacement Algorithm Round Robin Cache Replacement AlgorithmUVMArena
Direct Mapped Cache – Problem 3
In this problem we analyze a Direct Mapped Cache configuration and determine the RAM size and the tag directory size. Throughout the analysis we assume the system is byte-addressable, meaning every byte in memory has its own address.
Given
- Cache Size: 256 KB
- Block Size: 1 KB
- Tag Size: 8 bits
First convert the values to powers of two:
- Cache Size = 256 KB = 218 bytes
- Block Size = 1 KB = 210 bytes
Step 1 – Determine the Offset Bits
Since the block size is 210 bytes, we need 10 bits to address each byte inside the block.
Step 2 – Determine Line Bits
The number of cache lines is calculated using:
Number of Lines = Cache Size / Block Size
218 / 210 = 28
Therefore the cache contains:
To index 256 lines we need:
Step 3 – Address Structure
The physical address in a direct mapped cache consists of:
- Tag
- Line Index
- Offset
From the problem statement:
- Tag = 8 bits
- Line Index = 8 bits
- Offset = 10 bits
8 + 8 + 10 = 26 bits
Step 4 – Calculate RAM Size
With a 26-bit physical address, the number of possible addresses is:
226 addresses
Because the system is byte-addressable, the RAM size is:
Step 5 – Tag Directory Size
Every cache line stores a tag. Therefore the total tag storage (tag directory) is:
Tag Directory Size = Number of Lines × Tag Bits
= 28 × 8 bits
Convert bits to bytes by dividing by 8:
(28 × 8) / 8 = 28
Shortcut Method
Another quick way to solve the problem is:
-
Compute number of lines:
218 / 210 = 28 - Line bits = 8
- Offset bits = 10 (from block size)
- Tag bits = 8 (given)
- Total physical address bits = 8 + 8 + 10 = 26
- RAM size = 226 bytes = 64 MB