Detailed Notes On Cache Mapping and Cache Mapping Techniques
Detailed Notes On Cache Mapping and Cache Mapping Techniques
Abstract
This document provides a comprehensive overview of cache mapping and its various
techniques, which are crucial for optimizing memory access in computer systems. It includes
detailed explanations of different cache mapping methods, important questions that may
arise in examinations, and their corresponding answers. Examples are provided to illustrate
the concepts effectively, ensuring a thorough understanding of the topic.
---
Cache mapping refers to the method used to determine how data from the main memory is
stored in the cache memory. Cache memory is a small-sized type of volatile computer
memory that provides high-speed data access to the processor. The primary goal of cache
mapping is to improve the speed of data retrieval by keeping frequently accessed data
closer to the CPU.
1. Direct Mapping
2. Associative Mapping
3. Set-Associative Mapping
1. Direct Mapping
In direct mapping, each block of main memory maps to exactly one cache line. The mapping
is done using a simple modulo operation.
#### Example:
• Suppose we have a cache with 4 lines and main memory with 16 blocks.
• The mapping formula is: Cache Line = (Block Number) mod (Number of Cache Lines)
#### Advantages:
• Simple and easy to implement.
• Low hardware cost.
#### Disadvantages:
• High conflict misses if multiple blocks map to the same cache line.
2. Associative Mapping
In associative mapping, a block can be placed in any cache line. The cache uses a tag 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 line.
• The cache checks all lines to find the block using its tag.
#### Advantages:
• Reduces conflict misses.
• More flexible than direct mapping.
#### Disadvantages:
• More complex and expensive due to the need for additional hardware to search the
cache.
3. 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 multiple lines. A block can be placed in any line within
a specific set.
#### Example:
• If we have a 4-line cache divided into 2 sets (2 lines per set), Block 5 can go into either
line of Set 1 or Set 2 based on the mapping.
• The mapping formula is: Set Number = (Block Number) mod (Number of Sets)
#### Advantages:
• Balances the benefits of both direct and associative mapping.
• Reduces conflict misses while being less complex than fully associative mapping.
#### Disadvantages:
• More complex than direct mapping.
• Slightly higher cost due to additional hardware.
Short Questions
Long Questions
---
This document serves as a detailed guide for understanding cache mapping and its
techniques, providing essential information for exam preparation.