Approximating LRU
Learn how a system approximates LRU with the help of use bits and the clock algorithm.
We'll cover the following
Use bits
As it turns out, the answer is yes: approximating LRU is more feasible from a computational-overhead standpoint, and indeed it is what many modern systems do. The idea requires some hardware support, in the form of a use bit (sometimes called the reference bit), the first of which was implemented in the first system with paging, the
Clock algorithm
How does the OS employ the use bit to approximate LRU? Well, there could be a lot of ways, but with the
Note that this approach is not the only way to employ a use bit to approximate LRU. Indeed, any approach which periodically clears the use bits and then differentiates between which pages have use bits of 1 versus 0 to decide which to replace would be fine. The clock algorithm of Corbato’s was just one early approach that met with some success and had the nice property of not repeatedly scanning through all of the memory looking for an unused page.
The behavior of a clock algorithm variant is shown in the figure below.
This variant randomly scans pages when doing a replacement; when it encounters a page with a reference bit set to 1, it clears the bit (i.e., sets it to 0); when it finds a page with the reference bit set to 0, it chooses it as its victim. As you can see, although it doesn’t do quite as well as a perfect LRU, it does better than approaches that don’t consider history at all.
Get hands-on with 1400+ tech skills courses.