Operating system memory page replacement algorithm

Source: Internet
Author: User

A fixed 3 page box is assigned to the process, the resident set size is fixed, the execution of the process requires access to 5 different pages, the page address order that the process needs to access is: 2 3 2 1 5 2 4 5 3 2 5 2

I. OPT (best page replacement algorithm)

The algorithm chooses to displace those pages that are the longest in the current time, and it can be seen that the algorithm can result in a minimal number of page faults, but it is not possible to expect the operating system to anticipate future time, but the algorithm can be used as a standard to measure the performance of other algorithms.


Ii. LRU (least recently used)

The page that was last used in displace memory from the current farthest. According to the local principle, this is also the most recently inaccessible page, in fact, the performance of LRU strategy is close to opt, the problem of this method is difficult to achieve. One way is to add a last-accessed time label to each page, and update the tag every time you access the memory. Even with hardware that supports this scenario, the overhead is great. Another option is to maintain a stack of access pages, but the overhead is still high

2013-5-25 12:59:46 upload Download attachment (32.11 KB)
Third, FIFO policy (first-in, in-advance)

This strategy takes the page box assigned to the process as a circular buffer, moving the page by loop, which requires just a pointer that loops through the process's page box, so this is the simplest page substitution strategy to implement. This policy displaces the pages that have been in the page box for the longest time, thinking that the dwell time is the longest and may no longer be used. This inference is wrong, because a part of the program or data will often be used throughout the life of the program is very high frequency, if the use of the algorithm, these pages need to call back and forth


Four, clock strategy

The simplest clock strategy requires that each page box be associated with an additional bit, called a bit. When a page is first loaded into memory, the usage bit of the page box is set to 1, and when the page is subsequently accessed (after the access produces a fault with the fault), its usage bit is also set to 1. For the page replacement algorithm, the permutation algorithm is used for permutation of the candidate Page box collection (Current process: local scope; whole memory; global scope) is considered a circular buffer and has a pointer pin associated with it. When a page is replaced, the pointer pin is set to point to the next page box in the buffer. When a page needs to be replaced, the operating system scans the buffer to find a page box that uses BITS to be set to 0. Whenever a page box with a bit of 1 is encountered, the operating system resets the bit to 0, and if all the page boxes in the buffer are used with a bit of 0 o'clock at the beginning of the process, select the first page box substitution encountered, or if all the page boxes have a bit of 1 o'clock, the needle is fully looped in the buffer for one week. Set all the used bits to 0, and stay in the original position, replacing the page in the page box. It can be seen that the policy is similar to FIFO (first-in, in-place), except that the use of a 1-bit page box in a clock policy is skipped, and the policy is called a clock policy because it is possible to visualize a page frame in a ring. Many operating systems use some variant of this simple clock strategy.


Note: The * number indicates that the corresponding use bit is 1, and the Red cell indicates where the pointer is pointing


Reprinted from: Http://www.itmian4.com/forum.php?mod=viewthread&tid=2767&extra=page%3D1

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.