LRU Full Form
LRU stands for Least Recently Used. The development of the LRU algorithm ended the debate and research that had been going on about page replacement algorithms in the 1960s and 1970s.
LRU replaces the line in the cache that has been in the cache the longest with no reference to it. It works on the idea that the more recently used blocks are more likely to be referenced again. LRU is the most frequently used algorithm as it gives less number of page faults when compared to the other algorithms.
Characteristics of LRU
- It has been observed that pages that have been recently heavily used will probably also be heavily used in the upcoming instructions and this forms the basis for LRU.
- When the page requested by the program is not present in the RAM, page fault occurs and then if the page frame is full then we have to remove the page that has not been in use for the longest period of time.
- Can be implemented easily in a 2-way set associative mapping in which each line includes a USE bit. The USE bit of the referenced line is set to 1 and that of the other line is set to 0. When the set is full, we consider that block for replacement whose USE bit is zero.
Advantages of LRU
- Unlike FIFO, LRU does not suffer from Belady’s Anomaly.
- It gives less number of page faults than any other algorithm other than optimal and as optimal algorithm cannot be implemented in real-life LRU is the most frequently used algorithm.
- LRU algorithm is very efficient.
Disadvantages of LRU
- There is more overhead as we have to keep track of which pages were referenced.
- It is difficult to implement as hardware assistance is required.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.