UVMArena

Cache Memory Replacement Algorithm – MRU (Most Recently Used)

The Most Recently Used (MRU) replacement algorithm is a cache replacement policy where the cache block that was accessed most recently is replaced when a new block needs to be loaded and the cache is full.

Unlike FIFO, the order in which blocks were inserted into cache does not matter. What matters is which block was accessed most recently by the CPU.


Key Idea of MRU

  • When cache is full and a new block must be inserted:
  • Identify the most recently accessed block.
  • Replace that block with the new memory block.

MRU is based on the assumption that if a block was used very recently, it may not be needed again soon.


Important Observations

  • The order of filling cache lines does not matter.
  • Only the recent access history is important.
  • This makes MRU different from FIFO, where insertion order must be tracked.
  • The most recently referenced block is always the replacement candidate.

Example Scenario

Assume the cache contains 8 cache lines and the CPU generates the following reference string:


4, 3, 25, 8, 19, 6, 25, 8, 16, 35, 45, 22, 8, 3, 16, 25, 7

The cache initially starts empty.

  • Pages are loaded until the cache becomes full.
  • If the requested page already exists → Cache Hit
  • If it does not exist → Cache Miss
  • When cache is full → replace the Most Recently Used page

Results of the Example

  • Total Cache Misses: 11
  • Total Cache Hits: 6

For this particular reference string, the MRU algorithm performs better than FIFO and LRU because it results in fewer cache misses.


Final Cache State

After executing the entire reference string using MRU replacement:

  • Memory block 7 is stored in cache line 2.

(Cache blocks are typically indexed starting from 0.)


Important Note

The performance of cache replacement algorithms depends heavily on the reference string (the order in which the CPU accesses memory).

  • MRU may perform better in some workloads.
  • LRU may perform better in others.
  • No single replacement policy is universally optimal.