LRU Approximation (Second Chance Algorithm)


In computer operating systems, the LRU (Least Recently Used) approximation algorithm, commonly called the Second Chance algorithm, is a page replacement algorithm. It is based on the principle that pages that haven't been used in a while are more likely to be replaced than pages that have. In this article, we will discuss the details, advantages, and disadvantages of this article.

LRU Approximation Algorithm

To keep track of which pages are currently in memory, the LRU approximation algorithm employs a circular buffer. Each page receives a reference bit, which is initially set to 0. When a page is accessed, the reference bit on that page is set to 1. The operating system scans the circular buffer on a regular basis, looking for pages with reference bit 0. When such a page is discovered, it is replaced with the new one.

During the scan, if a page with reference bit 1 is found, the reference bit is set to 0 and the scan proceeds. By doing this, the page has a second chance to stay in your memory. The scan is repeated until a page with reference bit 0 is located if one is not found the first time.

The LRU approximation algorithm is not a true LRU algorithm, but it provides a good approximation with significantly less overhead. It is a straightforward and efficient algorithm that is found in many operating systems. However, in some cases, such as when the working set size is larger than the buffer size or when there are long periods of high memory activity, it may not perform well. More sophisticated page replacement algorithms may be required in such cases.

Advantages of LRU Approximation algorithm

There are several advantages to using the LRU approximation (Second Chance) algorithm, including −

  • Simplicity − The LRU approximation algorithm is simple to implement and has a low computational overhead. Each page only requires a single reference bit to be set and a circular buffer to store the pages.

  • Low Overhead − Since it does not require complex data structures or frequent memory scans, the LRU approximation algorithm has a low overhead. The algorithm only needs to scan the memory on a regular basis to look for pages with a reference bit of 0.

  • Good Performance − For most applications, the LRU approximation algorithm performs well, especially when the working set size is smaller than the buffer size. It can keep the most frequently used pages in memory while removing pages that are no longer needed.

  • Easy to Combine with Other Algorithms − To improve performance, the LRU approximation algorithm can be easily combined with other algorithms. It can be combined with the Clock algorithm, for example, to provide a more efficient page replacement algorithm.

  • Fairness − The LRU approximation algorithm is a fair algorithm that ensures all pages in memory have an equal chance of being evicted. This prevents pages from being evicted from memory unnecessarily and improves system performance overall.

  • Adaptability − The LRU approximation algorithm is adaptable and can be configured to work well in various system configurations. For example, the buffer size can be changed depending on the system's memory requirements, and the scanning frequency can be changed depending on the system's workload.

Disadvantages of the LRU approximation algorithm

Despite its benefits, the LRU approximation (Second Chance) algorithm has some drawbacks, which include −

  • Limited accuracy in choosing the least recently used page to evict

  • Poor performance when the working set size exceeds the buffer size

  • Increased memory scanning can impact system performance

  • Limited adaptability in certain system configurations

  • Complexity in implementation for multi-processor systems

The LRU approximation algorithm has shortcomings in terms of accuracy, performance, and adaptability. These constraints can have an impact on system performance in certain scenarios, and the algorithm may need to be tweaked to work optimally in different system configurations.


An efficient page replacement approach that works well in most situations is the LRU approximation (Second Chance) algorithm. We covered LRU Approximation in this article along with some of its benefits and drawbacks. It may be modified to fit different system configurations and is easy to apply. The system, meanwhile, has flaws in its performance, flexibility, and accuracy. When the working set size is larger than the buffer size, its performance could suffer because it might not always select the least recently used page for eviction.

Updated on: 04-May-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started