Tuesday, May 13, 2025

Memory Mapping Techniques in computer architecture

Memory mapping is a process that manages how data is stored and retrieved from main memory and cache memory. 

Efficient memory mapping speeds up data access and optimizes memory utilization. 

The three main techniques are Direct Mapping, Associative Mapping, and Set-Associative Mapping.


1. Direct Mapping

  • In Direct Mapping, each block of main memory maps to exactly one cache line.
  • The mapping is determined by the formula:

  {Cache Line} = ({Block Number}) \mod (\text{Number of Cache Lines})

Example:

Assume:

  • Cache has 8 lines (0 to 7).
  • Main memory has 32 blocks (0 to 31).

Mapping:

  • Block 0 → Line 0
  • Block 1 → Line 1
  • Block 8 → Line 0 (since 8 % 8 = 0)
  • Block 9 → Line 1, and so on...

Advantages:

  • Simple and easy to implement.
  • Fast access due to fixed line mapping.

Disadvantages:

  • High conflict misses if multiple frequently accessed blocks map to the same line.

2. Associative Mapping

  • In Associative Mapping, a block from main memory can be loaded into any cache line.
  • Mapping is flexible but requires searching the entire cache to find a block.

Example:

Assume:

  • Cache has 8 lines.
  • Main memory has 32 blocks.

Mapping:

  • Block 0 can go to any line (0 to 7).
  • Block 8 can also go to any available line.

When searching for data, the cache is searched in parallel for a tag match.

Advantages:

  • Reduces conflict misses since any line can be used.
  • Better cache utilization.

Disadvantages:

  • Slower lookup due to searching all lines.
  • More complex hardware needed.

3. Set-Associative Mapping

  • A compromise between Direct Mapping and Associative Mapping.
  • Cache is divided into sets, and each block maps to a specific set but can go to any line within that set.
  • If the set has k lines, it is called k-way Set-Associative Mapping.

Example:

Assume:

  • Cache has 8 lines and is organized as 4 sets (2 lines per set).
  • Main memory has 32 blocks.

Mapping:

  • Block 0, 4, 8, 12 → Set 0 (can be in line 0 or 1 of Set 0).
  • Block 1, 5, 9, 13 → Set 1.

Advantages:

  • Reduces conflict misses better than Direct Mapping.
  • Balances speed and flexibility.

Disadvantages:

  • More complex than Direct Mapping.
  • Slightly slower than Direct Mapping due to set searching.

Comparison Table

Technique Mapping Logic Speed Complexity Conflict Misses
Direct Mapping Fixed cache line Fastest Simple High
Associative Mapping Any cache line Slowest Complex Minimal
Set-Associative Mapping Specific set, any line within Moderate Moderate Balanced


No comments:

Post a Comment