InnoDB source code analysis-buffer pool (3), innodb source code-Buffer

Source: Internet
Author: User

InnoDB source code analysis-buffer pool (3), innodb source code-Buffer

Reprinted please link to the original article: http://www.cnblogs.com/wingsless/p/5582063.html

Yesterday I wrote the InnoDB buffer pool pre-read: "InnoDB source code analysis-buffer pool (ii)". Finally, I did not write the linear pre-read because I was in a hurry to watch the European Cup. I will continue writing it today.

Linear pre-read is implemented by this function: buf_read_ahead_linear. Like random pre-read, the first step is to determine the region boundary. If the accessed page within this boundary reaches a threshold (BUF_READ_AHEAD_LINEAR_THRESHOLD ), the pre-read operation is triggered. The boundary algorithm is determined by BUF_READ_AHEAD_LINEAR_AREA:

    low  = (offset / BUF_READ_AHEAD_LINEAR_AREA)        * BUF_READ_AHEAD_LINEAR_AREA;    high = (offset / BUF_READ_AHEAD_LINEAR_AREA + 1)        * BUF_READ_AHEAD_LINEAR_AREA;    if ((offset != low) && (offset != high - 1)) {        /* This is not a border page of the area: return */        return(0);    }

Note: If the offset is not on the boundary, no pre-read will be performed, which is different from the random pre-read. Linear pre-reading is actually sequential reading. If the offset is at the low position, the page is read in reverse order. If the offset is at the high position, the page is read in positive order. Each page to be read must be judged. If the number of accessed pages reaches the preceding threshold, the linear pre-read condition is met. If the threshold is not reached, pre-read is not performed, the Code is as follows:

Asc_or_desc = 1; // The default positive order if (offset = low) {asc_or_desc =-1; // if the offset is at the low position, it turns into a reverse order} fail_count = 0; for (I = low; I 

I have seen a sentence in a book before, which probably means that pages in the memory can be physically continuous but logically continuous. Linear pre-reading requires that these pages be physically consecutive:

Pred_offset = fil_page_get_prev (frame); succ_offset = fil_page_get_next (frame); mutex_exit (& (buf_pool-> mutex); if (offset = low) & (succ_offset = offset + 1) {/* This is OK, we can continue */
New_offset = pred_offset; // if the condition is met, continue} else if (offset = high-1) & (pred_offset = offset-1 )) {/* This is OK, we can continue */new_offset = succ_offset; // This is in the positive order, condition met} else {/* Successor or predecessor not in the right order */return (0 );}

This is the case. First, use the fil_page_get_prev and fil_page_get_next functions to read four bytes after the offset-> frame or before. If the results meet the sequence conditions, you can continue linear pre-read.

    for (i = low; i < high; i++) {        /* It is only sensible to do read-ahead in the non-sync        aio mode: hence FALSE as the first parameter */        if (!ibuf_bitmap_page(i)) {            count += buf_read_page_low(                &err, FALSE,                ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,                space, tablespace_version, i);            if (err == DB_TABLESPACE_DELETED) {                ut_print_timestamp(stderr);                fprintf(stderr,                    "  InnoDB: Warning: in"                    " linear readahead trying to access\n"                    "InnoDB: tablespace %lu page %lu,\n"                    "InnoDB: but the tablespace does not"                    " exist or is just being dropped.\n",                    (ulong) space, (ulong) i);            }        }    }

Linear pre-read still uses the buf_read_page_low function, which is the same as random pre-read and asynchronous.

Now linear pre-read is complete.

Whether it is random pre-read or linear pre-read, there are some conditions that do not pre-read. For example, when the system is under high pressure, this implementation:

    if (buf_pool->n_pend_reads        > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {        mutex_exit(&(buf_pool->mutex));        return(0);    }

It is stipulated that when pend reads more than half of buf_pool-> curr_size, it will not be pre-read. Similarly, there are many other conditions in the Code and it will not be written here.

Related Article

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.