←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Cache Memory Mapping Techniques & Associative Memory (CAM)

Study material and explanations for Unit 5

Cache Memory, Mapping Techniques, and Associative Memory (CAM)

What is Cache Memory? (In Simple Words)

Cache Memory is an extremely fast, small SRAM storage buffer built right inside the CPU chip.

  • Its only job is to store copies of the data and instructions the CPU will need next.
  • When the CPU finds its data in cache, it answers in 1 to 2 clock ticks instead of waiting 50 to 100 ticks for slow RAM!

1. The Principle of Locality of Reference

Why does a tiny 8 MB cache work so well when your computer has 16,000 MB (16 GB) of RAM?
Because computer software naturally follows the Locality of Reference:

The Two Dimensions of Locality
1. Temporal Locality (Time)
If you access a variable now, you will likely access it again very soon.
(e.g., loop counter i in for(i=0; i<1000; i++))
2. Spatial Locality (Space)
If you access one address, its nearby neighbor addresses will be accessed next.
(e.g., array elements arr[0], arr[1], arr[2])

💡 Real-Life Indian Student Analogy:
Think of doing your college homework:

  • Temporal Locality: You keep your favorite pen on your notebook because you keep using it every 10 seconds.
  • Spatial Locality: You open chapter 3 of your book; once you finish page 45, you naturally read page 46 next!

2. Hit Ratio and Average Access Time Formula

  • Cache Hit: The CPU looks for data in Cache and finds it immediately!
  • Cache Miss: The data is not in Cache; the CPU must fetch it from slow RAM.
  • Hit Ratio (H):
    H = (Number of Cache Hits) / (Total Memory Requests)

Average Memory Access Time (T_avg):

T_avg = (H × T_c) + ((1 - H) × T_m)

  • Where T_c is Cache speed (e.g. 2 ns) and T_m is RAM speed (e.g. 50 ns).
  • If your system has a 95% hit rate (H = 0.95):
    T_avg = (0.95 × 2) + (0.05 × 50) = 1.9 + 2.5 = 4.4 ns
    (The computer runs more than 11 times faster thanks to cache!).

3. Cache Mapping Techniques

How does a block from large RAM get placed into the smaller cache? There are 3 mapping methods:

Cache Mapping Comparison
1. Direct Mapping
Each RAM block maps to strictly ONE fixed cache line.
Formula: Line = Block mod Total Lines
2. Associative Mapping
Any RAM block can be placed in ANY free cache line.
Zero conflicts, but needs expensive search hardware.
3. Set-Associative Mapping
Cache is divided into sets (e.g., 2-way or 4-way).
The perfect middle ground used in all modern CPUs!

4. Associative Memory (Content Addressable Memory - CAM)

In normal RAM, you provide an address number to get data: “Give me what is stored at address 500”.

Associative Memory (CAM) works backwards: you search by data content:
“Search the whole memory at once and tell me which row contains the roll number 105!”

Associative Memory Hardware Organization
Argument Register (A) ➔ Word to Search
Key Register (K) ➔ Bitmask of Interest
➔ Parallel Match Logic ➔ Match Register (M)

Hardware Registers:

  1. Argument Register (A): Holds the specific word or number you are searching for.
  2. Key / Mask Register (K): Chooses which bits to compare and which bits to ignore.
  3. Match Register (M): Has 1 bit for every row in memory. If Row 4 matches your search, bit M[4] becomes 1!

Where is CAM Used?

  • TLB (Translation Lookaside Buffer): In Virtual Memory to translate page addresses in 1 nanosecond.
  • Internet Routers: To match destination IP addresses at Gigabit network speeds.

💡 DAVV Exam Preparation Tips

5-Mark Question: “Explain Temporal and Spatial Locality of Reference with examples.”

  • Define both clearly:
    • Temporal: re-accessing same data recently used.
    • Spatial: accessing neighboring memory locations.
  • Give the C-programming example:
    for(int i = 0; i < N; i++) { sum += A[i]; }
    Explain that variables i and sum show Temporal locality, while array A[i] shows Spatial locality.

10-Mark Question: “Explain Direct Mapping, Associative Mapping, and Set-Associative Cache Mapping techniques with block diagrams and address formats.”

  • Show the memory address format for all 3: Tag, Index/Set, and Word offset.
  • Explain why Direct Mapping is simple but causes conflict misses if two active blocks fight for the same line.
  • Explain how Set-Associative mapping (2-way, 4-way) gives the flexibility of associative mapping with the speed of direct mapping.