The number of pages in the network, FIFO, LRU, opt, three kinds of permutation algorithms

Source: Internet
Author: User

FIFO, LRU, opt the number of pages of the three permutation algorithmsreproduced
because to test the computer level four network, here encountered a problem, search some information to troubleshoot.

Consider the following page trends:

1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2 , 1, 2,3,6

When the number of memory blocks is 3 o'clock, ask FIFO,LRU,opt the three kinds of replacement algorithm of the number of pages ?

A: The page definition is that all memory blocks are initially empty, so the pages used for the first time are generated with a single fault.

When the number of memory blocks is 3 o'clock:

The number of fault pages interrupted is 16.

In the FIFO algorithm, the page that first enters the memory is swapped out first. When the page 6 to adjust, the state of the memory is 4,1,5, the page 6 before the page, 5, 1,2, 4 is visible, 4 is the first to enter the memory, this time should be swapped out, and then the page 6 into memory.

The number of fault pages interrupted is 15.

LRU is the acronym for Least recently used, which is the least recently used page replacement algorithm for virtual page Storage Management Services. The intent of this algorithm is to have memory management to be raised, the purpose is to solve "how to save the use of small capacity of memory for the most processes to provide resources" when how to reduce too much to let the process to read external memory.
Here the LRU is implemented as a linked list method:
A Little introduction
The operating system maintains a linked list for each process, and each node of the linked list records the address of a page. Once the page is called, the node of the page is removed from the chain and placed at the end of the chain; To load a new page, the page of the chain header is paged out, and the nodes of the page are generated and placed at the end of the chain.

In the LRU algorithm, the least recently used pages are first swapped out. When page 6 to adjust, the state of the memory is 5,2,1, the page 6 before the page, 5, 1, 2, See 2 for the most recent period of time use the least, this time should be swapped out, and then the page 6 into memory.

The number of fault pages interrupted is 11.

In the opt algorithm, pages that are visited in the farthest future are swapped out first. When page 6 is to be adjusted, the state of the memory is 1,2,5, the page after the page 6 to be paged in, 2, 1, 2 ,..., 5 for the most recent period of time the least used, this time should be swapped out, The page 6 is then paged into memory.

The least frequently Used (Least frequently used--LFU) page substitution algorithm requires that pages with the smallest reference count be displaced at page displacement, because pages that are used frequently should have a large number of references. However, some pages are used many times at the beginning, but are no longer used in the future, such pages will remain in memory for a long time, so you can shift the reference count register to the right by one bit, resulting in an exponential attenuation of the average number of uses.

Note the difference between LFU and LRU, LFU must be the least used and recently eliminated, and LRU is eliminated from the last time the longest use.


Opt algorithm because I want to know the page box behind the request, so I think this algorithm has a small bug, if in a request, if there is at least one page box after the requested page frame in a sequence of pages that do not match the current memory block, the order of the memory block (from top to bottom) replaces the page box that does not appear. Like the opt example above. For the last page box request, because 6 is missing, and 6 does not have the requested sequence, you should replace 3, so the replacement sequence is 6, 2, 1 of course, this is only for the purpose of the problem.

The following is the best page replacement algorithm:

Transfer from http://blog.csdn.net/tounaobun/article/details/8441493

The number of pages in the network, FIFO, LRU, opt, three kinds of permutation algorithms

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.