LRU implementation in the MySQL cache pool _ MySQL

Source: Internet
Author: User
The implementation of LRU in the MySQL cache pool MySQL InnoDB engine is configured with indexes and data cache pools. the LRU algorithm is used to maintain the cache hit rate.

The sequence table list is used as the buffer pool. each data node is called a block.

This algorithm uses the dot-point insertion method: when a new block is inserted, it removes the least recently used block at the end of the table and inserts a new block at the midpoint.

The link list is divided into two parts:

1. a part near the header is located in the young Area. the block here is the recently used node.

2. a part close to the end of the table, which is in the old area. The block here is rarely used recently.

This algorithm maintains the location of each block by using the block usage heat in the linked list. the block in the old area is the candidate area removed when the linked list is full.

The specific algorithm is as follows:

1. the 3/8 of the linked list is set to the old area.

2. the midpoint is not the center point of the linked list, but the header node of the old area, that is, the node adjacent to the old and young areas.

3. when the read data is not in the buffer pool, the Read block needs to be inserted into the linked list. the insertion point is the midpoint, but the inserted new node is the old node, if the old area is full at this time, remove the block (LRU node) at the end of the table)

4. when the block in the old area is read, the node will become a "young" node: this node moves to the header of the young area (the header of the young area)

5. in database operations, the Accessed node will be removed to the young header. in this way, the unaccessed node in the young area will gradually move to the end of the table. when the node is moved over the midpoint, the node in the old area. If the nodes in the old area are accessed, the young node is moved to the header, while the accessed nodes in the old area are still moved to the end of the table. when the table is full, the block at the end of the table will be eliminated.

The code implementation is not involved here. I just briefly talk about the principle. I will post it after implementation.

Reprinted please indicate the source: http://www.cnblogs.com/iamsupercp/p/3682659.html thank you for your cooperation

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.