MySQL source code analysis (5): InnoDB Cache System

Source: Internet
Author: User

InnoDB Cache System
Buffer operation
Check whether the buffer pool has been cached Based on the Space ID and offset of the tbl_test file. If yes, directly read the page information and return the result;
If no cache is available, a blank page is allocated first, and then the data on the disk is read and loaded into the memory, and the result is returned.
When SQL-level commands are executed on the buffer layer of InnoDB, they correspond to the read/write operations on the buffer block on the buf_pool.
For example, enter the following query statement on the client:
Select * From tbl_test;
The following actions are generated when layer-by-layer Parsing is executed to the cache system:
Introduction to InnoDB Buffer Pool System

Buf_pool-> free, idle block linked list

Buf_pool-> flush_list, block linked list to be written

Buf_pool-> LRU, LRU block linked list

Buf_pool-> unzip_lru, unzipped LRU block linked list

Buf_pool-> zip_clean, clean compressed block linked list

Buf_pool-> zip_free [buf_buddy_size], idle compressed block linked list
Buf0buf. c is the core part of the buffer system and provides interfaces for Disk File interaction with memory. The entire buffer pool is organized mainly through these linked lists.
Buf0lru. C is used for cache replacement in the buffer system. Algorithm The main operation object is the LRU linked list, which aims to better use the cache.
Buf0flu. c is the part in the system that writes data to the disk. To save the system I/O overhead, InnoDB also considers dirty pages in the current system, loads of the current system, and other factors.
Buf0rea. c is the part of the system that reads data, including common read, pre-read, insert buffer, and recovery.
The buf0buddy. c binary partner allocation algorithm is used when allocating compressed memory blocks to avoid Memory fragments in the system.
In addition, mem0pool. C is included to process some underlying data.
Read operations (loading data from disk to memory)
When database files are not stored in a compressed format, InnoDB directly uses buf_lru_get_free_block to obtain an idle control block. When MySQL is configured with Compressed Storage, the system allocates a suitable size control block through the binary partner algorithm to prevent memory fragments. The main calling process is as follows:
Buf_page_get_gen is a major API encapsulated by the InnoDB cache system for external system calls. This function is used to obtain a page containing data and return it to the called function. Shows the call stack in actual use:

Write operation (delete page from buffer pool and flush to disk)
The entry function is buf_page_release, which is used to release pages in the buffer pool. This function marks dirty data in the flush queue.

There is a master thread (srv_master_thread) in InnoDB, which is mainly responsible for regularly writing data to disk files. The theoretical refresh frequency is 1 second or 10 seconds, for details, refer to the current server load and the ratio of dirty pages in the buffer pool for dynamic adjustment.CodeThe call process is as follows:

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.