# Page replacement algorithm

Source: Internet
Author: User

The page permutation algorithm is divided into the local page substitution algorithm and the global page permutation algorithm according to the selection of the displacement page.

The local page substitution algorithm only replaces the physical pages in this process, and a page in the process is in memory, which means that a page has been replaced with memory, so the total number of physical pages occupied by a process is determined. The global page replacement algorithm displaces all the physical pages that can be swapped out in memory, that is, a page of process A that is swapped into memory, and the memory may be a page of process B, so the total number of pages that the process occupies in memory is variable.

First, the local page replacement algorithm:

1. Optimal page replacement algorithm:

Predict the last page to be used in the future and replace it with external memory. The least pages, but not the implementation, is just an ideal state, so as the evaluation criteria for other permutation algorithms.

2. FIFO algorithm

There is a list of the logical page, the chain of the head in memory for the longest time, the shortest end of the chain, so each replacement is the link to the head of the page into the external memory, the newly added page to the end of the list. Although this algorithm is simple, it causes a higher rate of missing pages, and the performance is relatively poor.

3. Last unused algorithm/least recently used algorithm

Replaces one of the earliest pages in memory that was last quoted time. You can use a linked list or stack to record the length of the quoted time of the page sorted, but whether it is a stack or a linked list, each replacement will involve the entire list or stack movement, the algorithm performance is better, but the cost is relatively large.

4. Clock algorithm

Store each page with a ring-linked list. The access bit for each page at initialization is 0. If not, set the access bit of the corresponding page to 1. If the page is missing, then from the first to enter the list of pages to traverse, encountered the access bit is 1 of the page, the access bit is set to 0, encountered the access bit is 0 of the page, then replace it to external memory, and then replace the required page into memory, and access bit 1. Then move the current pointer over the next page and proceed to the next page request processing.

More than a FIFO access bit to record page access, but less than LRU the order of access, so it is FIFO and LRU compromise.

5. Improved clock algorithm

The modified bit is added to the page, 1 is modified, and 0 is not modified. Because when a page break occurs, the unmodified pages are replaced with external memory to remove the page directly from memory, because the memory and external memory in the corresponding page content is the same, processing time only one time page fault access external memory. The modified pages also need to write to the external memory once, plus the time of the page break, the equivalent of access to two times external memory, is the above unmodified twice times. So avoid replacing modified pages to improve performance.

With the modified bit, when the pointer is modified to a 1-bit page, if using a bit of 1, only the use bit is set to 0, the change bit is unchanged, if the bit is 0, the modifier bit is set to 0, and then the page is written to external memory to do the update. When replaced, only the modified bits and pages with a bit of 0 are replaced.

6. Least commonly used algorithms:

The page has several as the access count, each access will add the number of visits, replace the minimum access count to replace the memory.

Arguably, the more physical pages a process is allocated, the fewer pages should be missing. But there are also the phenomenon that the number of missing pages increases, that is belady phenomenon.

8. Compare

Look at the picture. (CLOCK,LRU and FIFO performance for pages that have not been accessed)

Second, global permutation algorithm:

1. Working Set algorithm:

The working set is represented as a two-tuple function w (t,), T is the current moment, for the page Access time window, and the working set is the collection of all access pages during the T-to-t time period.

A resident set is a collection of pages that the process actually resides in memory at the current moment.

The working set substitution algorithm means that each time the memory is accessed, the pages that do not exist in the working set are swapped out of memory, regardless of whether the access page is missing or not.

2. The replacement algorithm of the missing pages rate

When accessing memory without missing pages, the corresponding page reference is set to 1. Page faults, the current time and the last time the page is subtracted to calculate the time interval, if the time interval is greater than the given window, it is too low, the process in memory of the number of physical pages too much, the process concurrency decreases, the CPU efficiency will be reduced, need to replace some pages. If the time interval is less than the given window, it means that the fault rate is too high and the missing pages are added into memory.

Unlike the working set algorithm described above, the page-fault rate substitution algorithm only increases or decreases when pages are missing. In this way, the part of the replacement process can be submitted to the hardware for processing when the missing pages are interrupted, which improves the performance.

Page replacement algorithm

Related Keywords:

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.