MySQL 9.1.0
Source Code Documentation
|
The database buffer buf_pool. More...
#include "my_config.h"
#include "btr0btr.h"
#include "buf0buf.h"
#include "fil0fil.h"
#include "fsp0sysspace.h"
#include "ha_prototypes.h"
#include "mem0mem.h"
#include "my_dbug.h"
#include "page0size.h"
#include "btr0sea.h"
#include "buf0buddy.h"
#include "buf0stats.h"
#include "dict0stats_bg.h"
#include "ibuf0ibuf.h"
#include "lock0lock.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "page0page.h"
#include "sync0rw.h"
#include "trx0purge.h"
#include "trx0undo.h"
#include <errno.h>
#include <stdarg.h>
#include <sys/types.h>
#include <time.h>
#include <map>
#include <new>
#include <sstream>
#include "buf0checksum.h"
#include "buf0dump.h"
#include "dict0dict.h"
#include "log0recv.h"
#include "os0thread-create.h"
#include "page0zip.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "sync0sync.h"
#include "ut0new.h"
#include "scope_guard.h"
#include "ut0stateful_latching_rules.h"
#include <numa.h>
#include <numaif.h>
Classes | |
struct | set_numa_interleave_t |
struct | Buf_fetch< T > |
This class implements the rules for fetching the pages from the buffer pool depending on the context. More... | |
struct | Buf_fetch_normal |
struct | Buf_fetch_other |
class | buf_page_t::Latching_rules_helpers |
The purpose of this class is to hide the knowledge that Buf_io_fix_latching_rules even exists from users of buf_page_t class, while also avoiding having to tediously repeat yourself in each place where buf_page_t's implementation needs to pass typical arguments to Buf_io_fix_latching_rules such as owned_latches or current state, which require access to private fields of buf_page_t. More... | |
Macros | |
#define | NUMA_MEMPOLICY_INTERLEAVE_IN_SCOPE set_numa_interleave_t scoped_numa |
#define | MONITOR_RW_COUNTER(io_type, counter) ((io_type == BUF_IO_READ) ? (counter##_READ) : (counter##_WRITTEN)) |
Macro to determine whether the read of write counter is used depending on the io_type. More... | |
Typedefs | |
typedef std::map< const byte *, buf_chunk_t *, std::less< const byte * >, ut::allocator< std::pair< const byte *const, buf_chunk_t * > > > | buf_pool_chunk_map_t |
Map of buffer pool chunks by its first frame address This is newly made by initialization of buffer pool and buf_resize_thread. More... | |
using | Buf_io_fix_latching_rules = ut::Stateful_latching_rules< buf_io_fix, 3 > |
Functions | |
static void | buf_pool_register_chunk (buf_chunk_t *chunk) |
Registers a chunk to buf_pool_chunk_map. More... | |
lsn_t | buf_pool_get_oldest_modification_approx (void) |
Gets the smallest oldest_modification lsn among all of the earliest added pages in flush lists. More... | |
lsn_t | buf_pool_get_oldest_modification_lwm (void) |
Gets a safe low watermark for oldest_modification. More... | |
void | buf_get_total_list_len (ulint *LRU_len, ulint *free_len, ulint *flush_list_len) |
Get total buffer pool statistics. More... | |
void | buf_get_total_list_size_in_bytes (buf_pools_list_size_t *buf_pools_list_size) |
Get total list size in bytes from all buffer pools. More... | |
void | buf_get_total_stat (buf_pool_stat_t *tot_stat) |
Get total buffer pool statistics. More... | |
buf_block_t * | buf_block_alloc (buf_pool_t *buf_pool) |
Allocates a buffer block. More... | |
void | buf_page_print (const byte *read_buf, const page_size_t &page_size, ulint flags) |
Prints a page to stderr. More... | |
static void | buf_block_init (buf_pool_t *buf_pool, buf_block_t *block, byte *frame) |
Initializes a buffer control block when the buf_pool is created. More... | |
void | buf_pool_update_madvise () |
Checks if innobase_should_madvise_buf_pool() value has changed since we've last check and if so, then updates buf_pool_should_madvise and calls madvise for all chunks in all srv_buf_pool_instances. More... | |
static buf_chunk_t * | buf_chunk_init (buf_pool_t *buf_pool, buf_chunk_t *chunk, ulonglong mem_size, std::mutex *mutex) |
Allocates a chunk of buffer frames. More... | |
static buf_block_t * | buf_chunk_contains_zip (buf_chunk_t *chunk, const void *data) |
Finds a block in the given buffer chunk that points to a given compressed page. More... | |
buf_block_t * | buf_pool_contains_zip (buf_pool_t *buf_pool, const void *data) |
Finds a block in the buffer pool that points to a given compressed page. More... | |
static void | buf_assert_all_are_replaceable (buf_chunk_t *chunk) |
Checks that all file pages in the buffer chunk are in a replaceable state. More... | |
static void | buf_pool_set_sizes (void) |
Set buffer pool size variables Note: It's safe without mutex protection because of startup only. More... | |
static void | buf_pool_create (buf_pool_t *buf_pool, ulint buf_pool_size, ulint instance_no, std::mutex *mutex, dberr_t &err) |
Initialize a buffer pool instance. More... | |
void | buf_page_free_descriptor (buf_page_t *bpage) |
Free a buf_page_t descriptor. More... | |
static void | buf_pool_free_instance (buf_pool_t *buf_pool) |
Free one buffer pool instance. More... | |
static void | buf_pool_free () |
Frees the buffer pool global data structures. More... | |
dberr_t | buf_pool_init (ulint total_size, ulint n_instances) |
Creates the buffer pool. More... | |
static bool | buf_page_realloc (buf_pool_t *buf_pool, buf_block_t *block) |
Reallocate a control block. More... | |
static void | buf_resize_status (buf_pool_resize_status_code_t status, const char *fmt,...) |
Sets the global variable that feeds MySQL's innodb_buffer_pool_resize_status to the specified string. More... | |
static void | buf_resize_status_progress_reset () |
Reset progress in current status code. More... | |
static void | buf_resize_status_progress_update (uint current_step, uint total_steps) |
Update progress in current status code. More... | |
void | buf_pool_resize_wait_for_test () |
bool | buf_block_will_withdrawn (buf_pool_t *buf_pool, const buf_block_t *block) |
Determines if a block is intended to be withdrawn. More... | |
bool | buf_frame_will_withdrawn (buf_pool_t *buf_pool, const byte *ptr) |
Determines if a frame is intended to be withdrawn. More... | |
static bool | buf_pool_withdraw_blocks (buf_pool_t *buf_pool) |
Withdraw the buffer pool blocks from end of the buffer pool instance until withdrawn by buf_pool->withdraw_target. More... | |
static void | buf_pool_resize_hash (buf_pool_t *buf_pool) |
resize page_hash and zip_hash for a buffer pool instance. More... | |
static void | buf_pool_resize_chunk_make_null (buf_chunk_t **new_chunks) |
This is a debug routine to inject an memory allocation failure error. More... | |
ulonglong | buf_pool_adjust_chunk_unit (ulonglong size) |
Adjust the proposed chunk unit size so that it satisfies all invariants. More... | |
static void | buf_pool_resize () |
Resize the buffer pool based on srv_buf_pool_size from srv_buf_pool_old_size. More... | |
void | buf_resize_thread () |
This is the thread for resizing buffer pool. More... | |
void | buf_pool_clear_hash_index (void) |
Clears the adaptive hash index on all pages in the buffer pool. More... | |
static void | buf_relocate (buf_page_t *bpage, buf_page_t *dpage) |
Relocate a buffer control block. More... | |
bool | buf_pool_watch_is_sentinel (const buf_pool_t *buf_pool, const buf_page_t *bpage) |
Determine if a block is a sentinel for a buffer pool watch. More... | |
static buf_page_t * | buf_pool_watch_set (const page_id_t &page_id, rw_lock_t **hash_lock) |
Add watch for the given page to be read in. More... | |
static void | buf_pool_watch_remove (buf_pool_t *buf_pool, buf_page_t *watch) |
Remove the sentinel block for the watch before replacing it with a real block. More... | |
void | buf_pool_watch_unset (const page_id_t &page_id) |
Stop watching if the page has been read in. More... | |
bool | buf_pool_watch_occurred (const page_id_t &page_id) |
Check if the page has been read in. More... | |
void | buf_page_make_young (buf_page_t *bpage) |
Moves a page to the start of the buffer pool LRU list. More... | |
void | buf_page_make_old (buf_page_t *bpage) |
Moved a page to the end of the buffer pool LRU list so that it can be flushed out at the earliest. More... | |
static void | buf_page_make_young_if_needed (buf_page_t *bpage) |
Moves a page to the start of the buffer pool LRU list if it is too old. More... | |
buf_page_t * | buf_page_set_file_page_was_freed (const page_id_t &page_id) |
Sets file_page_was_freed true if the page is found in the buffer pool. More... | |
buf_page_t * | buf_page_reset_file_page_was_freed (const page_id_t &page_id) |
Sets file_page_was_freed false if the page is found in the buffer pool. More... | |
static void | buf_block_try_discard_uncompressed (const page_id_t &page_id) |
Attempts to discard the uncompressed frame of a compressed page. More... | |
buf_page_t * | buf_page_get_zip (const page_id_t &page_id, const page_size_t &page_size) |
Get read access to a compressed page (usually of type FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2). More... | |
static void | buf_block_init_low (buf_block_t *block) |
Initialize some fields of a control block. More... | |
bool | buf_zip_decompress (buf_block_t *block, bool check) |
Decompress a block. More... | |
buf_block_t * | buf_block_from_ahi (const byte *ptr) |
Get a buffer block from an adaptive hash index pointer. More... | |
bool | buf_is_block_in_instance (const buf_pool_t *buf_pool, const buf_block_t *ptr) |
Find out if a block pointer points into one of currently used chunks of the buffer pool. More... | |
static bool | buf_debug_execute_is_force_flush () |
Return true if probe is enabled. More... | |
static void | buf_wait_for_read (buf_block_t *block) |
Wait for the block to be read in. More... | |
buf_block_t * | buf_page_get_gen (const page_id_t &page_id, const page_size_t &page_size, ulint rw_latch, buf_block_t *guess, Page_fetch mode, ut::Location location, mtr_t *mtr, bool dirty_with_no_latch) |
This is the general function used to get access to a database page. More... | |
bool | buf_page_optimistic_get (ulint rw_latch, buf_block_t *block, uint64_t modify_clock, Page_fetch fetch_mode, const char *file, ulint line, mtr_t *mtr) |
This is the general function used to get optimistic access to a database page. More... | |
bool | buf_page_get_known_nowait (ulint rw_latch, buf_block_t *block, Cache_hint hint, const char *file, ulint line, mtr_t *mtr) |
This is used to get access to a known database page, when no waiting can be done. More... | |
const buf_block_t * | buf_page_try_get (const page_id_t &page_id, ut::Location location, mtr_t *mtr) |
Given a tablespace id and page number tries to get that page. More... | |
static void | buf_page_init_low (buf_page_t *bpage) noexcept |
Initialize some fields of a control block. More... | |
static void | buf_page_init (buf_pool_t *buf_pool, const page_id_t &page_id, const page_size_t &page_size, buf_block_t *block) |
Inits a page to the buffer buf_pool. More... | |
buf_page_t * | buf_page_init_for_read (ulint mode, const page_id_t &page_id, const page_size_t &page_size, bool unzip) |
Inits a page for read to the buffer buf_pool. More... | |
buf_block_t * | buf_page_create (const page_id_t &page_id, const page_size_t &page_size, rw_lock_type_t rw_latch, mtr_t *mtr) |
Initializes a page to the buffer buf_pool. More... | |
static void | buf_page_monitor (const buf_page_t *bpage, enum buf_io_fix io_type) |
Monitor the buffer page read/write activity, and increment corresponding counter value if MONITOR_MODULE_BUF_PAGE (module_buf_page) module is enabled. More... | |
void | buf_read_page_handle_error (buf_page_t *bpage) |
Unfixes the page, unlatches the page, removes it from page_hash and removes it from LRU. More... | |
bool | buf_page_free_stale (buf_pool_t *buf_pool, buf_page_t *bpage) noexcept |
Free a stale page. More... | |
void | buf_page_force_evict (const page_id_t &page_id, const page_size_t &page_size, const bool dirty_is_ok) noexcept |
Evict a page from the buffer pool. More... | |
bool | buf_page_free_stale (buf_pool_t *buf_pool, buf_page_t *bpage, rw_lock_t *hash_lock) noexcept |
Free a stale page. More... | |
void | buf_page_free_stale_during_write (buf_page_t *bpage, bool owns_sx_lock) noexcept |
Free a stale page that is being written. More... | |
static std::ostream & | operator<< (std::ostream &outs, const buf_io_fix io_fix) |
Helper iostream operator presenting the io_fix value as human-readable name of the enum. More... | |
static bool | sync_read_page_verify_pageid (buf_page_t *bpage, IORequest *type, fil_node_t *node) |
Fetch the page from disk using synchronous read and verify if the page_id matches the page_id in the memory buffer block. More... | |
bool | buf_page_io_complete (buf_page_t *bpage, bool evict, IORequest *type, fil_node_t *node) |
Completes an asynchronous read or write request of a file page to or from the buffer pool. More... | |
static void | buf_assert_all_are_replaceable (buf_pool_t *buf_pool) |
Asserts that all file pages in the buffer are in a replaceable state. More... | |
static void | buf_refresh_io_stats (buf_pool_t *buf_pool) |
Refreshes the statistics used to print per-second averages. More... | |
static void | buf_pool_invalidate_instance (buf_pool_t *buf_pool) |
Invalidates file pages in one buffer pool instance. More... | |
void | buf_pool_invalidate (void) |
Invalidates the file pages in the buffer pool when an archive recovery is completed. More... | |
static void | buf_pool_validate_instance (buf_pool_t *buf_pool) |
Validates data in one buffer pool instance. More... | |
bool | buf_validate (void) |
Validates the buffer buf_pool data structure. More... | |
static void | buf_print_instance (buf_pool_t *buf_pool) |
Prints info of the buffer buf_pool data structure for one instance. More... | |
void | buf_print (void) |
Prints info of the buffer buf_pool data structure. More... | |
static ulint | buf_get_latched_pages_number_instance (buf_pool_t *buf_pool) |
Returns the number of latched pages in the buffer pool. More... | |
ulint | buf_get_latched_pages_number (void) |
Returns the number of latched pages in all the buffer pools. More... | |
ulint | buf_get_n_pending_read_ios (void) |
Returns the number of pending buf pool read ios. More... | |
double | buf_get_modified_ratio_pct (void) |
Returns the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool. More... | |
static void | buf_stats_aggregate_pool_info (buf_pool_info_t *total_info, const buf_pool_info_t *pool_info) |
Aggregates a pool stats information with the total buffer pool stats More... | |
void | buf_stats_get_pool_info (buf_pool_t *buf_pool, ulint pool_id, buf_pool_info_t *all_pool_info) |
Collect buffer pool stats information for a buffer pool. More... | |
static void | buf_print_io_instance (buf_pool_info_t *pool_info, FILE *file) |
Prints info of the buffer i/o. More... | |
void | buf_print_io (FILE *file) |
Prints info of the buffer i/o. More... | |
void | buf_refresh_io_stats_all () |
Refresh the statistics used to print per-second averages. More... | |
void | buf_assert_all_are_replaceable () |
Assert that all file pages in the buffer are in a replaceable state. More... | |
size_t | buf_pool_pending_io_reads_count () |
Computes number of pending I/O read operations for the buffer pool. More... | |
size_t | buf_pool_pending_io_writes_count () |
Computes number of pending I/O write operations for the buffer pool. More... | |
void | buf_pool_wait_for_no_pending_io () |
Waits until there are no pending I/O operations for the buffer pool. More... | |
std::ostream & | operator<< (std::ostream &out, const buf_pool_t &buf_pool) |
Print the given buf_pool_t object. More... | |
void | buf_pool_free_all () |
Frees the buffer pool instances and the global data structures. More... | |
bool | is_buffer_pool_resize_in_progress () |
Variables | |
constexpr std::chrono::microseconds | WAIT_FOR_READ {100} |
constexpr std::chrono::microseconds | WAIT_FOR_WRITE {100} |
static const ulint | BUF_PAGE_READ_MAX_RETRIES = 100 |
Number of attempts made to read in a page in the buffer pool. More... | |
static const ulint | BUF_READ_AHEAD_PAGES = 64 |
Number of pages to read ahead. More... | |
static const ulint | BUF_READ_AHEAD_PORTION = 32 |
The maximum portion of the buffer pool that can be used for the read-ahead buffer. More... | |
buf_pool_t * | buf_pool_ptr |
The buffer pools of the database. More... | |
volatile bool | buf_pool_resizing |
true when resizing buffer pool is in the critical path. More... | |
std::atomic_uint32_t | buf_pool_resize_status_code = {0} |
Atomic variables to track resize status code and progress. More... | |
std::atomic_uint32_t | buf_pool_resize_status_progress = {0} |
static buf_pool_chunk_map_t * | buf_chunk_map_reg |
buf_stat_per_index_t * | buf_stat_per_index |
Container for how many pages from each index are contained in the buffer pool(s). More... | |
Buf_flush_list_added_lsns_aligned_ptr | buf_flush_list_added |
Tracks adding dirty pages to the flush list. More... | |
static ulint | buf_dbg_counter = 0 |
This is used to insert validation operations in execution in the debug version. More... | |
bool | srv_buf_pool_debug |
This is used to enable multiple buffer pool instances with small buffer pool size. More... | |
static bool | buf_pool_should_madvise = false |
Buf_io_fix_latching_rules | buf_io_fix_latching_rules |
The database buffer buf_pool.
Created 11/5/1995 Heikki Tuuri
#define MONITOR_RW_COUNTER | ( | io_type, | |
counter | |||
) | ((io_type == BUF_IO_READ) ? (counter##_READ) : (counter##_WRITTEN)) |
Macro to determine whether the read of write counter is used depending on the io_type.
#define NUMA_MEMPOLICY_INTERLEAVE_IN_SCOPE set_numa_interleave_t scoped_numa |
typedef std::map<const byte *, buf_chunk_t *, std::less<const byte *>, ut::allocator<std::pair<const byte *const, buf_chunk_t *> > > buf_pool_chunk_map_t |
Map of buffer pool chunks by its first frame address This is newly made by initialization of buffer pool and buf_resize_thread.
Note: mutex protection is required when creating multiple buffer pools in parallel. We don't use a mutex during resize because that is still single threaded.
void buf_assert_all_are_replaceable | ( | ) |
Assert that all file pages in the buffer are in a replaceable state.
|
static |
Checks that all file pages in the buffer chunk are in a replaceable state.
[in] | chunk | The chunk to be checked |
|
static |
Asserts that all file pages in the buffer are in a replaceable state.
[in] | buf_pool | buffer pool instance |
buf_block_t * buf_block_alloc | ( | buf_pool_t * | buf_pool | ) |
Allocates a buffer block.
buf_pool | in/out: buffer pool instance, or NULL for round-robin selection of the buffer pool |
buf_block_t * buf_block_from_ahi | ( | const byte * | ptr | ) |
Get a buffer block from an adaptive hash index pointer.
This function does not return if the block is not identified.
[in] | ptr | pointer to within a page frame |
|
static |
Initializes a buffer control block when the buf_pool is created.
buf_pool | in: buffer pool instance |
block | in: pointer to control block |
frame | in: pointer to buffer frame |
|
inlinestatic |
Initialize some fields of a control block.
block | in: block to init |
|
static |
Attempts to discard the uncompressed frame of a compressed page.
The caller should not be holding any mutexes when this function is called.
[in] | page_id | page id |
bool buf_block_will_withdrawn | ( | buf_pool_t * | buf_pool, |
const buf_block_t * | block | ||
) |
Determines if a block is intended to be withdrawn.
The caller must ensure that there was a sufficient memory barrier to read curr_size and old_size.
[in] | buf_pool | buffer pool instance |
[in] | block | pointer to control block |
true | if will be withdrawn |
|
static |
Finds a block in the given buffer chunk that points to a given compressed page.
chunk | in: chunk being checked |
data | in: pointer to compressed page |
|
static |
Allocates a chunk of buffer frames.
If called for an existing buf_pool, its free_list_mutex must be locked.
buf_pool | in: buffer pool instance |
chunk | out: chunk of buffers |
mem_size | in: requested size in bytes |
mutex | in,out: Mutex protecting chunk map. |
|
static |
Return true if probe is enabled.
bool buf_frame_will_withdrawn | ( | buf_pool_t * | buf_pool, |
const byte * | ptr | ||
) |
Determines if a frame is intended to be withdrawn.
The caller must ensure that there was a sufficient memory barrier to read curr_size and old_size.
[in] | buf_pool | buffer pool instance |
[in] | ptr | pointer to a frame |
true | if will be withdrawn |
ulint buf_get_latched_pages_number | ( | void | ) |
Returns the number of latched pages in all the buffer pools.
Returns the number of latched pages in the buffer pool.
|
static |
Returns the number of latched pages in the buffer pool.
[in] | buf_pool | buffer pool instance |
double buf_get_modified_ratio_pct | ( | void | ) |
Returns the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool.
Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool.
ulint buf_get_n_pending_read_ios | ( | void | ) |
Returns the number of pending buf pool read ios.
Get total buffer pool statistics.
[out] | LRU_len | Length of all lru lists |
[out] | free_len | Length of all free lists |
[out] | flush_list_len | Length of all flush lists |
void buf_get_total_list_size_in_bytes | ( | buf_pools_list_size_t * | buf_pools_list_size | ) |
Get total list size in bytes from all buffer pools.
out: list sizes in all buffer pools
buf_pools_list_size | out: list sizes in all buffer pools |
void buf_get_total_stat | ( | buf_pool_stat_t * | tot_stat | ) |
Get total buffer pool statistics.
out: buffer pool stats
tot_stat | out: buffer pool stats |
bool buf_is_block_in_instance | ( | const buf_pool_t * | buf_pool, |
const buf_block_t * | ptr | ||
) |
Find out if a block pointer points into one of currently used chunks of the buffer pool.
This is useful if you stored the pointer some time ago, and want to dereference it now, and are afraid that buffer pool resize could free the memory pointed by it. Thus calling this function requires holding at least one of the latches which prevent freeing memory from buffer pool for the duration of the call and until you pin the block in some other way, as otherwise the result of this function might be obsolete by the time you dereference the block (an s-latch on buf_page_hash_lock_get for any hash cell is enough).
buf_pool | The buffer pool instance to search in. |
ptr | A pointer which you want to check. This function will not dereference it. |
block
points inside one of the chunks of the buf_pool
buf_block_t * buf_page_create | ( | const page_id_t & | page_id, |
const page_size_t & | page_size, | ||
rw_lock_type_t | rw_latch, | ||
mtr_t * | mtr | ||
) |
Initializes a page to the buffer buf_pool.
The page is usually not read from a file even if it cannot be found in the buffer buf_pool. This is one of the functions which perform to a block a state transition NOT_USED => FILE_PAGE (the other is buf_page_get_gen). The page is latched by passed mtr.
[in] | page_id | Page id |
[in] | page_size | Page size |
[in] | rw_latch | RW_SX_LATCH, RW_X_LATCH |
[in] | mtr | Mini-transaction |
|
noexcept |
Evict a page from the buffer pool.
[in] | page_id | page to be evicted. |
[in] | page_size | page size of the tablespace. |
[in] | dirty_is_ok | if true, it is OK for the page to be dirty. |
void buf_page_free_descriptor | ( | buf_page_t * | bpage | ) |
Free a buf_page_t descriptor.
[in] | bpage | bpage descriptor to free |
|
noexcept |
Free a stale page.
Caller must hold the LRU mutex. Upon successful page free the LRU mutex will be released.
[in,out] | buf_pool | Buffer pool the page belongs to. |
[in,out] | bpage | Page to free. |
|
noexcept |
Free a stale page.
Caller must be holding the hash_lock in S mode if hash_lock parameter is not nullptr. The hash lock will be released upon return always. Caller must hold the LRU mutex if and only if the hash_lock parameter is nullptr. Upon unsuccessful page free the LRU mutex will not be released if hash_lock is nullptr.
[in,out] | buf_pool | Buffer pool the page belongs to. |
[in,out] | bpage | Page to free. |
[in,out] | hash_lock | Hash lock covering the fetch from the hash table if latched in S mode. nullptr otherwise. |
|
noexcept |
Free a stale page that is being written.
The caller must be within the page's write code path.
[in,out] | bpage | Page to free. |
[in] | owns_sx_lock | SX lock on block->lock is set. |
buf_block_t * buf_page_get_gen | ( | const page_id_t & | page_id, |
const page_size_t & | page_size, | ||
ulint | rw_latch, | ||
buf_block_t * | guess, | ||
Page_fetch | mode, | ||
ut::Location | location, | ||
mtr_t * | mtr, | ||
bool | dirty_with_no_latch = false |
||
) |
This is the general function used to get access to a database page.
[in] | page_id | Page id |
[in] | page_size | Page size |
[in] | rw_latch | RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH |
[in] | guess | Guessed block or NULL |
[in] | mode | Fetch mode. |
[in] | location | Location from where this method was called. |
[in] | mtr | Mini-transaction |
[in] | dirty_with_no_latch | Mark page as dirty even if page is being pinned without any latch |
bool buf_page_get_known_nowait | ( | ulint | rw_latch, |
buf_block_t * | block, | ||
Cache_hint | hint, | ||
const char * | file, | ||
ulint | line, | ||
mtr_t * | mtr | ||
) |
This is used to get access to a known database page, when no waiting can be done.
[in] | rw_latch | RW_S_LATCH or RW_X_LATCH. |
[in] | block | The known page. |
[in] | hint | Cache_hint::MAKE_YOUNG or Cache_hint::KEEP_OLD |
[in] | file | File name from where it was called. |
[in] | line | Line from where it was called. |
[in,out] | mtr | Mini-transaction covering the fetch |
buf_page_t * buf_page_get_zip | ( | const page_id_t & | page_id, |
const page_size_t & | page_size | ||
) |
Get read access to a compressed page (usually of type FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
The page must be released with buf_page_release_zip(). NOTE: the page is not protected by any latch. Mutual exclusion has to be implemented at a higher level. In other words, all possible accesses to a given page through this function must be protected by the same set of mutexes or latches.
[in] | page_id | page id |
[in] | page_size | page size |
|
static |
Inits a page to the buffer buf_pool.
The block pointer must be private to the calling thread at the start of this function.
[in,out] | buf_pool | buffer pool |
[in] | page_id | page id |
[in] | page_size | page size |
[in,out] | block | block to init |
buf_page_t * buf_page_init_for_read | ( | ulint | mode, |
const page_id_t & | page_id, | ||
const page_size_t & | page_size, | ||
bool | unzip | ||
) |
Inits a page for read to the buffer buf_pool.
If the page is (1) already in buf_pool, or (2) if we specify to read only ibuf pages and the page is not an ibuf page, or (3) if the space is deleted or being deleted, then this function does nothing. Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock on the buffer frame. The io-handler must take care that the flag is cleared and the lock released later.
[in] | mode | BUF_READ_IBUF_PAGES_ONLY, ... |
[in] | page_id | page id |
[in] | page_size | page size |
[in] | unzip | true=request uncompressed page |
|
staticnoexcept |
Initialize some fields of a control block.
[in,out] | bpage | Block to initialize. |
bool buf_page_io_complete | ( | buf_page_t * | bpage, |
bool | evict, | ||
IORequest * | type = nullptr , |
||
fil_node_t * | node = nullptr |
||
) |
Completes an asynchronous read or write request of a file page to or from the buffer pool.
[in] | bpage | pointer to the block in question |
[in] | evict | whether or not to evict the page from LRU list |
[in] | type | i/o request type for which this completion routine is called. |
[in] | node | file node in which the disk copy of the page exists. |
void buf_page_make_old | ( | buf_page_t * | bpage | ) |
Moved a page to the end of the buffer pool LRU list so that it can be flushed out at the earliest.
[in] | bpage | buffer block of a file page |
void buf_page_make_young | ( | buf_page_t * | bpage | ) |
Moves a page to the start of the buffer pool LRU list.
This high-level function can be used to prevent an important page from slipping out of the buffer pool.
[in,out] | bpage | buffer block of a file page |
|
static |
Moves a page to the start of the buffer pool LRU list if it is too old.
This high-level function can be used to prevent an important page from slipping out of the buffer pool. The page must be fixed to the buffer pool.
[in,out] | bpage | buffer block of a file page |
|
static |
Monitor the buffer page read/write activity, and increment corresponding counter value if MONITOR_MODULE_BUF_PAGE (module_buf_page) module is enabled.
bpage | in: pointer to the block |
io_type | in: io_fix types |
bool buf_page_optimistic_get | ( | ulint | rw_latch, |
buf_block_t * | block, | ||
uint64_t | modify_clock, | ||
Page_fetch | fetch_mode, | ||
const char * | file, | ||
ulint | line, | ||
mtr_t * | mtr | ||
) |
This is the general function used to get optimistic access to a database page.
[in] | rw_latch | RW_S_LATCH, RW_X_LATCH |
[in,out] | block | Guessed block |
[in] | modify_clock | Modify clock value |
[in] | fetch_mode | Fetch mode |
[in] | file | File name |
[in] | line | Line where called |
[in,out] | mtr | Mini-transaction |
void buf_page_print | ( | const byte * | read_buf, |
const page_size_t & | page_size, | ||
ulint | flags | ||
) |
Prints a page to stderr.
[in] | read_buf | a database page |
[in] | page_size | page size |
[in] | flags | 0 or BUF_PAGE_PRINT_NO_CRASH or BUF_PAGE_PRINT_NO_FULL |
|
static |
Reallocate a control block.
[in] | buf_pool | buffer pool instance |
[in] | block | pointer to control block |
true | if succeeded or if failed because the block was fixed |
false | if failed because of no free blocks. |
buf_page_t * buf_page_reset_file_page_was_freed | ( | const page_id_t & | page_id | ) |
Sets file_page_was_freed false if the page is found in the buffer pool.
This function should be called when we free a file page and want the debug version to check that it is not accessed any more unless reallocated.
[in] | page_id | page id |
buf_page_t * buf_page_set_file_page_was_freed | ( | const page_id_t & | page_id | ) |
Sets file_page_was_freed true if the page is found in the buffer pool.
This function should be called when we free a file page and want the debug version to check that it is not accessed any more unless reallocated.
[in] | page_id | page id |
const buf_block_t * buf_page_try_get | ( | const page_id_t & | page_id, |
ut::Location | location, | ||
mtr_t * | mtr | ||
) |
Given a tablespace id and page number tries to get that page.
If the page is not in the buffer pool it is not loaded and NULL is returned. Suitable for using when holding the lock_sys latches (as it avoids deadlock).
[in] | page_id | page Id |
[in] | location | Location where called |
[in] | mtr | Mini-transaction |
Adjust the proposed chunk unit size so that it satisfies all invariants.
[in] | size | proposed size of buffer pool chunk unit in bytes |
void buf_pool_clear_hash_index | ( | void | ) |
Clears the adaptive hash index on all pages in the buffer pool.
buf_block_t * buf_pool_contains_zip | ( | buf_pool_t * | buf_pool, |
const void * | data | ||
) |
Finds a block in the buffer pool that points to a given compressed page.
Used only to confirm that buffer pool does not contain a given pointer, thus protected by zip_free_mutex.
[in] | buf_pool | buffer pool instance |
[in] | data | pointer to compressed page |
|
static |
Initialize a buffer pool instance.
[in] | buf_pool | buffer pool instance |
[in] | buf_pool_size | size in bytes |
[in] | instance_no | id of the instance |
[in,out] | mutex | Mutex to protect common data structures |
[out] | err | DB_SUCCESS if all goes well |
|
static |
Frees the buffer pool global data structures.
void buf_pool_free_all | ( | ) |
Frees the buffer pool instances and the global data structures.
Frees the buffer pool at shutdown.
|
static |
Free one buffer pool instance.
[in] | buf_pool | buffer pool instance to free |
lsn_t buf_pool_get_oldest_modification_approx | ( | void | ) |
Gets the smallest oldest_modification lsn among all of the earliest added pages in flush lists.
In other words - takes the last dirty page from each flush list, and calculates minimum oldest_modification among all of them. Does not acquire global lock for the whole process, so the result might come from inconsistent view on flush lists.
Returns zero if there were no dirty pages (flush lists were empty).
lsn_t buf_pool_get_oldest_modification_lwm | ( | void | ) |
Gets a safe low watermark for oldest_modification.
It's guaranteed that there were no dirty pages with smaller oldest_modification in the whole flush lists.
Returns zero if flush lists were empty, be careful in such case, because taking the newest lsn is probably not a good idea. If you wanted to rely on some lsn in such case, you would need to follow pattern:
dpa_lsn = buf_flush_list_added->smallest_not_added_lsn(); lwm_lsn = buf_pool_get_oldest_modification_lwm(); if (lwm_lsn == 0) lwm_lsn = dpa_lsn;
The order is important to avoid race conditions.
Creates the buffer pool.
[in] | total_size | Size of the total pool in bytes. |
[in] | n_instances | Number of buffer pool instances to create. |
void buf_pool_invalidate | ( | void | ) |
Invalidates the file pages in the buffer pool when an archive recovery is completed.
All the file pages buffered must be in a replaceable state when this function is called: not latched and not modified.
|
static |
Invalidates file pages in one buffer pool instance.
[in] | buf_pool | buffer pool instance |
size_t buf_pool_pending_io_reads_count | ( | ) |
Computes number of pending I/O read operations for the buffer pool.
size_t buf_pool_pending_io_writes_count | ( | ) |
Computes number of pending I/O write operations for the buffer pool.
|
static |
Registers a chunk to buf_pool_chunk_map.
[in] | chunk | chunk of buffers |
|
static |
Resize the buffer pool based on srv_buf_pool_size from srv_buf_pool_old_size.
|
static |
This is a debug routine to inject an memory allocation failure error.
|
static |
resize page_hash and zip_hash for a buffer pool instance.
[in] | buf_pool | buffer pool instance |
void buf_pool_resize_wait_for_test | ( | ) |
|
static |
Set buffer pool size variables Note: It's safe without mutex protection because of startup only.
void buf_pool_update_madvise | ( | ) |
Checks if innobase_should_madvise_buf_pool() value has changed since we've last check and if so, then updates buf_pool_should_madvise and calls madvise for all chunks in all srv_buf_pool_instances.
|
static |
Validates data in one buffer pool instance.
[in] | buf_pool | buffer pool instance |
void buf_pool_wait_for_no_pending_io | ( | ) |
Waits until there are no pending I/O operations for the buffer pool.
Keep waiting in loop with sleeps, emitting information every minute. This is used to avoid risk of some pending async IO (e.g. enqueued by the linear read-ahead), which would involve ibuf merge and create new redo records.
bool buf_pool_watch_is_sentinel | ( | const buf_pool_t * | buf_pool, |
const buf_page_t * | bpage | ||
) |
Determine if a block is a sentinel for a buffer pool watch.
[in] | buf_pool | buffer pool instance |
[in] | bpage | block |
bool buf_pool_watch_occurred | ( | const page_id_t & | page_id | ) |
Check if the page has been read in.
This may only be called after buf_pool_watch_set(same_page_id) has returned NULL and before invoking buf_pool_watch_unset(same_page_id).
[in] | page_id | page id |
|
static |
Remove the sentinel block for the watch before replacing it with a real block.
buf_page_watch_unset() or buf_page_watch_occurred() will notice that the block has been replaced with the real block.
[in,out] | buf_pool | buffer pool instance |
[in,out] | watch | sentinel for watch |
|
static |
Add watch for the given page to be read in.
Caller must have appropriate hash_lock for the bpage and hold the LRU list mutex to avoid a race condition with buf_LRU_free_page inserting the same page into the page hash. This function may release the hash_lock and reacquire it.
[in] | page_id | page id |
[in,out] | hash_lock | hash_lock currently latched |
void buf_pool_watch_unset | ( | const page_id_t & | page_id | ) |
Stop watching if the page has been read in.
buf_pool_watch_set(same_page_id) must have returned NULL before.
[in] | page_id | page id |
|
static |
Withdraw the buffer pool blocks from end of the buffer pool instance until withdrawn by buf_pool->withdraw_target.
[in] | buf_pool | buffer pool instance |
true | if retry is needed |
void buf_print | ( | void | ) |
Prints info of the buffer buf_pool data structure.
Prints info of the buffer pool data structure.
|
static |
Prints info of the buffer buf_pool data structure for one instance.
[in] | buf_pool | buffer pool instance |
void buf_print_io | ( | FILE * | file | ) |
Prints info of the buffer i/o.
in: file where to print
file | in/out: buffer where to print |
|
static |
Prints info of the buffer i/o.
pool_info | in: buffer pool info |
file | in/out: buffer where to print |
void buf_read_page_handle_error | ( | buf_page_t * | bpage | ) |
Unfixes the page, unlatches the page, removes it from page_hash and removes it from LRU.
[in,out] | bpage | pointer to the block |
|
static |
Refreshes the statistics used to print per-second averages.
[in,out] | buf_pool | buffer pool instance |
void buf_refresh_io_stats_all | ( | ) |
Refresh the statistics used to print per-second averages.
|
static |
Relocate a buffer control block.
Relocates the block on the LRU list and in buf_pool->page_hash. Does not relocate bpage->list. The caller must take care of relocating bpage->list.
[in,out] | bpage | control block being relocated, buf_page_get_state() must be BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE |
[in,out] | dpage | destination control block |
|
static |
Sets the global variable that feeds MySQL's innodb_buffer_pool_resize_status to the specified string.
The format and the following parameters are the same as the ones used for printf(3).
[in] | status | status code |
[in] | fmt | format |
[in] | ... | extra parameters according to fmt |
|
static |
Reset progress in current status code.
This indicates beginning of a new status code
|
static |
Update progress in current status code.
[in] | current_step | current step that is complete. |
[in] | total_steps | steps to complete before moving to next status code |
void buf_resize_thread | ( | ) |
This is the thread for resizing buffer pool.
It waits for an event and when waked up either performs a resizing and sleeps again.
|
static |
Aggregates a pool stats information with the total buffer pool stats
total_info | in/out: the buffer pool info to store aggregated result |
pool_info | in: individual buffer pool stats info |
void buf_stats_get_pool_info | ( | buf_pool_t * | buf_pool, |
ulint | pool_id, | ||
buf_pool_info_t * | all_pool_info | ||
) |
Collect buffer pool stats information for a buffer pool.
Also record aggregated stats if there are more than one buffer pool in the server
buf_pool | in: buffer pool |
pool_id | in: buffer pool ID |
all_pool_info | in/out: buffer pool info to fill |
bool buf_validate | ( | void | ) |
Validates the buffer buf_pool data structure.
Validates the buffer pool data structure.
|
static |
Wait for the block to be read in.
[in] | block | The block to check |
bool buf_zip_decompress | ( | buf_block_t * | block, |
bool | check | ||
) |
Decompress a block.
block | in/out: block |
check | in: true=verify the page checksum |
bool is_buffer_pool_resize_in_progress | ( | ) |
std::ostream & operator<< | ( | std::ostream & | out, |
const buf_pool_t & | buf_pool | ||
) |
Print the given buf_pool_t object.
[in,out] | out | the output stream |
[in] | buf_pool | the buf_pool_t object to be printed |
|
static |
Helper iostream operator presenting the io_fix value as human-readable name of the enum.
Used in error messages of Buf_io_fix_latching_rules.
[in] | outs | the output stream to which to print |
[in] | io_fix | the value to be printed |
|
static |
Fetch the page from disk using synchronous read and verify if the page_id matches the page_id in the memory buffer block.
[in] | bpage | the buffer block page |
[in] | type | i/o context object |
[in] | node | file where the page is available on disk. |
|
static |
|
static |
This is used to insert validation operations in execution in the debug version.
Buf_flush_list_added_lsns_aligned_ptr buf_flush_list_added |
Tracks adding dirty pages to the flush list.
The life cycle of this object is constraint to the life of buffer pool
Buf_io_fix_latching_rules buf_io_fix_latching_rules |
|
static |
Number of attempts made to read in a page in the buffer pool.
buf_pool_t* buf_pool_ptr |
The buffer pools of the database.
std::atomic_uint32_t buf_pool_resize_status_code = {0} |
Atomic variables to track resize status code and progress.
Buffer pool resize status code and progress are tracked using these atomic variables to ensure thread synchronization between innodb_buffer_pool_size_update (raising srv_buf_resize_event) and buf_resize_thread (handling srv_buf_resize_event)
std::atomic_uint32_t buf_pool_resize_status_progress = {0} |
volatile bool buf_pool_resizing |
true when resizing buffer pool is in the critical path.
|
static |
|
static |
Number of pages to read ahead.
|
static |
The maximum portion of the buffer pool that can be used for the read-ahead buffer.
(Divide buf_pool size by this amount)
buf_stat_per_index_t* buf_stat_per_index |
Container for how many pages from each index are contained in the buffer pool(s).
bool srv_buf_pool_debug |
This is used to enable multiple buffer pool instances with small buffer pool size.
|
constexpr |
|
constexpr |