InnoDB Source Analysis--buffer pool (iii)

Source: Internet
Author: User

Reprint please attach original link: http://www.cnblogs.com/wingsless/p/5582063.html

Yesterday wrote the InnoDB buffer pool pre-read: "InnoDB source Analysis-buffer pool (ii)", and finally because of the anxious look at the European Cup, did not put the linear pre-reading, and then write today.

Linear pre-reading is implemented by this function: Buf_read_ahead_linear, as with random pre-reading, the first is to determine the area boundary, the page accessed within this boundary if a threshold value (Buf_read_ahead_linear_threshold) , the read-ahead operation is triggered. The algorithm of the boundary 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   /*   */ return  (0  ); }

Note that if offset is not on the boundary, it will not be pre-read, which is not the same as random read-ahead. Linear pre-reading is actually sequential read, if offset is in the low position, read the page in reverse order, if offset is in the high position, the positive sequence reads the page. Read each page, to be judged, if the number of visited pages reached the above threshold, to meet the linear pre-reading conditions, not to the threshold, no pre-read, the code is as follows:

Asc_or_desc =1;//default positive orderif(offset = =Low ) {Asc_or_desc= -1;//If offset is in low position, turn to reverse order} Fail_count=0;  for(i = low, i < high; i++) {Block=Buf_page_hash_get (space, I);//traversal of pages within a boundary rangeif(block = = NULL) | |!block->accessed) {            /*Not accessed*/Fail_count++;//Page count not read}Else if(Pred_block&& (UT_ULINT_CMP (block->lru_position, Pred_block-lru_position)!=Asc_or_desc)) {            /*accesses not on the right order*/Fail_count++; Pred_block=Block; }    }    if(Fail_count >Buf_read_ahead_linear_area-buf_read_ahead_linear_threshold) {//Do not meet pre-read conditions, exit/*Too many Failures:return*/Mutex_exit (& (buf_pool->mutex)); return(0); }

I've seen a word in a book before, presumably meaning that pages in memory are not physically contiguous, but logically contiguous. The linear pre-reading here requires that these pages also be physically contiguous:

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; Meet the conditions, continue}Else if(offset = = high-1) && (Pred_offset = = Offset-1)) { /*This is OK, we can continue*/New_offset=Succ_offset;//This is a positive order case, satisfies the condition}Else { /*successor or predecessor not on the right order*/ return(0); }

This place is the first to use the Fil_page_get_prev and Fil_page_get_next functions to read the Offset->frame or the previous 4 bytes, if the result satisfies the order condition, can proceed the linear pre-reading.

     for(i = low, i < high; i++) {        /*It is a sensible to does 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-reading or the use of the Buf_read_page_low function, which is the same as random pre-reading, and is asynchronous.

This completes the linear pre-reading.

Whether it is a random pre-reading or linear pre-reading, there are some conditions do not pre-read, such as the system pressure is not pre-read, this implementation:

    if (buf_pool->n_pend_reads        > Buf_pool->curr_size/ buf_read_ahead_pend_limit) {        mutex_ Exit (& (buf_pool->mutex));         return (0);    }

Here the pend reads more than buf_pool->curr_size half of the time, it is not pre-read, similar to a lot of conditions, all in the code, here do not write.

InnoDB Source Analysis--buffer pool (iii)

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.