"Operating system" page replacement algorithm __ algorithm

Source: Internet
Author: User
1, the page replacement algorithm is why

the basics of how virtual page storage Management works: before the process runs, instead of loading all the pages, instead of loading all the pages, load one or 0 pages, then dynamically mount the other pages according to the needs of the process, and when the memory space is full and the new pages need to be loaded, some sort of algorithm eliminates a page in order to load a new page.

When using virtual page storage management, you need to add some content to the page table, and the contents of the page table are as follows:
Page number, resident bit, memory block number, external address, access bit, modify bit
Where the resident bit, also known as the interrupt bit, indicates that the page is in memory or external storage; The access bit indicates whether the page was accessed during memory, known as R bit, and whether the modification bit indicates if the alternative has been modified in memory, known as M-bit.

the access bit and the modification bit can be used to determine which page to replace, such as the Second Chance page replacement algorithm.

Page break: in the address mapping process, if you find that the page you want to visit in the table is not in memory, it will result in missing pages.

When a page break occurs, the operating system must select one of the pages in memory to remove the page so that the page you are about to make up is out of space. 2. Page Replacement algorithm

(1) ideal page (Opt:optimal)

This is an ideal page replacement algorithm, but it is actually impossible to achieve.

The basic idea of the algorithm is that when a page fault occurs, some pages are in memory, and one of the pages will be accessed soon (the page that contains the next instruction immediately), other pages may be accessed after 10, 100, or 1000 instructions, and each page can be marked with the number of instructions to be executed before the page is first accessed. the largest page of the tag tree should be replaced.

For example: If a page is not used in 8 million instructions, and another page is not used in 6 million instructions, the previous page is replaced.

This algorithm can not be implemented, because when the page fault is interrupted, the system can not know the next time the individual pages are visited.

(2) Advanced first Out (fifo:first-in first-out)

Advanced First out page replacement algorithm always select the first load of memory page to pull up, or to reside in the memory of the longest page.

FIFO algorithm is simple and easy to implement. In order to put the pages loaded into the memory of the pages in order to enter the queue, each time always pull the first page of the team. When the system maintains a list of all current pages in memory, the oldest page is on the head, the newest page at the end of the table. When a page fault occurs, the table header is eliminated and the newly transferred page is added to the end of the table.

(3) Least recently Used (Lru:least recently Used)

The least Recently used page replacement algorithm always chooses a page that has not been visited for the longest time now.

(4) Second Chance page replacement algorithm

FIFO algorithm may be a regular use of the page replacement out, in order to avoid this problem, the algorithm for simple modification: Check the oldest page R bit, if R bit is 0, then this page is old useless, can be replaced immediately, if it is 1, clear 0 R bit, and put the page to the end of the list, Modify its loading time so that it looks like it was loaded, and then continue searching. If all the pages have been accessed, the algorithm is reduced to a purely FIFO algorithm.

(5) clock page replacement algorithm

Because of the second chance page replacement algorithm to often move pages in the linked list, reducing the efficiency. A better way to put all the pages there is a ring-like table on the clock surface.

(6) Not recently Used (Nru:not recently Used)

A simple page replacement algorithm is constructed with r bits and M bits: When a process is started, the two bits of all its pages are set by the operating system to 0,r bit by regular zeroing to distinguish between recently accessed pages and visited pages.
According to R bit and M bit, divided into 4 kinds of pages
Class No. 0: No access, no modification
Class 1th, not being accessed, was modified
The 2nd class, which was accessed, had not been modified
The 3rd class, which was accessed, was modified.

The NRU algorithm randomly picks a page out of the least numbered Non-empty class. The implicit meaning of this algorithm is that eliminating a modified page that has not been accessed in the most recent clock cycle is better than eliminating a clean page that is frequently accessed.

abnormal phenomenon of belady

Intuitively, the more the number of physical pages in memory, the less the number of missing programs, but the actual situation is not the case.

Belady found a counter example in 1969, when using the FIFO algorithm, four page frames have more pages than three page frames. This strange situation is called the belady anomaly phenomenon . calculate the number of page faults

Title: A program in the deposit to allocate 3 pages , initially empty, the page to 4, 3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5. Calculates the number of page faults.

the number of missing pages in ideal permutation algorithm
Replaces the last occurrence of the page,

number of FIFO pages
Advanced to the page, go out first.

Least Recently used

Look at the top of the page direction, compared to the current number of pages far from the replacement.

Topic 2
In a request-page storage management, the page of a program is 3,4,2,1,4,5,4,3,5,1,2 and the LRU algorithm is used. The number of storage blocks allocated to the program is 3 and 4, and the number of page faults occurred in this visit is F.

S = 3,f = 8;

S = 4,f = 7.

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.