MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
buf0flu.cc File Reference
#include "buf0flu.h"
#include "buf0buf.h"
#include "buf0checksum.h"
#include "srv0start.h"
#include "srv0srv.h"
#include "page0zip.h"
#include "ut0byte.h"
#include "ut0lst.h"
#include "page0page.h"
#include "fil0fil.h"
#include "buf0lru.h"
#include "buf0rea.h"
#include "ibuf0ibuf.h"
#include "log0log.h"
#include "os0file.h"
#include "trx0sys.h"
#include "srv0mon.h"
#include "mysql/plugin.h"
#include "mysql/service_thd_wait.h"
Include dependency graph for buf0flu.cc:

Go to the source code of this file.

Macros

#define PAGE_CLEANER_LRU_BATCH_CHUNK_SIZE   100
#define BUF_LRU_MIN_LEN   256

Functions

UNIV_INLINE void buf_flush_set_hp (buf_pool_t *buf_pool, const buf_page_t *bpage)
UNIV_INLINE bool buf_flush_is_hp (buf_pool_t *buf_pool, const buf_page_t *bpage)
UNIV_INLINE void buf_flush_update_hp (buf_pool_t *buf_pool, buf_page_t *bpage)
UNIV_INTERN void buf_flush_init_flush_rbt (void)
UNIV_INTERN void buf_flush_free_flush_rbt (void)
UNIV_INTERN void buf_flush_insert_into_flush_list (buf_pool_t *buf_pool, buf_block_t *block, lsn_t lsn)
UNIV_INTERN void buf_flush_insert_sorted_into_flush_list (buf_pool_t *buf_pool, buf_block_t *block, lsn_t lsn)
UNIV_INTERN ibool buf_flush_ready_for_replace (buf_page_t *bpage)
UNIV_INTERN bool buf_flush_ready_for_flush (buf_page_t *bpage, buf_flush_t flush_type)
UNIV_INTERN void buf_flush_remove (buf_page_t *bpage)
UNIV_INTERN void buf_flush_relocate_on_flush_list (buf_page_t *bpage, buf_page_t *dpage)
UNIV_INTERN void buf_flush_write_complete (buf_page_t *bpage)
UNIV_INTERN void buf_flush_update_zip_checksum (buf_frame_t *page, ulint zip_size, lsn_t lsn)
UNIV_INTERN void buf_flush_init_for_writing (byte *page, void *page_zip_, lsn_t newest_lsn)
UNIV_INTERN void buf_flush_page (buf_pool_t *buf_pool, buf_page_t *bpage, buf_flush_t flush_type, bool sync)
UNIV_INTERN void buf_flush_wait_batch_end (buf_pool_t *buf_pool, buf_flush_t type)
UNIV_INTERN bool buf_flush_list (ulint min_n, lsn_t lsn_limit, ulint *n_processed)
UNIV_INTERN ibool buf_flush_single_page_from_LRU (buf_pool_t *buf_pool)
UNIV_INTERN ulint buf_flush_LRU_tail (void)
UNIV_INTERN void buf_flush_wait_LRU_batch_end (void)
UNIV_INTERN os_thread_ret_t
DECLARE_THREAD() 
buf_flush_page_cleaner_thread (void *arg __attribute__((unused)))

Variables

UNIV_INTERN ibool buf_page_cleaner_is_active = FALSE

Detailed Description

The database buffer buf_pool flush algorithm

Created 11/11/1995 Heikki Tuuri

Definition in file buf0flu.cc.

Macro Definition Documentation

#define BUF_LRU_MIN_LEN   256
If LRU list of a buf_pool is less than this size then LRU eviction

should not happen. This is because when we do LRU flushing we also put the blocks on free list. If LRU list is very small then we can end up in thrashing.

Definition at line 74 of file buf0flu.cc.

#define PAGE_CLEANER_LRU_BATCH_CHUNK_SIZE   100
LRU flush batch is further divided into this chunk size to

reduce the wait time for the threads waiting for a clean block

Definition at line 64 of file buf0flu.cc.

Function Documentation

UNIV_INTERN void buf_flush_free_flush_rbt ( void  )

Frees up the red-black tree.

Definition at line 320 of file buf0flu.cc.

Here is the call graph for this function:

UNIV_INTERN void buf_flush_init_flush_rbt ( void  )

Initialize the red-black tree to speed up insertions into the flush_list during recovery process. Should be called at the start of recovery process before any page has been read/written.

Definition at line 296 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_init_for_writing ( byte *  page,
void *  page_zip_,
lsn_t  newest_lsn 
)

Initializes a page for writing to the tablespace.

Parameters
pagein/out: page
page_zip_in/out: compressed page, or NULL
newest_lsnin: newest modification lsn to the page

Definition at line 773 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_insert_into_flush_list ( buf_pool_t buf_pool,
buf_block_t block,
lsn_t  lsn 
)

Inserts a modified block into the flush list.

Parameters
buf_poolbuffer pool instance
blockin/out: block which is modified
lsnin: oldest modification

Definition at line 347 of file buf0flu.cc.

Here is the call graph for this function:

UNIV_INTERN void buf_flush_insert_sorted_into_flush_list ( buf_pool_t buf_pool,
buf_block_t block,
lsn_t  lsn 
)

Inserts a modified block into the flush list in the right sorted position. This function is used by recovery, because there the modifications do not necessarily come in the order of lsn's.

Parameters
buf_poolin: buffer pool instance
blockin/out: block which is modified
lsnin: oldest modification

Definition at line 403 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE bool buf_flush_is_hp ( buf_pool_t buf_pool,
const buf_page_t bpage 
)

Checks if the given block is a hazard pointer

Returns
true if bpage is hazard pointer
Parameters
buf_poolin: buffer pool instance
bpagein: buffer control block

Definition at line 156 of file buf0flu.cc.

Here is the caller graph for this function:

UNIV_INTERN bool buf_flush_list ( ulint  min_n,
lsn_t  lsn_limit,
ulint *  n_processed 
)

This utility flushes dirty blocks from the end of the flush list of all buffer pool instances. NOTE: The calling thread is not allowed to own any latches on pages!

Returns
true if a batch was queued successfully for each buffer pool instance. false if another batch of same type was already running in at least one of the buffer pool instance
Parameters
min_nin: wished minimum mumber of blocks flushed (it is not guaranteed that the actual number is that big, though)
lsn_limitin the case BUF_FLUSH_LIST all blocks whose oldest_modification is smaller than this should be flushed (if their number does not exceed min_n), otherwise ignored
n_processedout: the number of pages which were processed is passed back to caller. Ignored if NULL

Definition at line 1895 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ulint buf_flush_LRU_tail ( void  )

Clears up tail of the LRU lists: Put replaceable pages at the tail of LRU to the free list Flush dirty pages at the tail of LRU to the disk The depth to which we scan each buffer pool is controlled by dynamic config parameter innodb_LRU_scan_depth.

Returns
total pages flushed

Definition at line 2073 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_page ( buf_pool_t buf_pool,
buf_page_t bpage,
buf_flush_t  flush_type,
bool  sync 
)

Writes a flushable page asynchronously from the buffer pool to a file. NOTE: in simulated aio we must call os_aio_simulated_wake_handler_threads after we have posted a batch of writes! NOTE: buf_pool->mutex and buf_page_get_mutex(bpage) must be held upon entering this function, and they will be released by this function.

Parameters
buf_poolin: buffer pool instance
bpagein: buffer control block
flush_typein: type of flush
syncin: true if sync IO request

Definition at line 997 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN os_thread_ret_t DECLARE_THREAD() buf_flush_page_cleaner_thread ( void *arg   __attribute__(unused))

page_cleaner thread tasked with flushing dirty pages from the buffer pools. As of now we'll have only one instance of this thread.

Returns
a dummy parameter
Parameters
__attribute__in: a dummy parameter required by os_thread_create

Definition at line 2389 of file buf0flu.cc.

Here is the call graph for this function:

UNIV_INTERN bool buf_flush_ready_for_flush ( buf_page_t bpage,
buf_flush_t  flush_type 
)

Returns true if the block is modified and ready for flushing.

Returns
true if can flush immediately
Parameters
bpagein: buffer control block, must be buf_page_in_file(bpage)
flush_typein: type of flush

Definition at line 532 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ibool buf_flush_ready_for_replace ( buf_page_t bpage)

Returns TRUE if the file page block is immediately suitable for replacement, i.e., the transition FILE_PAGE => NOT_USED allowed.

Returns
TRUE if can replace immediately
Parameters
bpagein: buffer control block, must be buf_page_in_file(bpage) and in the LRU list

Definition at line 497 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_relocate_on_flush_list ( buf_page_t bpage,
buf_page_t dpage 
)

Relocates a buffer control block on the flush_list. Note that it is assumed that the contents of bpage have already been copied to dpage. IMPORTANT: When this function is called bpage and dpage are not exact copies of each other. For example, they both will have different ::state. Also the ::list pointers in dpage may be stale. We need to use the current list node (bpage) to do the list manipulation because the list pointers could have changed between the time that we copied the contents of bpage to the dpage and the flush list manipulation below.

Parameters
bpagein/out: control block being moved
dpagein/out: destination block

Definition at line 649 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_remove ( buf_page_t bpage)

Remove a block from the flush list of modified blocks.

Parameters
bpagein: pointer to the block in question

Definition at line 579 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE void buf_flush_set_hp ( buf_pool_t buf_pool,
const buf_page_t bpage 
)

Sets hazard pointer during flush_list iteration.

Parameters
buf_poolin/out: buffer pool instance
bpagein: buffer control block

Definition at line 137 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ibool buf_flush_single_page_from_LRU ( buf_pool_t buf_pool)

This function picks up a single dirty page from the tail of the LRU list, flushes it, removes it from page_hash and LRU list and puts it on the free list. It is called from user threads when they are unable to find a replaceable page at the tail of the LRU list i.e.: when the background LRU flushing in the page_cleaner thread is not fast enough to keep pace with the workload.

Returns
TRUE if success.
Parameters
buf_poolin/out: buffer pool instance

Definition at line 1982 of file buf0flu.cc.

Here is the call graph for this function:

UNIV_INLINE void buf_flush_update_hp ( buf_pool_t buf_pool,
buf_page_t bpage 
)

Whenever we move a block in flush_list (either to remove it or to relocate it) we check the hazard pointer set by some other thread doing the flush list scan. If the hazard pointer is the same as the one we are about going to move then we set it to NULL to force a rescan in the thread doing the batch.

Parameters
buf_poolin: buffer pool instance
bpagein: buffer control block

Definition at line 174 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_update_zip_checksum ( buf_frame_t page,
ulint  zip_size,
lsn_t  lsn 
)

Calculate the checksum of a page from compressed table and update the page.

Parameters
pagein/out: Page to update
zip_sizein: Compressed page size
lsnin: Lsn to stamp on the page

Definition at line 752 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_wait_batch_end ( buf_pool_t buf_pool,
buf_flush_t  type 
)

Waits until a flush batch of the given type ends

Parameters
buf_poolbuffer pool instance
typein: BUF_FLUSH_LRU or BUF_FLUSH_LIST

Definition at line 1817 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_wait_LRU_batch_end ( void  )

Wait for any possible LRU flushes that are in progress to end.

Definition at line 2138 of file buf0flu.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void buf_flush_write_complete ( buf_page_t bpage)

Updates the flush system data structures when a write is completed.

Parameters
bpagein: pointer to the block in question

Definition at line 719 of file buf0flu.cc.

Here is the call graph for this function:

Variable Documentation

UNIV_INTERN ibool buf_page_cleaner_is_active = FALSE
Flag indicating if the page_cleaner is in active state. This flag

is set to TRUE by the page_cleaner thread when it is spawned and is set back to FALSE at shutdown by the page_cleaner as well. Therefore no need to protect it by a mutex. It is only ever read by the thread doing the shutdown

Definition at line 60 of file buf0flu.cc.