Page Replacement Algorithm (OS)

Optimal permutation algorithm (OPT)

Optimal replacement algorithm: The pages selected for elimination each time will be pages that will never be used in the future, or pages that will not be accessed for the longest time, so that the lowest page fault rate can be guaranteed.
insert image description here
The optimal replacement algorithm can guarantee the lowest page fault rate, but in fact, only during the execution of the process can we know which page will be accessed next. The operating system cannot predict the access sequence of pages in advance. Therefore, an optimal permutation algorithm cannot be implemented.

First-in-first-out replacement algorithm (FIFO)

Each time you select the page to be eliminated, the page that enters the memory first.
Implementation method: Arrange the pages transferred into the memory into a queue according to the order in which they were transferred, and select the page at the head of the queue when the page needs to be swapped out. The maximum length of the queue depends on how many memory blocks the system has allocated for the process.

insert image description here
insert image description here

Least recently used replacement algorithm (LRU)

LRU (least recently used): The page eliminated each time is the page that has not been used the most recently.

insert image description here
The implementation of this algorithm requires special hardware support. Although the algorithm has good performance, it is difficult to implement and has a large overhead.

Clock replacement algorithm (CLOCK)

The clock replacement algorithm is an algorithm that balances performance and overhead, also known as the CLOCK algorithm, or the recently unused algorithm (NRU, Not Recent Used)

Simple CLOCK algorithm implementation method: set an access value for each page, and then link the pages in the memory into a circular queue through link pointers. When a page is accessed, its access bit is 1. When a page needs to be retired, just check the page's access bit. If it is 0, select the page to swap out; if it is 1, set it to 0, do not swap out for now, continue to check the next page, if all pages in the first round of scanning are 1, then these pages After the access position is 0 in turn, the second scan is performed (in the second round of scanning, there must be a page with the access bit of 0, so the simple CLOCK algorithm selects an eliminated page and it will go through at most two rounds of scanning)

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
The pointer starts to scan only when the page is changed, and when the page is not changed, only 0 or 1 is changed when the page is changed;

Improved Clock Algorithm

insert image description here

Guess you like

Origin blog.csdn.net/m0_50127633/article/details/118110579
Recommended