MySQL 9.1.0
Source Code Documentation
buf0flu.h File Reference

The database buffer pool flush algorithm. More...

#include "buf0types.h"
#include "log0types.h"
#include "univ.i"
#include "ut0byte.h"
#include "ut0cpu_cache.h"
#include "ut0link_buf.h"
#include <memory>
#include "buf0flu.ic"

Go to the source code of this file.

Classes

class  Flush_observer
 We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load.cc).Since we disable redo logging during a index build, we need to make sure that all dirty pages modified by the index build are flushed to disk before any redo logged operations go to the index. More...
 
class  Buf_flush_list_added_lsns
 Tracks the concurrent executions of adding dirty pages to the flush lists. More...
 

Typedefs

using Buf_flush_list_added_lsns_aligned_ptr = std::unique_ptr< Buf_flush_list_added_lsns, ut::detail::Aligned_deleter< Buf_flush_list_added_lsns > >
 

Functions

bool buf_flush_page_cleaner_is_active ()
 Checks if the page_cleaner is in active state. More...
 
void buf_flush_remove (buf_page_t *bpage)
 Remove a block from the flush list of modified blocks. More...
 
void buf_flush_relocate_on_flush_list (buf_page_t *bpage, buf_page_t *dpage)
 Relocates a buffer control block on the flush_list. More...
 
void buf_flush_write_complete (buf_page_t *bpage)
 Updates the flush system data structures when a write is completed. More...
 
bool page_is_uncompressed_type (const byte *page)
 Check if page type is uncompressed. More...
 
void buf_flush_init_for_writing (const buf_block_t *block, byte *page, void *page_zip_, lsn_t newest_lsn, bool skip_checksum, bool skip_lsn_check)
 Initialize a page for writing to the tablespace. More...
 
bool buf_flush_page_try (buf_pool_t *buf_pool, buf_block_t *block)
 Writes a flushable page asynchronously from the buffer pool to a file. More...
 
bool buf_flush_do_batch (buf_pool_t *buf_pool, buf_flush_t type, ulint min_n, lsn_t lsn_limit, ulint *n_processed)
 Do flushing batch of a given type. More...
 
bool buf_flush_lists (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. More...
 
bool buf_flush_single_page_from_LRU (buf_pool_t *buf_pool)
 This function picks up a single page from the tail of the LRU list, flushes it (if it is dirty), removes it from page_hash and LRU list and puts it on the free list. More...
 
void buf_flush_await_no_flushing (buf_pool_t *buf_pool, buf_flush_t flush_type)
 Waits until there's no flush of the given type from given BP instance. More...
 
static void buf_flush_note_modification (buf_block_t *block, lsn_t start_lsn, lsn_t end_lsn, Flush_observer *observer)
 This function should be called at a mini-transaction commit, if a page was modified in it. More...
 
static void buf_flush_recv_note_modification (buf_block_t *block, lsn_t start_lsn, lsn_t end_lsn)
 This function should be called when recovery has modified a buffer page. More...
 
bool buf_flush_ready_for_replace (const 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. More...
 
void buf_flush_page_cleaner_disabled_debug_update (THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
 Disables page cleaner threads (coordinator and workers). More...
 
void buf_flush_page_cleaner_init ()
 Initialize page_cleaner. More...
 
bool buf_flush_validate (buf_pool_t *buf_pool)
 Validates the flush list. More...
 
void buf_flush_init_flush_rbt (void)
 Initialize the red-black tree to speed up insertions into the flush_list during recovery process. More...
 
void buf_flush_free_flush_rbt (void)
 Frees up the red-black tree. More...
 
bool 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. More...
 
bool buf_flush_ready_for_flush (buf_page_t *bpage, buf_flush_t flush_type)
 Check if the block is modified and ready for flushing. More...
 
ulint buf_pool_get_dirty_pages_count (buf_pool_t *buf_pool, space_id_t id, Flush_observer *observer)
 Check if there are any dirty pages that belong to a space id in the flush list in a particular buffer pool. More...
 
void buf_flush_fsync ()
 Executes fsync for all tablespaces, to fsync all pages written to disk. More...
 
void buf_flush_sync_all_buf_pools ()
 Synchronously flush dirty blocks from the end of the flush list of all buffer pool instances. More...
 
bool buf_are_flush_lists_empty_validate ()
 Checks if all flush lists are empty. More...
 
lsn_t get_flush_sync_lsn () noexcept
 Get the lsn up to which data pages are to be synchronously flushed. More...
 

Variables

bool innodb_page_cleaner_disabled_debug
 Value of MySQL global variable used to disable page cleaner. More...
 
os_event_t buf_flush_event
 Event to synchronise with the flushing. More...
 
os_event_t buf_flush_tick_event
 Event to wait for one flushing step. More...
 
Buf_flush_list_added_lsns_aligned_ptr buf_flush_list_added
 Tracks adding dirty pages to the flush list. More...
 

Detailed Description

The database buffer pool flush algorithm.

Created 11/5/1995 Heikki Tuuri

Typedef Documentation

◆ Buf_flush_list_added_lsns_aligned_ptr

Function Documentation

◆ buf_are_flush_lists_empty_validate()

bool buf_are_flush_lists_empty_validate ( )

Checks if all flush lists are empty.

It is supposed to be used in single thread, during startup or shutdown. Hence it does not acquire lock and it is caller's responsibility to guarantee that flush lists are not changed in background.

Returns
true if all flush lists were empty.

◆ buf_flush_await_no_flushing()

void buf_flush_await_no_flushing ( buf_pool_t buf_pool,
buf_flush_t  flush_type 
)

Waits until there's no flush of the given type from given BP instance.

Note that in case of BUF_FLUSH_LIST and BUF_FLUSH_LRU we also make sure there's no ongoing batch initialization (which could lead to flushes). The BUF_FLUSH_SINGLE_PAGE does not have batch initialization. Note, that we return as soon as there is no flush, but in general a new one could start right after we've returned (it's up to the caller to prevent this). If buf_pool is nullptr, then it will await a moment with no flushes for each BP instance in turn, which in general doesn't imply there was a single moment when all instances were quiescent - it's up to the caller to ensure that.

Parameters
[in]buf_poolThe specific buffer pool instance to check. Can be null, if we want to wait for each buf_pool in turn.
[in]flush_typeFlush type.

◆ buf_flush_do_batch()

bool buf_flush_do_batch ( buf_pool_t buf_pool,
buf_flush_t  type,
ulint  min_n,
lsn_t  lsn_limit,
ulint n_processed 
)

Do flushing batch of a given type.

NOTE: The calling thread is not allowed to own any latches on pages!

Parameters
[in,out]buf_poolbuffer pool instance
[in]typeflush type
[in]min_nwished minimum number of blocks flushed (it is not guaranteed that the actual number is that big, though)
[in]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
[out]n_processedthe number of pages which were processed is passed back to caller. Ignored if NULL
Return values
trueif a batch was queued successfully.
falseif another batch of same type was already running.

◆ buf_flush_free_flush_rbt()

void buf_flush_free_flush_rbt ( void  )

Frees up the red-black tree.

◆ buf_flush_fsync()

void buf_flush_fsync ( )

Executes fsync for all tablespaces, to fsync all pages written to disk.

◆ buf_flush_init_flush_rbt()

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.

◆ buf_flush_init_for_writing()

void buf_flush_init_for_writing ( const buf_block_t block,
byte page,
void *  page_zip_,
lsn_t  newest_lsn,
bool  skip_checksum,
bool  skip_lsn_check 
)

Initialize a page for writing to the tablespace.

Parameters
[in]blockbuffer block; NULL if bypassing the buffer pool
[in,out]pagepage frame
[in,out]page_zip_compressed page, or NULL if uncompressed
[in]newest_lsnnewest modification LSN to the page
[in]skip_checksumwhether to disable the page checksum
[in]skip_lsn_checktrue to skip check for LSN (in DEBUG)

◆ buf_flush_lists()

bool buf_flush_lists ( 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!

Parameters
[in]min_nwished minimum number of blocks flushed (it is not guaranteed that the actual number is that big, though)
[in]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
[out]n_processedthe number of pages which were processed is passed back to caller. Ignored if NULL.
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

◆ buf_flush_note_modification()

static void buf_flush_note_modification ( buf_block_t block,
lsn_t  start_lsn,
lsn_t  end_lsn,
Flush_observer observer 
)
inlinestatic

This function should be called at a mini-transaction commit, if a page was modified in it.

Puts the block to the list of modified blocks, if it not already in it.

Parameters
[in]blockblock which is modified
[in]start_lsnstart lsn of the first mtr in a set of mtr's
[in]end_lsnend lsn of the last mtr in the set of mtr's
[in]observerflush observer

◆ buf_flush_page()

bool 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: 1. in simulated aio we must call os_aio_simulated_wake_handler_threads after we have posted a batch of writes! 2. buf_page_get_mutex(bpage) must be held upon entering this function. The LRU list mutex must be held if flush_type == BUF_FLUSH_SINGLE_PAGE. Both mutexes will be released by this function if it returns true.

Parameters
[in]buf_poolbuffer pool instance
[in]bpagebuffer control block
[in]flush_typetype of flush
[in]synctrue if sync IO request
Returns
true if page was flushed

◆ buf_flush_page_cleaner_disabled_debug_update()

void buf_flush_page_cleaner_disabled_debug_update ( THD thd,
SYS_VAR var,
void *  var_ptr,
const void *  save 
)

Disables page cleaner threads (coordinator and workers).

It's used by: SET GLOBAL innodb_page_cleaner_disabled_debug = 1 (0).

Parameters
[in]thdthread handle
[in]varpointer to system variable
[out]var_ptrwhere the formal string goes
[in]saveimmediate result from check function

◆ buf_flush_page_cleaner_init()

void buf_flush_page_cleaner_init ( )

Initialize page_cleaner.


◆ buf_flush_page_cleaner_is_active()

bool buf_flush_page_cleaner_is_active ( )

Checks if the page_cleaner is in active state.

Checks if the page_cleaner is in active state.

◆ buf_flush_page_try()

bool buf_flush_page_try ( buf_pool_t buf_pool,
buf_block_t block 
)

Writes a flushable page asynchronously from the buffer pool to a file.

NOTE: block and LRU list mutexes must be held upon entering this function, and they will be released by this function after flushing. This is loosely based on buf_flush_batch() and buf_flush_page().

Parameters
[in,out]buf_poolbuffer pool instance
[in,out]blockbuffer control block
Returns
true if the page was flushed and the mutex released

◆ buf_flush_ready_for_flush()

bool buf_flush_ready_for_flush ( buf_page_t bpage,
buf_flush_t  flush_type 
)

Check if the block is modified and ready for flushing.

Requires buf_page_get_mutex(bpage).

Parameters
[in]bpagebuffer control block, must be buf_page_in_file()
[in]flush_typetype of flush
Returns
true if can flush immediately

◆ buf_flush_ready_for_replace()

bool buf_flush_ready_for_replace ( const 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.

The caller must hold the LRU list and block mutexes.

Parameters
[in]bpagebuffer control block, must be buf_page_in_file() and in the LRU list
Returns
true if can replace immediately

◆ buf_flush_recv_note_modification()

static void buf_flush_recv_note_modification ( buf_block_t block,
lsn_t  start_lsn,
lsn_t  end_lsn 
)
inlinestatic

This function should be called when recovery has modified a buffer page.

Parameters
[in]blockblock which is modified
[in]start_lsnstart lsn of the first mtr in a set of mtr's
[in]end_lsnend lsn of the last mtr in the set of mtr's

◆ buf_flush_relocate_on_flush_list()

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 has already been copied to dpage. in/out: destination block

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

◆ buf_flush_remove()

void buf_flush_remove ( buf_page_t bpage)

Remove a block from the flush list of modified blocks.

Parameters
[in]bpagepointer to the block in question

◆ buf_flush_single_page_from_LRU()

bool buf_flush_single_page_from_LRU ( buf_pool_t buf_pool)

This function picks up a single page from the tail of the LRU list, flushes it (if it is dirty), 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.

Parameters
[in,out]buf_poolbuffer pool instance
Returns
true if success.

◆ buf_flush_sync_all_buf_pools()

void buf_flush_sync_all_buf_pools ( )

Synchronously flush 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!

◆ buf_flush_validate()

bool buf_flush_validate ( buf_pool_t buf_pool)

Validates the flush list.

Returns
true if ok

◆ buf_flush_write_complete()

void buf_flush_write_complete ( buf_page_t bpage)

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

Parameters
[in]bpagepointer to the block in question

◆ buf_pool_get_dirty_pages_count()

ulint buf_pool_get_dirty_pages_count ( buf_pool_t buf_pool,
space_id_t  id,
Flush_observer observer 
)

Check if there are any dirty pages that belong to a space id in the flush list in a particular buffer pool.

Returns
number of dirty pages present in a single buffer pool in: flush observer to check
number of dirty pages present in a single buffer pool
Parameters
buf_poolin: buffer pool
idin: space id to check
observerin: flush observer to check

◆ get_flush_sync_lsn()

lsn_t get_flush_sync_lsn ( )
noexcept

Get the lsn up to which data pages are to be synchronously flushed.

Returns
target lsn for the requested flush_sync

◆ page_is_uncompressed_type()

bool page_is_uncompressed_type ( const byte page)

Check if page type is uncompressed.

Parameters
[in]pagepage frame
Returns
true if uncompressed page type.

Variable Documentation

◆ buf_flush_event

os_event_t buf_flush_event
extern

Event to synchronise with the flushing.

◆ buf_flush_list_added

Buf_flush_list_added_lsns_aligned_ptr buf_flush_list_added
extern

Tracks adding dirty pages to the flush list.

The life cycle of this object is constraint to the life of buffer pool

◆ buf_flush_tick_event

os_event_t buf_flush_tick_event
extern

Event to wait for one flushing step.

◆ innodb_page_cleaner_disabled_debug

bool innodb_page_cleaner_disabled_debug
extern

Value of MySQL global variable used to disable page cleaner.