In the process of address mapping, a page fault is generated if the page is found to be no longer in memory. When a page break occurs, the operating system must select one of the pages in memory to move it out of memory to make room for the page that is about to be paged in. And the rule for choosing which page to retire is called the page replacement algorithm.
Consider the following page trends:
1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6
When the number of memory blocks is 3 o'clock, ask FIFO, LRU, opt the three kinds of replacement algorithm of the number of pages?
A: The page definition is that all memory blocks are initially empty, so the pages used for the first time are generated with a single fault.
When the number of memory blocks is 3 o'clock: 1.FIFO
The number of fault pages interrupted is 16.
In the FIFO algorithm, the page that first enters the memory is swapped out first. When page 6 to adjust, the state of the memory is 4, 1, 5, the page 6 before the page, 5, 1, 2, 4 is visible, 4 is the first to enter the memory, this time should be swapped out, and then the page 6 into memory.
2.LRU
The number of fault pages interrupted is 15.
In the LRU algorithm, the least recently used pages are first swapped out. When page 6 to adjust, the state of the memory is 5, 2, 1, the page 6 before the page, 5, 1, 2, see 2 for the most recent period of time the least used, this time should be swapped out, and then the page 6 into memory.
3.OPT
The number of fault pages interrupted is 11.
In the OPT algorithm, pages that are visited in the farthest future are swapped out first. When Page 6 is to be adjusted, the state of the memory is 1, 2, 5, the page after the page 6 to be transferred into the pages 2, 1, 2 、..., visible 5 for the most recent period of time use the least, this time should be swapped out, and then the page 6 into memory.
LRU algorithm: Select the least recently visited page as the replaced page. No Belady exception
FIFO algorithm: is a relatively simple implementation of the page replacement algorithm, the basic principle is "choose the first main memory of the page elimination", the reason is the first entry of the page, it is no longer used more likely than the most recently transferred to the page. There are belady anomalies.
OPT algorithm: Replace the future unused pages in the near future based on the actual usage. This algorithm is used to evaluate the quality of the replacement algorithm in the time standard. impossible to achieve. The selected obsolete page will be a page that is never used in the future or is no longer accessed for the longest time, which guarantees the lowest possible paging rate. No Belady exception