Brendan Ang

Search

Search IconIcon to open search

Least Recently Used Policy

Last updated Nov 8, 2022 Edit Source

# Least Recently Used Policy (LRU)

  1. Keep track of when each item is accessed
  2. When an item needs to be replaced, we will choose the one that has the oldest timestamp

# LRU-K

Rather than just taking the most recent access time for consideration, having a history of timestamps allows us to calculate the interarrival between references.

LRU-1 is just the normal LRU algorithm

  1. Keep track of the K previous access timestamps of the item.
    • This can be done with a HISTORY array
  2. When item on memory is accessed, we update the history array with the latest access time in a stack manner
  3. When item needs to be evicted, we will choose the one that has the oldest Kth timestamp

# Implementation

# Stack

Swap used pages to the top of stack. Push out pages at the bottom.

# LRU Approximation

Hardware support is necessary as exact algorithms are expensive and generally not available. It may be better to simply approximate LRU using an easier more supported implementation.

Clock (or Second Chance) Policy