Point out the difference between direct mapping technique and associated mapping technique, with the help of example.


Q.) Point out the difference between direct mapping technique and associated mapping technique, with the help of example.

Subject: Computer System Organization

Introduction

Cache memory is a small-sized type of volatile computer memory that provides high-speed data access to a processor and stores frequently used computer programs, applications and data. It is the fastest memory in a computer, and is typically integrated onto the motherboard and directly embedded in the processor or main random access memory (RAM).

Mapping techniques in cache memory are used to determine the way a particular block of memory will be stored in the cache. These techniques play a crucial role in reducing the time taken to access data from the main memory. The two main types of mapping techniques are direct mapping and associative mapping.

Direct Mapping Technique

Direct mapping is a simple and commonly used technique where each block of the main memory maps to exactly one block of the cache.

Definition

In direct mapping, the cache lines are directly mapped to the main memory. This means that each block of the main memory is mapped to a specific line in the cache.

How it works

The address of a block in the main memory is interpreted as a tag and an index. The index determines the cache line where the block is stored, and the tag is stored in the tag field of the cache line to uniquely identify the block within the main memory.

Formulas involved

The formulas used in direct mapping are:

  1. Cache line = Block address mod number of lines in cache
  2. Tag = Block address / number of lines in cache

Advantages and disadvantages of direct mapping technique

The main advantage of direct mapping is its simplicity and low cost. However, it can lead to a high miss rate if several blocks map to the same cache line.

Example of direct mapping technique

Consider a cache memory with 4 lines (0 to 3) and a main memory with 8 blocks (0 to 7). If a program accesses the blocks in the order 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, the blocks will be mapped to the cache as follows:

  • Block 0 -> Line 0
  • Block 1 -> Line 1
  • Block 2 -> Line 2
  • Block 3 -> Line 3
  • Block 4 -> Line 0 (replaces block 0)
  • Block 5 -> Line 1 (replaces block 1)
  • Block 6 -> Line 2 (replaces block 2)
  • Block 7 -> Line 3 (replaces block 3)

When the program accesses the blocks again, they are not found in the cache (cache miss), so they have to be fetched from the main memory.

Associative Mapping Technique

Associative mapping is a more flexible and complex technique where a block of memory can be stored in any cache line.

Definition

In associative mapping, the cache lines are not directly mapped to the main memory. Instead, each block of the main memory can be mapped to any line of the cache.

How it works

The address of a block in the main memory is interpreted as a tag and a block. The block is stored in any cache line that is currently free. The tag is stored in the tag field of the cache line to uniquely identify the block within the main memory.

Formulas involved

The formula used in associative mapping is:

  1. Tag = Block address

Advantages and disadvantages of associative mapping technique

The main advantage of associative mapping is its flexibility and low miss rate. However, it is more complex and expensive than direct mapping.

Example of associative mapping technique

Consider the same cache memory and main memory as in the previous example. If the program accesses the blocks in the same order, the blocks will be mapped to the cache as follows:

  • Block 0 -> Line 0
  • Block 1 -> Line 1
  • Block 2 -> Line 2
  • Block 3 -> Line 3
  • Block 4 -> Line 0 (replaces block 0)
  • Block 5 -> Line 1 (replaces block 1)
  • Block 6 -> Line 2 (replaces block 2)
  • Block 7 -> Line 3 (replaces block 3)

When the program accesses the blocks again, they are found in the cache (cache hit), so they don't have to be fetched from the main memory.

Comparison between Direct Mapping and Associative Mapping

Parameter Direct Mapping Associative Mapping
Mapping Each block of main memory maps to exactly one cache line Each block of main memory can map to any cache line
Complexity Simple and low cost More complex and expensive
Miss rate High if several blocks map to the same cache line Low due to flexibility in mapping

Conclusion

Both direct mapping and associative mapping have their own advantages and disadvantages. Direct mapping is simple and low cost, but can lead to a high miss rate. On the other hand, associative mapping is more flexible and has a low miss rate, but is more complex and expensive. The choice between the two depends on the specific requirements of the system.

Diagram is not necessary in this case as the explanation and examples are clear and easy to understand.

Summary

Cache memory mapping techniques determine how data is stored in the cache. Direct mapping maps each block of main memory to exactly one cache line, while associative mapping allows each block to be stored in any cache line. Direct mapping is simple and low cost, but can lead to a high miss rate. Associative mapping is more flexible and has a low miss rate, but is more complex and expensive.

Analogy

Cache memory mapping techniques can be compared to organizing books on a bookshelf. Direct mapping is like assigning each book to a specific shelf, while associative mapping is like allowing each book to be placed on any available shelf. Direct mapping is simpler and cheaper, but can lead to a higher chance of books being misplaced. Associative mapping is more flexible and reduces the chance of misplacement, but requires more effort and resources to implement.

Quizzes
Flashcards
Viva Question and Answers

Quizzes

What is the main difference between direct mapping and associative mapping?
  • Direct mapping maps each block of main memory to exactly one cache line, while associative mapping allows each block to be stored in any cache line.
  • Direct mapping allows each block to be stored in any cache line, while associative mapping maps each block of main memory to exactly one cache line.
  • Direct mapping is more flexible and has a low miss rate, while associative mapping is simple and low cost.
  • Direct mapping is more complex and expensive, while associative mapping is simple and low cost.