Page Replacement Algorithm

Source: Internet
Author: User

 

1. first-in-first-out (FIFO)

Simplest Page ReplacementAlgorithmYes first in first out ( FIFO . This algorithmEssenceYes, it is always the one-page replacement of the longest (the oldest) Staying Time in the primary storage, that isGo to the Memory Page and exit the memory first.. The reason is: the page that is first transferred to memory is no longer used than the page that is just transferred to memory. Create FIFO Queue, the shelter has pages in the memory. The replaced page is always on the queue header. When a page is put into memory, it is inserted at the end of the team.
This algorithm is onlyIt is ideal to access the address space in a linear order.Otherwise, the efficiency is not high. Because the pages that are frequently accessed often stay in the primary storage for the longest time, as a result " Old " And have to be replaced.
FIFO Another drawback is that it has an exception, that is, when the storage block is added, the page disconnection rate increases. Of course, the page trend that causes such exceptions is rare.

2. Optimal Replacement Algorithm (OPT)

Optimal Replacement ( Optimal Replacement ) Is inTheoreticallyA proposed algorithm. ItsEssenceYes: when a new page is transferred and an old page must be replaced in advance, the selected old page should not be used in the future, or be accessed in the farthest future. This page replacement algorithm is used to ensure a minimum page missing rate.
However, it is difficult to implement the optimal page replacement algorithm, because it requires people to know all the page movements during the entire process in advance. However, this algorithmAvailable for Measurement(For example, through simulated experiment analysis or theoretical analysis)Advantages and disadvantages of other algorithms.

3 least time to use the algorithm (LRU)

FIFO Algorithm and OPT AlgorithmsDifferenceYes, FIFO The algorithm uses the duration after the page enters the memory as the basis for replacement. OPT The algorithm is based on the time when the page will be used in the future. If we use the recent past as an approximation of the near future, we can replace the pages that have not been used for the longest period of time in the past. ItsEssenceYes. When you need to replace one page,Replace the pages that have not been used for the longest time in the recent period.. LRU The algorithm is related to the last time used on each page. When you must replace a page, LRU The algorithm selects the pages that have not been used for the longest time in the past.
LRU The algorithm isFrequently Used Page Replacement AlgorithmsAnd is considered to be quite good, but there is a problem of how to implement it. LRU The algorithm must be supported by hardware. The problem is how to determine the sequence of last time used. There are two feasible methods:
( 1 ) Counter. The simplest case is that each page table item corresponds to a time field and CPU Add a logical clock or counter. This clock is used for each storage access. 1 . When you access a page, the content of the clock register is copied to the time field used by the corresponding page. In this way, we can keep the last accessed " Time " . On the Replace page, select the page with the minimum time value. In this way, not only the page table needs to be queried, but when the page table changes (because CPU Schedule) to maintain the time in the page table, you must also consider the problem of clock overflow.
( 2 Stack. Use a stack to retain the page number. Every time a page is accessed, it is taken out from the stack and placed on the top of the stack. In this way, the top of the stack always has the most used pages, while the bottom of the stack contains the pages that are currently the least used. To remove an item from the middle of the stack, use a bidirectional link with a head and tail pointer. In the worst case, removing a page and placing it on the top of the stack requires modification. 6 Pointers. Each modification requires overhead, but the page to be replaced can be directly obtained without searching, because the tail Pointer Points to the bottom of the stack, where there is a replaced page.
Implementation LRU Algorithms must have a large amount of hardware support and a certain amount of software overhead. Therefore, the actual implementation is simple and effective. LRU Approximate Algorithm.
One type LRU The approximate algorithm is not used recently ( Not recently used , Nur ). It adds a reference bit to each item in the block table, and the operating system periodically sets them 0 . When a page is accessed, hardware places the location 1 . After a period of time, you can check these bits to determine which pages have been used and which pages have been 0 Has not been used. You can set this bit 0 Because it has not been accessed recently.

4 second opportunity algorithm (SCR)

The basic idea of the second opportunity algorithm is FIFO Same, but improved to avoid replacing frequently used pages. When the page is replaced, check its access location. If yes 0 , This page will be eliminated; if the access bit is 1 To give it a second opportunity and select the next FIFO Page. When a page gets a second chance, its access location is 0 And its arrival time is set to the current time. If this page is accessed during this period, the access location 1 . In this way, the page with the second chance will not be phased out until all other pages have been phased out (or the Second Chance is also given ). Therefore, if a page is frequently used, its access bit is always 1 It will never be eliminated.
The second opportunity algorithm can be viewed as a circular queue. Use a pointer to indicate which page is to be eliminated. When a block is required, the pointer goes forward until the access bit is found to be 0 . As the pointer advances, the access bit is 0 . In the worst case, all access bits are 1 , The pointer should pass the entire queue for one week, and each page will give a second opportunity. This degrades FIFO Algorithm.

There are also many variants of the page replacement algorithm, such as considering whether the replaced page has been modified or notFIFOWhen the page selected by the algorithm is in use, hardware and software must be implemented collaboratively.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.