Cache Memory Mapping Techniques
Cache Memory Mapping Techniques
Abstract
Cache memory mapping techniques are essential for optimizing the performance of
computer systems by efficiently managing how data is stored and accessed in cache
memory. This document provides detailed notes on the various cache memory mapping
techniques, including direct mapping, associative mapping, and set-associative mapping.
Additionally, it includes important exam questions along with their answers and examples to
aid in understanding these concepts.
Content
• Direct Mapping
• Associative Mapping
• Set-Associative Mapping
3. Direct Mapping
In direct mapping, each block of main memory maps to exactly one cache line. The mapping
is done using the following formula:
#### Example:
• Suppose we have a cache with 4 lines and main memory with 16 blocks.
• Block 0 maps to Cache Line 0 (0 mod 4)
• Block 1 maps to Cache Line 1 (1 mod 4)
• Block 2 maps to Cache Line 2 (2 mod 4)
• Block 3 maps to Cache Line 3 (3 mod 4)
• Block 4 maps back to Cache Line 0 (4 mod 4)
#### Advantages:
• Simple to implement.
• Low hardware cost.
#### Disadvantages:
• High conflict misses if multiple blocks map to the same cache line.
4. Associative Mapping
In associative mapping, a block can be placed in any cache line. The cache uses tags to
identify which block is stored in which line.
#### Example:
• If a block from main memory is loaded into the cache, it can go into any of the cache
lines. The cache line will store the block along with its tag.
#### Advantages:
• Reduces conflict misses.
• More flexible than direct mapping.
#### Disadvantages:
• More complex and expensive to implement.
• Requires more hardware for tag comparison.
5. Set-Associative Mapping
Set-associative mapping is a hybrid of direct and associative mapping. The cache is divided
into several sets, and each set contains a number of lines. A block maps to a specific set but
can occupy any line within that set.
#### Example:
• If we have a 4-line cache divided into 2 sets (2 lines per set), the mapping would be:
#### Advantages:
• Balances the benefits of direct and associative mapping.
• Reduces conflict misses while being less complex than fully associative mapping.
#### Disadvantages:
• More complex than direct mapping.
• Requires more hardware than direct mapping.
#### Question 1: Explain the differences between direct mapping, associative mapping, and
set-associative mapping.
Answer:
• Direct Mapping: Each block maps to one specific cache line. Simple but can lead to
high conflict misses.
• Associative Mapping: Any block can go into any cache line, reducing conflict misses
but increasing complexity.
• Set-Associative Mapping: A compromise where blocks map to a set of lines, allowing
flexibility while managing complexity.
#### Question 2: What are the advantages and disadvantages of direct mapping?
Answer:
• Advantages: Simple to implement, low hardware cost.
• Disadvantages: High conflict misses due to multiple blocks mapping to the same line.
#### Question 4: How does set-associative mapping improve upon direct mapping?
Answer:
Set-associative mapping reduces conflict misses by allowing a block to be placed in any line
within a specific set, rather than being restricted to a single line as in direct mapping.
7. Conclusion
Understanding cache memory mapping techniques is crucial for optimizing computer
performance. Each technique has its own advantages and disadvantages, and the choice of
technique can significantly impact the efficiency of data retrieval. Mastery of these concepts
is essential for success in computer architecture and systems design.
8. References
• Computer Architecture: A Quantitative Approach by John L. Hennessy and David A.
Patterson.
• Operating System Concepts by Abraham Silberschatz, Peter B. Galvin, and Greg
Gagne.