Virtual Memory-based Page Replacement Algorithm

Source: Internet
Author: User
Tags bit set

Virtual Memory-based Page Replacement Algorithm

Four Page Replacement algorithms:

Optimal (OPT, Optional) Least Recently Used (LRU, Least Recently Used) First-In-First-Out (FIFO, First In First Out) Clock (Clock)

I. Optimal Replacement Algorithm

Select the OPT policy to replace the pages that the next visit is the longest from the current time. It can be seen that this algorithm can cause the least page breaks, but because it requires the operating system to know future events, obviously, this is impossible. However, it can still be used as a standard to measure the performance of other algorithms.

Ii. Least recently used algorithms

The LRU policy is used to replace the last used page in the memory that is farthest from the current one. According to the Locality Principle, this is also the most impossible page to access. In fact, the performance of the LRU policy is close to that of the OPT policy. This method is difficult to implement. One way is to add a last access timestamp to each page and update the timestamp each time the memory is accessed. Even if there is hardware for this solution, the overhead is still very large. Another optional method is to maintain a stack for accessing pages, but the overhead is also high.

Iii. Advanced FIFO Algorithm

The FIFO Policy regards the page box allocated to the process as a circular buffer and moves the page cyclically. It only needs a pointer, which loops in the page box of the process. Therefore, this is the simplest page replacement policy. In addition to its simplicity, the logic behind this selection method is to replace the pages that reside in the memory for the longest time: a page that has been retrieved into the memory a long time ago, and may no longer be used until now. This inference is incorrect because some programs or data are frequently used frequently throughout the life cycle of the program. If the FIFO algorithm is used, these pages are repeatedly swapped in and out, increasing the system overhead.

Iv. Clock

The clock is the approximate Implementation of LRU. The simplest clock policy requires an additional bit for each page. When a certain header is loaded into the memory, the usage of the page box is set to 1. When the page is subsequently accessed (after the page is interrupted ), his usage space will also be set to 1. The set of candidate page boxes used by the Page Replacement Algorithm for replacement is considered as a circular buffer, and a pointer is associated with it. When a page is replaced, the pointer is set to point to the next page box in the buffer zone. When one page needs to be replaced, the operating system scans the buffer to find a page box with a usage bit set to 0. Every time you encounter a page box with a bit of 1, the operating system places the value 0 as the new one. If at the beginning of this process, all the page boxes in the buffer zone are 0, select the first page box to replace. If the bits of all page boxes are 1, the pointer loops completely for one week in the buffer and sets all bits to 0, and stay at the original position, replace the page in the page box.

Example:

The execution of a process needs to access five different pages. The order of page addresses required to run the program is:
2 3 2 1 5 2 4 5 3 2 5 2

Related Article

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.