Operating system---page replacement algorithm

OPT (Optimal Elimination Algorithm)

Pages that will never be used in the future are removed from the main memory. If there is no such page, the page that will not be accessed for the longest time is selected. Ensure the lowest page fault rate . That is: the eliminated page is the page that will no longer be visited in the future or the longest time no longer visited.

When 2 enters for the first time, it is found that 7 will not be accessed for a long period of time in the future, so 7 is replaced. When 3 visits for the first time, it is found that 1 will not be visited for a long period of time in the future, then 1 is replaced. In turn.
Insert picture description here
Among them, the number of replacements is 6 times.
Insert picture description here
Number of page faults: 9 times
Insert picture description here

FIFO (first in first out)

The first page that enters the memory (the page that resides in the main memory for the longest time) is eliminated first. Similar to the idea of ​​a queue, the elements at the head of the queue are eliminated each time.
When 2 enters for the first time, it is found that 7 is the earliest used page, then 7 is replaced. When 3 is entered, it is found that 0 is the first to enter the memory, so 0 is replaced.
Insert picture description here
Replacement times: 12 times Page
Insert picture description here
missing times: 15 times
Insert picture description here

LRU (Least recently visited)

Eliminate the pages that have not been visited the longest recently.
When 2 entered for the first time, it was found that 7 was the longest not visited, so 7 was replaced. When 3 enters for the first time, it is found that 1 has not been visited for the longest time, so 1 is replaced.

Insert picture description here
Replacement times: 9 times Page
Insert picture description here
missing times: 12 times
Insert picture description here

LFU (Longest not used algorithm)

Selecting the least recently visited page as the page to be replaced (eliminate the least recently used page), the essence is to add a counter operation to each page visit, and select the page with the smallest count to swap out each time.

note
When using this algorithm, it should be noted that when the number of page visits is the same, other methods need to be used for replacement.

Insert picture description here
Replacement times: 8 times Page
Insert picture description here
missing times: 11 times
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42708024/article/details/108460796