Innodb Buffer Pool Internal structure

Source: Internet
Author: User
Tags mutex

Innodb Buffer Pool Internal structure

1. Innodb Buffer function

The primary function of the INNODB buffer pool is to store the mirrored image of the external memory page in memory. There are 2 images of the image:

(1) Read-only mirroring: read-only mirror reads non-dirty pages.

(2) Update Image: Update image as dirty page in buffer pool.

InnoDB implements the row-level multi-version (MVCC) rather than the multiple versions of the entire page. Oracle has a third image in the implementation, which is version mirroring. And the InnoDB did not. The read and update of the dirty pages in any external memory in InnoDB is done in buffer pool.

2. INNODB Pool Data structure

The following major data structures are used in the entire module design of the InnoDB buffer pool:

(1) buf_page_t: External memory page in-memory storage structure, including compressed and uncompressed pages.

(2) buf_block_t: The page control structure exists in the InnoDB buffer pool, which controls the object that the page contains a memory structure such as mutexes. Each structure contains members of the buf_page_t. Each page in memory has a corresponding buf_block_t structure. When InnoDB starts at the specified innodb_buffer_pool_size, the value specified by the parameter is pre-calculated to calculate how many pages the current memory pool can store and the number of buf_block_t required per page to allocate memory to the structure. Every connection thread in MySQL who wants to access a page in the memory pool must obtain the buf_block_t mutex for the corresponding page.

(3) buf_chunk_t: This structure mainly contains an array of buf_block_t.

(4) The structure of the BUF_POOL_T:INNODB buffer pool, which contains hash table maintenance of compressed and uncompressed pages, maintenance of buf_chunk_t, and 3 lists of links. Free list, flush LRU list, LRU list, respectively. At the same time InnoDB buffer pool maintains a hash table that exists in memory, the hash table of the page present in the buffer pool. Each Innod buffer pool has a mutex to protect the memory structure.

3. Mapping of pages

Each page in the INNODB buffer pool loads the pages in the external memory into the memory pool according to the internal rules, using the space_id of each page, and the offset for the function operation. Each connection thread accesses a page with a function operation based on the page's Space ID and offset, which returns a pointer to a buffer pool, and finally finds it in the buffer pool of the specified buffer pool, which is obtained after the function operation. If it is found, direct access, if not found on the basis of the page's space ID and offset for the function of the buffer pool to be loaded, and finally through the IO operation to load the page into the specified buffer pool. For example, the current InnoDB buffer pool allocates 20G of memory, while the number of InnoDB buffer pools is 8, and if access to a page is no longer in the memory pool, the page is loaded from external memory to one of the 8 memory pools. If it exists in a memory pool, you only need to look for a hash table in a memory pool to see if the page exists. This will improve the efficiency of your search.

The above mentioned function that obtains a buffer pool instance based on space ID and Offsset is buf_pool_get, and the return value is buf_pool_t. The following is the prototype of the function:

/******************************************************************//**

Returns The buffer pool instance given space and offset of page

@return Buffer Pool */

Univ_inline

buf_pool_t*

Buf_pool_get (

/*==========*/

Ulint space,/*!< in:space ID */

Ulint offset)/*!< In:offset of the page within space */

4. Dump/restore of memory pools

MySQL adds a dump and restore of the buffer pool after the new version. Its main application scenario is that the MySQL server needs to be restarted, but does not affect the hot spot data at the time of the previous peak.

The dump of the INNODB buffer pool is a dump of the space ID of each page in memory and the combination of offset into external memory instead of dumping all the contents of the entire memory. The dump of the Buffer pool takes the following steps:

    1. Gets the mutex of the buffer pool.
    2. Traverse the LRU list in the pool, read the space ID of the page and offset, and deposit into the memory array.
    3. Releases the mutex in the buffer pool.
    4. Writes the contents of the array to a disk file.

Innodb Buffer Pool Internal structure

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.