The key distinction between the FIFO and OPT algorithms (other than looking backward versus forward in time) is that the FIFO algorithm uses the time when a page was brought into memory, whereas the OPT algorithm uses the time when a page is to be used.
If we use the recent past as an approximation of the near future, then we can replace the page that has not been used for the longest period of time (see Fig. 9.14).
Figure 9.14: LRU page-replacement algorithm.
This approach is the least-recently-used (LRU) algorithm. The result of applying LRU replacement to our example reference string is shown in Fig. 9.14. The LRU algorithm produces 12 faults.
Notice that the first 5 faults are the same as those for optimal replacement.
When the reference to page 4 occurs, however, LRU replacement sees that, of the three frames in memory, page 2 was used least recently.
Thus, the LRU algorithm replaces page 2, not knowing that page 2 is about to be used.
When it then faults for page 2, the LRU algorithm replaces page 3, since it is now the least recently used of the three pages in memory.
Despite these problems, LRU replacement with 12 faults is much better than FIFO replacement with 15.
Allocation of Frames
Now, first major problem mentioned in Section 9.4.1 will be discussed. How do we allocate the fixed amount of free memory among the various processes?
If we have 93 free frames and two processes, how many frames does each process get?
The simplest case is the single-user system.
Consider a single-user system with 128 KB of memory composed of pages 1 KB in size. This system has 128 frames.
The OS may take 35 K8, leaving 93 frames for the user process.
Under pure demand paging, all 93 frames would initially be put on the free-frame list.
When a user process started execution, it would generate a sequence of page faults.
The first 93 page faults would all get free frames from the free-frame list.
When the free-frame list was