About cache scheduling algorithm FIFO, LRU, opt the number of pages of three kinds of permutation algorithms

Source: Internet
Author: User

These three permutation algorithms, or cache scheduling algorithms, actually originate from the operating system. The page replacement algorithm for the operating system.
FIFO: The first out algorithm.
Lru:least recently used, the least recently used algorithm. That is, the least recently used object is kicked out of memory.
Opt:optimal, the best alternative, the god mode. It takes into account the current in-memory objects, as well as the objects that will be put into memory in the future, and then kicks out the memory for the pages that are visited in the furthest future. So, when the algorithm is converted, it needs to take into account the objects that will be put into memory in the future in order to find the object to be kicked out of memory.

Take a look at the detailed examples below to understand the specific strategy of the algorithm.

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 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.

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 the least used, 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, and then the page 6 into memory.

via:http://yinzhezq.blog.163.com/blog/static/1648628902010112961039187/


Other than that:
There are also algorithms:
Lfu:least frequently used, the least frequently used algorithm. It is based on the number of times the page has been used to select the least used pages. Notice the difference between it and LRU.

In addition, the OPT algorithm is often used to evaluate the quality of other replacement algorithms. cannot be achieved by itself.
via:http://wenda.tianya.cn/question/7885ae7b7cc29697

Some references:
In Java, the principle and application of LRU cache scheduling algorithm based on Linkedhashmap are implemented. Search, there are a bunch of articles:
such as: http://www.cnblogs.com/-OYK/archive/2012/12/04/2801799.html

There are also many algorithms based on LRU improvements, such as:
Http://www.cnblogs.com/cyjb/archive/2012/11/16/LruCache.html


Cache Hit Ratio

On the other hand, when you're going to write a caching algorithm yourself, or to use one, or to evaluate comparisons,
What we want to focus on is the cache hit ratio problem.

If you write one yourself, it's best to simulate some data, test how big the approximate hit rate is, and then compare it to the other algorithm's hit rate.


Reprint: HTTP://CHEN.JUNCHANG.BLOG.163.COM/BLOG/STATIC/6

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.