3--fifo class of "turn" cache elimination algorithm series

Source: Internet
Author: User

Original address: http://www.360doc.com/content/13/0805/16/13247663_304923435.shtml

1 FIFO1.1. Principle

Retire data according to the principle of FIFO (first In,first out).

1.2. Implement

FIFO queue, specifically implemented as follows:

1. The newly accessed data is inserted into the tail of the FIFO queue and the data is moved sequentially in the FIFO queue;

2. Elimination of FIFO queue header data;

1.3. Analysis

L Hit ratio

The hit rate is low because the hit rate is too low to be used in practice.

L Degree of complexity

Simple

L Cost

The implementation cost is very small.

2. Second Chance2.1. Principle

The improved version of the FIFO algorithm, whose idea is to "give it a second chance (Second chance)" If the data has been accessed before being retired.

2.2. Implement

Each data is incremented by an access flag bit that identifies whether this data has been accessed again after it is placed in the cache queue.

For example, a is the oldest data in the FIFO queue and is not accessed again after it is placed in the queue, A is immediately retired, otherwise if it is accessed after the queue is placed, a is moved to the FIFO queue header and the access flag bit is cleared.

If all of the data has been accessed, the data will be phased out after a single loop followed by the FIFO principle.

2.3. Analysis

L Hit ratio

The hit ratio is higher than FIFO.

L Degree of complexity

Compared to FIFO, the access flag bits of the data need to be recorded and the data needs to be moved.

L Cost

The implementation cost is higher than FIFO.

3. Clock3.1. Principle

Clock is an improved version of Second chance, which avoids moving data in the FIFO queue through a ring queue.

3.2. Implement

For example, its specific implementation is as follows:

The current pointer is pointing to C, and if C is accessed, clear the access flag for C and point the pointer to D;

L if C has not been accessed, insert the new data into the position of C and point the pointer to D.

3.3. Analysis

L Hit ratio

The hit ratio is higher than FIFO and second chance.

L Degree of complexity

Compared to FIFO, the access flag bits of the data need to be recorded, and data pointers need to be moved.

L Cost

The implementation cost is higher than FIFO, lower than second chance.

4. FIFO class algorithm comparison

Contrast point

Contrast

Shooting

Clock = Second Chance > FIFO

Complexity of

Second chance > Clock > FIFO

Price

Second chance > Clock > FIFO

Because FIFO class algorithm hit ratio is much lower than other algorithms, this kind of algorithm is seldom used in practical applications.

3--fifo class of "turn" cache elimination algorithm series

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.