MySQL 8.0.40
Source Code Documentation
buf0buf.h File Reference

The database buffer pool high-level routines. More...

#include "buf0types.h"
#include "fil0fil.h"
#include "hash0hash.h"
#include "mtr0types.h"
#include "os0proc.h"
#include "page0types.h"
#include "srv0shutdown.h"
#include "srv0srv.h"
#include "univ.i"
#include "ut0byte.h"
#include "ut0rbt.h"
#include "buf/buf.h"
#include <ostream>
#include "buf0buf.ic"

Go to the source code of this file.

Classes

struct  buf_pool_info_t
 This structure defines information we will fetch from each buffer pool. More...
 
struct  buf_pools_list_size_t
 The occupied bytes of lists in all buffer pools. More...
 
class  copyable_atomic_t< T >
 
class  buf_page_t
 
class  buf_page_t::io_responsibility_t
 
struct  btr_search_prefix_info_t
 Structure used by AHI to contain information on record prefixes to be considered in hash index subsystem. More...
 
struct  buf_block_t
 The buffer control block structure. More...
 
struct  buf_block_t::ahi_t
 Structure that holds most AHI-related fields. More...
 
class  HazardPointer
 A "Hazard Pointer" class used to iterate over page lists inside the buffer pool. More...
 
class  FlushHp
 Class implementing buf_pool->flush_list hazard pointer. More...
 
class  LRUHp
 Class implementing buf_pool->LRU hazard pointer. More...
 
class  LRUItr
 Special purpose iterators to be used when scanning the LRU list. More...
 
struct  buf_buddy_free_t
 Struct that is embedded in the free zip blocks. More...
 
struct  buf_pool_stat_t
 The buffer pool statistics structure. More...
 
struct  buf_buddy_stat_t
 Statistics of buddy blocks of a given size. More...
 
struct  buf_buddy_stat_t::snapshot_t
 
struct  buf_pool_t
 The buffer pool structure. More...
 
struct  CheckInLRUList
 Functor to validate the LRU list. More...
 
struct  CheckInFreeList
 Functor to validate the LRU list. More...
 
struct  CheckUnzipLRUAndLRUList
 

Macros

#define BUF_POOL_WATCH_SIZE   (srv_n_purge_threads + 1)
 Maximum number of concurrent buffer pool watches. More...
 

Typedefs

using buf_fix_count_atomic_t = copyable_atomic_t< uint32_t >
 

Enumerations

enum  buf_page_state : uint8_t {
  BUF_BLOCK_POOL_WATCH , BUF_BLOCK_ZIP_PAGE , BUF_BLOCK_ZIP_DIRTY , BUF_BLOCK_NOT_USED ,
  BUF_BLOCK_READY_FOR_USE , BUF_BLOCK_FILE_PAGE , BUF_BLOCK_MEMORY , BUF_BLOCK_REMOVE_HASH
}
 States of a control block. More...
 
enum  buf_page_print_flags { BUF_PAGE_PRINT_NO_CRASH = 1 , BUF_PAGE_PRINT_NO_FULL = 2 }
 
Modes for buf_page_get_gen
enum class  Page_fetch {
  NORMAL , SCAN , IF_IN_POOL , PEEK_IF_IN_POOL ,
  NO_LATCH , IF_IN_POOL_OR_WATCH , POSSIBLY_FREED
}
 
Modes for buf_page_get_known_nowait
enum class  Cache_hint { MAKE_YOUNG = 51 , KEEP_OLD = 52 }
 

Functions

dberr_t buf_pool_init (ulint total_size, ulint n_instances)
 Creates the buffer pool. More...
 
void buf_pool_free_all ()
 Frees the buffer pool at shutdown. More...
 
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...
 
void buf_resize_thread ()
 This is the thread for resizing buffer pool. 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...
 
void buf_pool_clear_hash_index (void)
 Clears the adaptive hash index on all pages in the buffer pool. More...
 
static ulint buf_pool_get_curr_size (void)
 Gets the current size of buffer buf_pool in bytes. More...
 
static ulint buf_pool_get_n_pages (void)
 Gets the current size of buffer buf_pool in frames. 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...
 
static buf_page_tbuf_page_alloc_descriptor (void)
 Allocates a buf_page_t descriptor. More...
 
void buf_page_free_descriptor (buf_page_t *bpage)
 Free a buf_page_t descriptor. More...
 
buf_block_tbuf_block_alloc (buf_pool_t *buf_pool)
 Allocates a buffer block. More...
 
static void buf_block_free (buf_block_t *block)
 Frees a buffer block which does not contain a file page. More...
 
static bytebuf_frame_copy (byte *buf, const buf_frame_t *frame)
 Copies contents of a buffer frame to a given buffer. 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_tbuf_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...
 
buf_page_tbuf_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...
 
buf_block_tbuf_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. More...
 
buf_block_tbuf_page_get (const page_id_t &id, const page_size_t &size, ulint latch, ut::Location location, mtr_t *mtr)
 NOTE! The following macros should be used instead of buf_page_get_gen, to improve debugging. More...
 
buf_block_tbuf_page_get_with_no_latch (const page_id_t &id, const page_size_t &size, ut::Location location, mtr_t *mtr)
 Use these macros to bufferfix a page with no latching. More...
 
buf_block_tbuf_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_release_zip (buf_page_t *bpage)
 Releases a compressed-only page acquired with buf_page_get_zip(). More...
 
static void buf_page_release_latch (buf_block_t *block, ulint rw_latch)
 Releases a latch, if specified. 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 bool buf_page_peek (const page_id_t &page_id)
 Returns true if the page can be found in the buffer pool hash table. More...
 
buf_page_tbuf_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_tbuf_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 ulint buf_page_get_freed_page_clock (const buf_page_t *bpage)
 Reads the freed_page_clock of a buffer block. More...
 
static ulint buf_block_get_freed_page_clock (const buf_block_t *block)
 Reads the freed_page_clock of a buffer block. More...
 
static bool buf_page_peek_if_young (const buf_page_t *bpage)
 Tells, for heuristics, if a block is still close enough to the MRU end of the LRU list meaning that it is not in danger of getting evicted and also implying that it has been accessed recently. More...
 
static bool buf_page_peek_if_too_old (const buf_page_t *bpage)
 Recommends a move of a block to the start of the LRU list if there is danger of dropping from the buffer pool. More...
 
static lsn_t buf_page_get_newest_modification (const buf_page_t *bpage)
 Gets the youngest modification log sequence number for a frame. More...
 
static void buf_block_modify_clock_inc (buf_block_t *block)
 Increment the modify clock. More...
 
static void buf_block_buf_fix_inc_func (ut::Location location, buf_block_t *block)
 Increments the bufferfix count. More...
 
static ulint buf_block_fix (buf_page_t *bpage)
 Increments the bufferfix count. More...
 
static ulint buf_block_fix (buf_block_t *block)
 Increments the bufferfix count. More...
 
static ulint buf_block_unfix (buf_page_t *bpage)
 Decrements the bufferfix count. More...
 
static ulint buf_block_unfix (buf_block_t *block)
 Decrements the bufferfix count. 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...
 
void buf_block_buf_fix_inc (buf_block_t *b, ut::Location l)
 Increments the bufferfix count. More...
 
static void buf_ptr_get_fsp_addr (const void *ptr, space_id_t *space, fil_addr_t *addr)
 Gets the space id, page offset, and byte offset within page of a pointer pointing to a buffer frame containing a file page. More...
 
buf_block_tbuf_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 buf_frame_tbuf_frame_align (byte *ptr)
 
bool buf_validate (void)
 Validates the buffer pool data structure. More...
 
void buf_print (void)
 Prints info of the buffer pool data structure. More...
 
void buf_page_print (const byte *read_buf, const page_size_t &page_size, ulint flags)
 Prints a page to stderr. More...
 
bool buf_zip_decompress (buf_block_t *block, bool check)
 Decompress a block. More...
 
ulint buf_get_latched_pages_number (void)
 Returns the number of latched pages in the buffer pool. More...
 
ulint buf_get_n_pending_read_ios (void)
 Returns the number of pending buf pool read ios. More...
 
void buf_print_io (FILE *file)
 Prints info of the buffer i/o. 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...
 
double buf_get_modified_ratio_pct (void)
 Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool. More...
 
void buf_refresh_io_stats_all ()
 Refresh the statistics used to print per-second averages. More...
 
void buf_must_be_all_freed (void)
 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...
 
void buf_pool_invalidate (void)
 Invalidates the file pages in the buffer pool when an archive recovery is completed. More...
 
static void buf_block_dbg_add_level (buf_block_t *block, latch_level_t level)
 Adds latch level info for the rw-lock protecting the buffer frame. More...
 
static enum buf_page_state buf_page_get_state (const buf_page_t *bpage)
 Gets the state of a block. More...
 
static enum buf_page_state buf_block_get_state (const buf_block_t *block)
 Gets the state of a block. More...
 
static void buf_page_set_state (buf_page_t *bpage, enum buf_page_state state)
 Sets the state of a block. More...
 
static void buf_block_set_state (buf_block_t *block, enum buf_page_state state)
 Sets the state of a block. More...
 
static bool buf_page_in_file (const buf_page_t *bpage)
 Determines if a block is mapped to a tablespace. More...
 
static bool buf_page_belongs_to_unzip_LRU (const buf_page_t *bpage)
 Determines if a block should be on unzip_LRU list. More...
 
static BPageMutexbuf_page_get_mutex (const buf_page_t *bpage)
 Gets the mutex of a block. More...
 
static buf_flush_t buf_page_get_flush_type (const buf_page_t *bpage)
 Get the flush type of a page. More...
 
static void buf_page_set_flush_type (buf_page_t *bpage, buf_flush_t flush_type)
 Set the flush type of a page. More...
 
static void buf_block_set_file_page (buf_block_t *block, const page_id_t &page_id)
 Map a block to a file page. More...
 
static enum buf_io_fix buf_page_get_io_fix (const buf_page_t *bpage)
 Gets the io_fix state of a block. More...
 
static enum buf_io_fix buf_block_get_io_fix (const buf_block_t *block)
 Gets the io_fix state of a block. More...
 
static void buf_page_set_io_fix (buf_page_t *bpage, enum buf_io_fix io_fix)
 Sets the io_fix state of a block. More...
 
static void buf_block_set_io_fix (buf_block_t *block, enum buf_io_fix io_fix)
 Sets the io_fix state of a block. More...
 
static void buf_page_set_sticky (buf_page_t *bpage)
 Makes a block sticky. More...
 
static void buf_page_unset_sticky (buf_page_t *bpage)
 Removes stickiness of a block. More...
 
static bool buf_page_can_relocate (const buf_page_t *bpage)
 Determine if a buffer block can be relocated in memory. More...
 
static bool buf_page_is_old (const buf_page_t *bpage)
 Determine if a block has been flagged old. More...
 
static void buf_page_set_old (buf_page_t *bpage, bool old)
 Flag a block old. More...
 
static std::chrono::steady_clock::time_point buf_page_is_accessed (const buf_page_t *bpage)
 Determine the time of first access of a block in the buffer pool. More...
 
static void buf_page_set_accessed (buf_page_t *bpage)
 Flag a block accessed. More...
 
static buf_block_tbuf_page_get_block (buf_page_t *bpage)
 Gets the buf_block_t handle of a buffered file block if an uncompressed page frame exists, or NULL. More...
 
static buf_frame_tbuf_block_get_frame (const buf_block_t *block)
 Gets a pointer to the memory frame of a block. More...
 
buf_block_tbuf_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...
 
buf_page_tbuf_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...
 
bool buf_page_io_complete (buf_page_t *bpage, bool evict)
 Completes an asynchronous read or write request of a file page to or from the buffer pool. More...
 
bool buf_page_free_stale (buf_pool_t *buf_pool, buf_page_t *bpage) noexcept
 Free a stale page. 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=false) noexcept
 Free a stale page that is being written. More...
 
static ulint buf_pool_index (const buf_pool_t *buf_pool)
 Calculates the index of a buffer pool to the buf_pool[] array. More...
 
static buf_pool_tbuf_pool_from_bpage (const buf_page_t *bpage)
 Returns the buffer pool instance given a page instance. More...
 
static buf_pool_tbuf_pool_from_block (const buf_block_t *block)
 Returns the buffer pool instance given a block instance. More...
 
static buf_pool_tbuf_pool_get (const page_id_t &page_id)
 Returns the buffer pool instance given a page id. More...
 
static buf_pool_tbuf_pool_from_array (ulint index)
 Returns the buffer pool instance given its array index. More...
 
static buf_page_tbuf_page_hash_get_low (buf_pool_t *buf_pool, const page_id_t &page_id)
 Returns the control block of a file page, NULL if not found. More...
 
static buf_page_tbuf_page_hash_get_locked (buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode, bool watch=false)
 Returns the control block of a file page, NULL if not found. More...
 
static buf_block_tbuf_block_hash_get_locked (buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode)
 Returns the control block of a file page, NULL if not found. More...
 
buf_page_tbuf_page_hash_get_s_locked (buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
 
buf_page_tbuf_page_hash_get_x_locked (buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
 
buf_page_tbuf_page_hash_get (buf_pool_t *b, const page_id_t &page_id)
 
buf_page_tbuf_page_get_also_watch (buf_pool_t *b, const page_id_t &page_id)
 
buf_block_tbuf_block_hash_get_s_locked (buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
 
buf_block_tbuf_block_hash_get_x_locked (buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
 
buf_block_tbuf_block_hash_get (buf_pool_t *b, const page_id_t &page_id)
 
ulint buf_get_free_list_len (void)
 Gets the current length of the free list of buffer blocks. 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...
 
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_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...
 
static buf_block_tbuf_get_nth_chunk_block (const buf_pool_t *buf_pool, ulint n, ulint *chunk_size)
 Get the nth chunk's buffer block in the specified buffer pool. More...
 
static ulint buf_pool_size_align (ulint size)
 Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit, if needed. More...
 
ulonglong buf_pool_adjust_chunk_unit (ulonglong size)
 Adjust the proposed chunk unit size so that it satisfies all invariants. More...
 
void buf_flush_update_zip_checksum (buf_frame_t *page, ulint size, lsn_t lsn, bool skip_lsn_check)
 Calculate the checksum of a page from compressed table and update the page. More...
 
static ulint buf_get_withdraw_depth (buf_pool_t *buf_pool)
 Return how many more pages must be added to the withdraw list to reach the withdraw target of the currently ongoing buffer pool resize. More...
 
bool buf_block_state_valid (buf_block_t *block)
 Check if a buf_block_t object is in a valid state. More...
 
std::ostream & operator<< (std::ostream &out, const buf_pool_t &buf_pool)
 Print the given buf_pool_t object. More...
 
void buf_page_prepare_for_free (buf_page_t *bpage) noexcept
 Prepare a page before adding to the free list. More...
 
page_zip_des_tbuf_block_get_page_zip (buf_block_t *block) noexcept
 Gets the compressed page descriptor corresponding to an uncompressed page if applicable. More...
 
const page_zip_des_tbuf_block_get_page_zip (const buf_block_t *block) noexcept
 Gets the compressed page descriptor corresponding to an uncompressed page if applicable. More...
 
void buf_block_reset_page_type_on_mismatch (buf_block_t &block, page_type_t type, mtr_t &mtr)
 Verify the page contained by the block. More...
 
static uint64_t buf_pool_hash_zip_frame (void *ptr)
 Compute the hash value for blocks in buf_pool->zip_hash. More...
 
static uint64_t buf_pool_hash_zip (buf_block_t *b)
 

Variables

constexpr ulint MAX_BUFFER_POOLS_BITS = 6
 Number of bits to representing a buffer pool ID. More...
 
constexpr ulint MAX_BUFFER_POOLS = (1 << MAX_BUFFER_POOLS_BITS)
 The maximum number of buffer pools that can be defined. More...
 
constexpr ulint MAX_PAGE_HASH_LOCKS = 1024
 The maximum number of page_hash locks. More...
 
buf_pool_tbuf_pool_ptr
 The buffer pools of the database. More...
 
constexpr uint32_t BUF_PAGE_STATE_BITS = 3
 The common buffer control block structure for compressed and uncompressed frames. More...
 

Accessors for buffer pool mutexes

Use these instead of accessing buffer pool mutexes directly.

#define buf_flush_list_mutex_own(b)   mutex_own(&(b)->flush_list_mutex)
 Test if flush list mutex is owned. More...
 
#define buf_flush_list_mutex_enter(b)
 Acquire the flush list mutex. More...
 
#define buf_flush_list_mutex_exit(b)
 Release the flush list mutex. More...
 
#define buf_page_mutex_enter(b)
 Acquire the block->mutex. More...
 
#define buf_page_mutex_exit(b)
 Release the block->mutex. More...
 
rw_lock_tbuf_page_hash_lock_get (const buf_pool_t *buf_pool, const page_id_t page_id)
 Get appropriate page_hash_lock. More...
 
rw_lock_tbuf_page_hash_lock_s_confirm (rw_lock_t *hash_lock, const buf_pool_t *buf_pool, const page_id_t page_id)
 If not appropriate page_hash_lock, relock until appropriate. More...
 
rw_lock_tbuf_page_hash_lock_x_confirm (rw_lock_t *hash_lock, buf_pool_t *buf_pool, const page_id_t &page_id)
 
ulint buf_page_hash_lock_held_s (const buf_pool_t *buf_pool, const buf_page_t *bpage)
 Test if page_hash lock is held in s-mode. More...
 
ulint buf_page_hash_lock_held_x (const buf_pool_t *buf_pool, const buf_page_t *bpage)
 Test if page_hash lock is held in x-mode. More...
 
bool buf_page_hash_lock_held_s_or_x (const buf_pool_t *buf_pool, const buf_page_t *bpage)
 Test if page_hash lock is held in x or s-mode. More...
 
bool buf_block_hash_lock_held_s (const buf_pool_t *buf_pool, const buf_block_t *block)
 
bool buf_block_hash_lock_held_x (const buf_pool_t *buf_pool, const buf_block_t *block)
 
bool buf_block_hash_lock_held_s_or_x (const buf_pool_t *buf_pool, const buf_block_t *block)
 

Detailed Description

The database buffer pool high-level routines.

Created 11/5/1995 Heikki Tuuri

Macro Definition Documentation

◆ buf_flush_list_mutex_enter

#define buf_flush_list_mutex_enter (   b)
Value:
do { \
mutex_enter(&(b)->flush_list_mutex); \
} while (0)

Acquire the flush list mutex.

◆ buf_flush_list_mutex_exit

#define buf_flush_list_mutex_exit (   b)
Value:
do { \
mutex_exit(&(b)->flush_list_mutex); \
} while (0)

Release the flush list mutex.

◆ buf_flush_list_mutex_own

#define buf_flush_list_mutex_own (   b)    mutex_own(&(b)->flush_list_mutex)

Test if flush list mutex is owned.

◆ buf_page_mutex_enter

#define buf_page_mutex_enter (   b)
Value:
do { \
mutex_enter(&(b)->mutex); \
} while (0)

Acquire the block->mutex.

◆ buf_page_mutex_exit

#define buf_page_mutex_exit (   b)
Value:
do { \
(b)->mutex.exit(); \
} while (0)

Release the block->mutex.

◆ BUF_POOL_WATCH_SIZE

#define BUF_POOL_WATCH_SIZE   (srv_n_purge_threads + 1)

Maximum number of concurrent buffer pool watches.

Typedef Documentation

◆ buf_fix_count_atomic_t

Enumeration Type Documentation

◆ buf_page_print_flags

Enumerator
BUF_PAGE_PRINT_NO_CRASH 

Do not crash at the end of buf_page_print().

BUF_PAGE_PRINT_NO_FULL 

Do not print the full page dump.

◆ buf_page_state

enum buf_page_state : uint8_t

States of a control block.

See also
buf_page_t

The enumeration values must be 0..7.

Enumerator
BUF_BLOCK_POOL_WATCH 

A sentinel for the buffer pool watch, element of buf_pool->watch[].

BUF_BLOCK_ZIP_PAGE 

Contains a clean compressed page.

BUF_BLOCK_ZIP_DIRTY 

Contains a compressed page that is in the buf_pool->flush_list.

BUF_BLOCK_NOT_USED 

Is in the free list; must be after the BUF_BLOCK_ZIP_ constants for compressed-only pages.

See also
buf_block_state_valid()
BUF_BLOCK_READY_FOR_USE 

When buf_LRU_get_free_block returns a block, it is in this state.

BUF_BLOCK_FILE_PAGE 

Contains a buffered file page.

BUF_BLOCK_MEMORY 

Contains some main memory object.

BUF_BLOCK_REMOVE_HASH 

Hash index should be removed before putting to the free list.

◆ Cache_hint

enum class Cache_hint
strong
Enumerator
MAKE_YOUNG 

Move the block to the start of the LRU list if there is a danger that the block would drift out of the buffer pool.

KEEP_OLD 

Preserve the current LRU position of the block.

◆ Page_fetch

enum class Page_fetch
strong
Enumerator
NORMAL 

Get always.

SCAN 

Same as NORMAL, but hint that the fetch is part of a large scan.

Try not to flood the buffer pool with pages that may not be accessed again any time soon.

IF_IN_POOL 

get if in pool

PEEK_IF_IN_POOL 

get if in pool, do not make the block young in the LRU list

NO_LATCH 

get and bufferfix, but set no latch; we have separated this case, because it is error-prone programming not to set a latch, and it should be used with care

IF_IN_POOL_OR_WATCH 

Get the page only if it's in the buffer pool, if not then set a watch on the page.

POSSIBLY_FREED 

Like Page_fetch::NORMAL, but do not mind if the file page has been freed.

Function Documentation

◆ buf_block_alloc()

buf_block_t * buf_block_alloc ( buf_pool_t buf_pool)

Allocates a buffer block.

Returns
own: the allocated block, in state BUF_BLOCK_MEMORY in: buffer pool instance, or NULL for round-robin selection of the buffer pool
own: the allocated block, in state BUF_BLOCK_MEMORY
Parameters
buf_poolin/out: buffer pool instance, or NULL for round-robin selection of the buffer pool

◆ buf_block_buf_fix_inc()

void buf_block_buf_fix_inc ( buf_block_t b,
ut::Location  l 
)
inline

Increments the bufferfix count.

Parameters
[in,out]bblock to bufferfix
[in]llocation where requested

◆ buf_block_buf_fix_inc_func()

static void buf_block_buf_fix_inc_func ( ut::Location  location,
buf_block_t block 
)
inlinestatic

Increments the bufferfix count.

Parameters
[in]locationlocation
[in,out]blockblock to bufferfix

◆ buf_block_dbg_add_level()

static void buf_block_dbg_add_level ( buf_block_t block,
latch_level_t  level 
)
inlinestatic

Adds latch level info for the rw-lock protecting the buffer frame.

This should be called in the debug version after a successful latching of a page if we know the latching order level of the acquired latch.

Parameters
[in]blockbuffer page where we have acquired latch
[in]levellatching order level

◆ buf_block_fix() [1/2]

static ulint buf_block_fix ( buf_block_t block)
inlinestatic

Increments the bufferfix count.

Parameters
[in,out]blockblock to bufferfix
Returns
the count

◆ buf_block_fix() [2/2]

static ulint buf_block_fix ( buf_page_t bpage)
inlinestatic

Increments the bufferfix count.

Parameters
[in,out]bpageblock to bufferfix
Returns
the count

◆ buf_block_free()

static void buf_block_free ( buf_block_t block)
inlinestatic

Frees a buffer block which does not contain a file page.

in, own: block to be freed

◆ buf_block_from_ahi()

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.

Parameters
[in]ptrpointer to within a page frame
Returns
pointer to block, never NULL

◆ buf_block_get_frame()

static buf_frame_t * buf_block_get_frame ( const buf_block_t block)
inlinestatic

Gets a pointer to the memory frame of a block.

Returns
pointer to the frame in: pointer to the control block

◆ buf_block_get_freed_page_clock()

static ulint buf_block_get_freed_page_clock ( const buf_block_t block)
inlinestatic

Reads the freed_page_clock of a buffer block.

Returns
freed_page_clock in: block

◆ buf_block_get_io_fix()

static enum buf_io_fix buf_block_get_io_fix ( const buf_block_t block)
inlinestatic

Gets the io_fix state of a block.

Returns
io_fix state in: pointer to the control block

◆ buf_block_get_page_zip() [1/2]

page_zip_des_t * buf_block_get_page_zip ( buf_block_t block)
inlinenoexcept

Gets the compressed page descriptor corresponding to an uncompressed page if applicable.

Parameters
[in]blockGet the zip descriptor for this block.

◆ buf_block_get_page_zip() [2/2]

const page_zip_des_t * buf_block_get_page_zip ( const buf_block_t block)
inlinenoexcept

Gets the compressed page descriptor corresponding to an uncompressed page if applicable.

Const version.

Parameters
[in]blockGet the zip descriptor for this block.
Returns
page descriptor or nullptr.

◆ buf_block_get_state()

static enum buf_page_state buf_block_get_state ( const buf_block_t block)
inlinestatic

Gets the state of a block.

Returns
state in: pointer to the control block

◆ buf_block_hash_get()

buf_block_t * buf_block_hash_get ( buf_pool_t b,
const page_id_t page_id 
)
inline

◆ buf_block_hash_get_locked()

static buf_block_t * buf_block_hash_get_locked ( buf_pool_t buf_pool,
const page_id_t page_id,
rw_lock_t **  lock,
ulint  lock_mode 
)
inlinestatic

Returns the control block of a file page, NULL if not found.

If the block is found and lock is not NULL then the appropriate page_hash lock is acquired in the specified lock mode. Otherwise, mode value is ignored. It is up to the caller to release the lock. If the block is found and the lock is NULL then the page_hash lock is released by this function.

Parameters
[in]buf_poolbuffer pool instance
[in]page_idpage id
[in,out]locklock of the page hash acquired if bpage is found, NULL otherwise. If NULL is passed then the hash_lock is released by this function.
[in]lock_modeRW_LOCK_X or RW_LOCK_S. Ignored if lock == NULL
Returns
pointer to the block or NULL; if NULL, lock is also NULL.

◆ buf_block_hash_get_s_locked()

buf_block_t * buf_block_hash_get_s_locked ( buf_pool_t b,
const page_id_t page_id,
rw_lock_t **  l 
)
inline

◆ buf_block_hash_get_x_locked()

buf_block_t * buf_block_hash_get_x_locked ( buf_pool_t b,
const page_id_t page_id,
rw_lock_t **  l 
)
inline

◆ buf_block_hash_lock_held_s()

bool buf_block_hash_lock_held_s ( const buf_pool_t buf_pool,
const buf_block_t block 
)
inline

◆ buf_block_hash_lock_held_s_or_x()

bool buf_block_hash_lock_held_s_or_x ( const buf_pool_t buf_pool,
const buf_block_t block 
)
inline

◆ buf_block_hash_lock_held_x()

bool buf_block_hash_lock_held_x ( const buf_pool_t buf_pool,
const buf_block_t block 
)
inline

◆ buf_block_modify_clock_inc()

static void buf_block_modify_clock_inc ( buf_block_t block)
inlinestatic

Increment the modify clock.

The caller must (1) own the buf_pool->mutex and block bufferfix count has to be zero, (2) own X or SX latch on the block->lock, or (3) operate on a thread-private temporary table

Parameters
[in,out]blockbuffer block

◆ buf_block_reset_page_type_on_mismatch()

void buf_block_reset_page_type_on_mismatch ( buf_block_t block,
page_type_t  type,
mtr_t mtr 
)
inline

Verify the page contained by the block.

If there is page type mismatch then reset it to expected page type. Data files created before MySQL 5.7 GA may contain garbage in the FIL_PAGE_TYPE field.

Parameters
[in,out]blockblock that may possibly have invalid FIL_PAGE_TYPE
[in]typeExpected page type
[in,out]mtrMini-transaction

◆ buf_block_set_file_page()

static void buf_block_set_file_page ( buf_block_t block,
const page_id_t page_id 
)
inlinestatic

Map a block to a file page.

Parameters
[in,out]blockpointer to control block
[in]page_idpage id

◆ buf_block_set_io_fix()

static void buf_block_set_io_fix ( buf_block_t block,
enum buf_io_fix  io_fix 
)
inlinestatic

Sets the io_fix state of a block.

Parameters
[in,out]blockcontrol block
[in]io_fixio_fix state

◆ buf_block_set_state()

static void buf_block_set_state ( buf_block_t block,
enum buf_page_state  state 
)
inlinestatic

Sets the state of a block.

Parameters
[in,out]blockpointer to control block
[in]statestate

◆ buf_block_state_valid()

bool buf_block_state_valid ( buf_block_t block)
inline

Check if a buf_block_t object is in a valid state.

Parameters
blockbuffer block
Returns
true if valid

◆ buf_block_unfix() [1/2]

static ulint buf_block_unfix ( buf_block_t block)
inlinestatic

Decrements the bufferfix count.

Parameters
[in,out]blockblock to bufferunfix
Returns
the remaining buffer-fix count

◆ buf_block_unfix() [2/2]

static ulint buf_block_unfix ( buf_page_t bpage)
inlinestatic

Decrements the bufferfix count.

Parameters
[in,out]bpageblock to bufferunfix
Returns
the remaining buffer-fix count

◆ buf_block_will_withdrawn()

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.

Parameters
[in]buf_poolbuffer pool instance
[in]blockpointer to control block
Return values
trueif will be withdrawn

◆ buf_flush_update_zip_checksum()

void buf_flush_update_zip_checksum ( buf_frame_t page,
ulint  size,
lsn_t  lsn,
bool  skip_lsn_check 
)

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

Parameters
[in,out]pagepage to update
[in]sizecompressed page size
[in]lsnLSN to stamp on the page
[in]skip_lsn_checktrue to skip check for lsn (in DEBUG)

◆ buf_frame_align()

static buf_frame_t * buf_frame_align ( byte ptr)
inlinestatic

◆ buf_frame_copy()

static byte * buf_frame_copy ( byte buf,
const buf_frame_t frame 
)
inlinestatic

Copies contents of a buffer frame to a given buffer.

Parameters
[in]bufbuffer to copy to
[in]framebuffer frame
Returns
buf

◆ buf_frame_will_withdrawn()

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.

Parameters
[in]buf_poolbuffer pool instance
[in]ptrpointer to a frame
Return values
trueif will be withdrawn

◆ buf_get_free_list_len()

ulint buf_get_free_list_len ( void  )

Gets the current length of the free list of buffer blocks.

Returns
length of the free list

◆ buf_get_latched_pages_number()

ulint buf_get_latched_pages_number ( void  )

Returns the number of latched pages in the buffer pool.

Returns
number of latched pages

Returns the number of latched pages in the buffer pool.

Returns
number of latched pages

◆ buf_get_modified_ratio_pct()

double buf_get_modified_ratio_pct ( void  )

Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool.

Returns
modified page percentage ratio

Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool.

Returns
modified page percentage ratio

◆ buf_get_n_pending_read_ios()

ulint buf_get_n_pending_read_ios ( void  )

Returns the number of pending buf pool read ios.

Returns
number of pending read I/O operations

◆ buf_get_nth_chunk_block()

static buf_block_t * buf_get_nth_chunk_block ( const buf_pool_t buf_pool,
ulint  n,
ulint chunk_size 
)
inlinestatic

Get the nth chunk's buffer block in the specified buffer pool.

Parameters
[in]buf_poolbuffer pool instance
[in]nnth chunk in the buffer pool
[in]chunk_sizechunk_size
Returns
the nth chunk's buffer block.

◆ buf_get_total_list_len()

void buf_get_total_list_len ( ulint LRU_len,
ulint free_len,
ulint flush_list_len 
)

Get total buffer pool statistics.

Parameters
[out]LRU_lenLength of all lru lists
[out]free_lenLength of all free lists
[out]flush_list_lenLength of all flush lists

◆ buf_get_total_list_size_in_bytes()

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

Parameters
buf_pools_list_sizeout: list sizes in all buffer pools

◆ buf_get_total_stat()

void buf_get_total_stat ( buf_pool_stat_t tot_stat)

Get total buffer pool statistics.

out: buffer pool stats

Parameters
tot_statout: buffer pool stats

◆ buf_get_withdraw_depth()

static ulint buf_get_withdraw_depth ( buf_pool_t buf_pool)
inlinestatic

Return how many more pages must be added to the withdraw list to reach the withdraw target of the currently ongoing buffer pool resize.

Parameters
[in]buf_poolbuffer pool instance
Returns
page count to be withdrawn or zero if the target is already achieved or if the buffer pool is not currently being resized.

◆ buf_is_block_in_instance()

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).

Parameters
buf_poolThe buffer pool instance to search in.
ptrA pointer which you want to check. This function will not dereference it.
Returns
true iff block points inside one of the chunks of the buf_pool

◆ buf_must_be_all_freed()

void buf_must_be_all_freed ( void  )

Assert that all file pages in the buffer are in a replaceable state.

Assert that all file pages in the buffer are in a replaceable state.

◆ buf_page_alloc_descriptor()

static buf_page_t * buf_page_alloc_descriptor ( void  )
inlinestatic

Allocates a buf_page_t descriptor.

This function must succeed. In case of failure we assert in this function.

◆ buf_page_belongs_to_unzip_LRU()

static bool buf_page_belongs_to_unzip_LRU ( const buf_page_t bpage)
inlinestatic

Determines if a block should be on unzip_LRU list.

Returns
true if block belongs to unzip_LRU in: pointer to control block

◆ buf_page_can_relocate()

static bool buf_page_can_relocate ( const buf_page_t bpage)
inlinestatic

Determine if a buffer block can be relocated in memory.

The block can be dirty, but it must not be I/O-fixed or bufferfixed. control block being relocated

◆ buf_page_create()

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.

Parameters
[in]page_idPage id
[in]page_sizePage size
[in]rw_latchRW_SX_LATCH, RW_X_LATCH
[in]mtrMini-transaction
Returns
pointer to the block, page bufferfixed

◆ buf_page_free_descriptor()

void buf_page_free_descriptor ( buf_page_t bpage)

Free a buf_page_t descriptor.

Parameters
[in]bpagebpage descriptor to free

◆ buf_page_free_stale() [1/2]

bool buf_page_free_stale ( buf_pool_t buf_pool,
buf_page_t bpage 
)
noexcept

Free a stale page.

Caller must hold the LRU mutex. Upon successful page free the LRU mutex will be released.

Parameters
[in,out]buf_poolBuffer pool the page belongs to.
[in,out]bpagePage to free.
Returns
true if page was freed.

◆ buf_page_free_stale() [2/2]

bool buf_page_free_stale ( buf_pool_t buf_pool,
buf_page_t bpage,
rw_lock_t hash_lock 
)
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.

Parameters
[in,out]buf_poolBuffer pool the page belongs to.
[in,out]bpagePage to free.
[in,out]hash_lockHash lock covering the fetch from the hash table if latched in S mode. nullptr otherwise.
Returns
true if page was freed.

◆ buf_page_free_stale_during_write()

void buf_page_free_stale_during_write ( buf_page_t bpage,
bool  owns_sx_lock = false 
)
noexcept

Free a stale page that is being written.

The caller must be within the page's write code path.

Parameters
[in,out]bpagePage to free.
[in]owns_sx_lockSX lock on block->lock is set.

◆ buf_page_get()

buf_block_t * buf_page_get ( const page_id_t id,
const page_size_t size,
ulint  latch,
ut::Location  location,
mtr_t mtr 
)
inline

NOTE! The following macros should be used instead of buf_page_get_gen, to improve debugging.

Only values RW_S_LATCH and RW_X_LATCH are allowed in LA!

◆ buf_page_get_also_watch()

buf_page_t * buf_page_get_also_watch ( buf_pool_t b,
const page_id_t page_id 
)
inline

◆ buf_page_get_block()

static buf_block_t * buf_page_get_block ( buf_page_t bpage)
inlinestatic

Gets the buf_block_t handle of a buffered file block if an uncompressed page frame exists, or NULL.

page frame exists, or NULL. The caller must hold either the appropriate hash lock in any mode, either the LRU list mutex. Note: even though bpage is not declared a const we don't update its value. It is safe to make this pure.

Parameters
[in]bpagecontrol block, or NULL
Returns
control block, or NULL

◆ buf_page_get_flush_type()

static buf_flush_t buf_page_get_flush_type ( const buf_page_t bpage)
inlinestatic

Get the flush type of a page.

Returns
flush type in: buffer page

◆ buf_page_get_freed_page_clock()

static ulint buf_page_get_freed_page_clock ( const buf_page_t bpage)
inlinestatic

Reads the freed_page_clock of a buffer block.

Returns
freed_page_clock in: block

◆ buf_page_get_gen()

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.

Parameters
[in]page_idPage id
[in]page_sizePage size
[in]rw_latchRW_S_LATCH, RW_X_LATCH, RW_NO_LATCH
[in]guessGuessed block or NULL
[in]modeFetch mode.
[in]locationLocation from where this method was called.
[in]mtrMini-transaction
[in]dirty_with_no_latchMark page as dirty even if page is being pinned without any latch
Returns
pointer to the block or NULL

◆ buf_page_get_io_fix()

static enum buf_io_fix buf_page_get_io_fix ( const buf_page_t bpage)
inlinestatic

Gets the io_fix state of a block.

Returns
io_fix state in: pointer to the control block

◆ buf_page_get_known_nowait()

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.

Parameters
[in]rw_latchRW_S_LATCH or RW_X_LATCH.
[in]blockThe known page.
[in]hintCache_hint::MAKE_YOUNG or Cache_hint::KEEP_OLD
[in]fileFile name from where it was called.
[in]lineLine from where it was called.
[in,out]mtrMini-transaction covering the fetch
Returns
true if success

◆ buf_page_get_mutex()

static BPageMutex * buf_page_get_mutex ( const buf_page_t bpage)
inlinestatic

Gets the mutex of a block.

Returns
pointer to mutex protecting bpage in: pointer to control block

◆ buf_page_get_newest_modification()

static lsn_t buf_page_get_newest_modification ( const buf_page_t bpage)
inlinestatic

Gets the youngest modification log sequence number for a frame.

Returns zero if not file page or no modification occurred yet.

Returns
newest modification to page in: block containing the page frame

◆ buf_page_get_state()

static enum buf_page_state buf_page_get_state ( const buf_page_t bpage)
inlinestatic

Gets the state of a block.

Returns
state in: pointer to the control block

◆ buf_page_get_with_no_latch()

buf_block_t * buf_page_get_with_no_latch ( const page_id_t id,
const page_size_t size,
ut::Location  location,
mtr_t mtr 
)
inline

Use these macros to bufferfix a page with no latching.

Remember not to read the contents of the page unless you know it is safe. Do not modify the contents of the page! We have separated this case, because it is error-prone programming not to set a latch, and it should be used with care.

◆ buf_page_get_zip()

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.

Parameters
[in]page_idpage id
[in]page_sizepage size
Returns
pointer to the block

◆ buf_page_hash_get()

buf_page_t * buf_page_hash_get ( buf_pool_t b,
const page_id_t page_id 
)
inline

◆ buf_page_hash_get_locked()

static buf_page_t * buf_page_hash_get_locked ( buf_pool_t buf_pool,
const page_id_t page_id,
rw_lock_t **  lock,
ulint  lock_mode,
bool  watch = false 
)
inlinestatic

Returns the control block of a file page, NULL if not found.

If the block is found and lock is not NULL then the appropriate page_hash lock is acquired in the specified lock mode. Otherwise, mode value is ignored. It is up to the caller to release the lock. If the block is found and the lock is NULL then the page_hash lock is released by this function.

Parameters
[in]buf_poolbuffer pool instance
[in]page_idpage id
[in,out]locklock of the page hash acquired if bpage is found, NULL otherwise. If NULL is passed then the hash_lock is released by this function.
[in]lock_modeRW_LOCK_X or RW_LOCK_S. Ignored if lock == NULL
[in]watchif true, return watch sentinel also.
Returns
pointer to the bpage or NULL; if NULL, lock is also NULL or a watch sentinel.

◆ buf_page_hash_get_low()

static buf_page_t * buf_page_hash_get_low ( buf_pool_t buf_pool,
const page_id_t page_id 
)
inlinestatic

Returns the control block of a file page, NULL if not found.

Parameters
[in]buf_poolbuffer pool instance
[in]page_idpage id
Returns
block, NULL if not found

◆ buf_page_hash_get_s_locked()

buf_page_t * buf_page_hash_get_s_locked ( buf_pool_t b,
const page_id_t page_id,
rw_lock_t **  l 
)
inline

◆ buf_page_hash_get_x_locked()

buf_page_t * buf_page_hash_get_x_locked ( buf_pool_t b,
const page_id_t page_id,
rw_lock_t **  l 
)
inline

◆ buf_page_hash_lock_get()

rw_lock_t * buf_page_hash_lock_get ( const buf_pool_t buf_pool,
const page_id_t  page_id 
)
inline

Get appropriate page_hash_lock.

◆ buf_page_hash_lock_held_s()

ulint buf_page_hash_lock_held_s ( const buf_pool_t buf_pool,
const buf_page_t bpage 
)
inline

Test if page_hash lock is held in s-mode.

◆ buf_page_hash_lock_held_s_or_x()

bool buf_page_hash_lock_held_s_or_x ( const buf_pool_t buf_pool,
const buf_page_t bpage 
)
inline

Test if page_hash lock is held in x or s-mode.

◆ buf_page_hash_lock_held_x()

ulint buf_page_hash_lock_held_x ( const buf_pool_t buf_pool,
const buf_page_t bpage 
)
inline

Test if page_hash lock is held in x-mode.

◆ buf_page_hash_lock_s_confirm()

rw_lock_t * buf_page_hash_lock_s_confirm ( rw_lock_t hash_lock,
const buf_pool_t buf_pool,
const page_id_t  page_id 
)
inline

If not appropriate page_hash_lock, relock until appropriate.

◆ buf_page_hash_lock_x_confirm()

rw_lock_t * buf_page_hash_lock_x_confirm ( rw_lock_t hash_lock,
buf_pool_t buf_pool,
const page_id_t page_id 
)
inline

◆ buf_page_in_file()

static bool buf_page_in_file ( const buf_page_t bpage)
inlinestatic

Determines if a block is mapped to a tablespace.

Returns
true if mapped in: pointer to control block

◆ buf_page_init_for_read()

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.

Parameters
[in]modeBUF_READ_IBUF_PAGES_ONLY, ...
[in]page_idpage id
[in]page_sizepage size
[in]unziptrue=request uncompressed page
Returns
pointer to the block or NULL

◆ buf_page_io_complete()

bool buf_page_io_complete ( buf_page_t bpage,
bool  evict 
)

Completes an asynchronous read or write request of a file page to or from the buffer pool.

Parameters
[in]bpagepointer to the block in question
[in]evictwhether or not to evict the page from LRU list
Returns
true if successful

◆ buf_page_is_accessed()

static std::chrono::steady_clock::time_point buf_page_is_accessed ( const buf_page_t bpage)
inlinestatic

Determine the time of first access of a block in the buffer pool.

Returns
Time of first access, zero if not accessed in: control block

◆ buf_page_is_old()

static bool buf_page_is_old ( const buf_page_t bpage)
inlinestatic

Determine if a block has been flagged old.

Parameters
[in]bpagecontrol block
Returns
true if old

◆ buf_page_make_old()

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.

Parameters
[in]bpagebuffer block of a file page

◆ buf_page_make_young()

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.

Parameters
[in,out]bpagebuffer block of a file page

◆ buf_page_optimistic_get()

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.

Parameters
[in]rw_latchRW_S_LATCH, RW_X_LATCH
[in,out]blockGuessed block
[in]modify_clockModify clock value
[in]fetch_modeFetch mode
[in]fileFile name
[in]lineLine where called
[in,out]mtrMini-transaction
Returns
true if success

◆ buf_page_peek()

static bool buf_page_peek ( const page_id_t page_id)
inlinestatic

Returns true if the page can be found in the buffer pool hash table.

NOTE that it is possible that the page is not yet read from disk, though.

Parameters
[in]page_idpage id
Returns
true if found in the page hash table

◆ buf_page_peek_if_too_old()

static bool buf_page_peek_if_too_old ( const buf_page_t bpage)
inlinestatic

Recommends a move of a block to the start of the LRU list if there is danger of dropping from the buffer pool.

NOTE: does not reserve the LRU list mutex.

Parameters
[in]bpageblock to make younger
Returns
true if should be made younger

◆ buf_page_peek_if_young()

static bool buf_page_peek_if_young ( const buf_page_t bpage)
inlinestatic

Tells, for heuristics, if a block is still close enough to the MRU end of the LRU list meaning that it is not in danger of getting evicted and also implying that it has been accessed recently.

The page must be either buffer-fixed, either its page hash must be locked.

Parameters
[in]bpageblock
Returns
true if block is close to MRU end of LRU

◆ buf_page_prepare_for_free()

void buf_page_prepare_for_free ( buf_page_t bpage)
inlinenoexcept

Prepare a page before adding to the free list.

Parameters
[in,out]bpageBuffer page to prepare for freeing.

◆ buf_page_print()

void buf_page_print ( const byte read_buf,
const page_size_t page_size,
ulint  flags 
)

Prints a page to stderr.

Parameters
[in]read_bufa database page
[in]page_sizepage size
[in]flags0 or BUF_PAGE_PRINT_NO_CRASH or BUF_PAGE_PRINT_NO_FULL

◆ buf_page_release_latch()

static void buf_page_release_latch ( buf_block_t block,
ulint  rw_latch 
)
inlinestatic

Releases a latch, if specified.

Parameters
[in]blockbuffer block
[in]rw_latchRW_S_LATCH, RW_X_LATCH, RW_NO_LATCH

◆ buf_page_release_zip()

static void buf_page_release_zip ( buf_page_t bpage)
inlinestatic

Releases a compressed-only page acquired with buf_page_get_zip().

in: buffer block

◆ buf_page_reset_file_page_was_freed()

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.

Parameters
[in]page_idpage id
Returns
control block if found in page hash table, otherwise NULL

◆ buf_page_set_accessed()

static void buf_page_set_accessed ( buf_page_t bpage)
inlinestatic

Flag a block accessed.

in/out: control block

◆ buf_page_set_file_page_was_freed()

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.

Parameters
[in]page_idpage id
Returns
control block if found in page hash table, otherwise NULL

◆ buf_page_set_flush_type()

static void buf_page_set_flush_type ( buf_page_t bpage,
buf_flush_t  flush_type 
)
inlinestatic

Set the flush type of a page.

Parameters
[in]bpagebuffer page
[in]flush_typeflush type

◆ buf_page_set_io_fix()

static void buf_page_set_io_fix ( buf_page_t bpage,
enum buf_io_fix  io_fix 
)
inlinestatic

Sets the io_fix state of a block.

Parameters
[in,out]bpagecontrol block
[in]io_fixio_fix state

◆ buf_page_set_old()

static void buf_page_set_old ( buf_page_t bpage,
bool  old 
)
inlinestatic

Flag a block old.

Parameters
[in,out]bpagecontrol block
[in]oldold

◆ buf_page_set_state()

static void buf_page_set_state ( buf_page_t bpage,
enum buf_page_state  state 
)
inlinestatic

Sets the state of a block.

Parameters
[in,out]bpagepointer to control block
[in]statestate

◆ buf_page_set_sticky()

static void buf_page_set_sticky ( buf_page_t bpage)
inlinestatic

Makes a block sticky.

A sticky block implies that even after we release the buf_pool->LRU_list_mutex and the block->mutex: it cannot be removed from the flush_list the block descriptor cannot be relocated it cannot be removed from the LRU list Note that: the block can still change its position in the LRU list the next and previous pointers can change.

Parameters
[in,out]bpagecontrol block

◆ buf_page_try_get()

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).

Parameters
[in]page_idpage Id
[in]locationLocation where called
[in]mtrMini-transaction
Returns
pointer to a page or NULL

◆ buf_page_unset_sticky()

static void buf_page_unset_sticky ( buf_page_t bpage)
inlinestatic

Removes stickiness of a block.

in/out: control block

◆ buf_pool_adjust_chunk_unit()

ulonglong buf_pool_adjust_chunk_unit ( ulonglong  size)

Adjust the proposed chunk unit size so that it satisfies all invariants.

Parameters
[in]sizeproposed size of buffer pool chunk unit in bytes
Returns
adjusted size which meets invariants

◆ buf_pool_clear_hash_index()

void buf_pool_clear_hash_index ( void  )

Clears the adaptive hash index on all pages in the buffer pool.

◆ buf_pool_contains_zip()

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.

Parameters
[in]buf_poolbuffer pool instance
[in]datapointer to compressed page
Returns
buffer block pointing to the compressed page, or NULL

◆ buf_pool_free_all()

void buf_pool_free_all ( )

Frees the buffer pool at shutdown.

This must not be invoked before freeing all mutexes.

Frees the buffer pool at shutdown.

◆ buf_pool_from_array()

static buf_pool_t * buf_pool_from_array ( ulint  index)
inlinestatic

Returns the buffer pool instance given its array index.

Returns
buffer pool in: array index to get buffer pool instance from

◆ buf_pool_from_block()

static buf_pool_t * buf_pool_from_block ( const buf_block_t block)
inlinestatic

Returns the buffer pool instance given a block instance.

Returns
buf_pool in: block

◆ buf_pool_from_bpage()

static buf_pool_t * buf_pool_from_bpage ( const buf_page_t bpage)
inlinestatic

Returns the buffer pool instance given a page instance.

Returns
buf_pool in: buffer pool page

◆ buf_pool_get()

static buf_pool_t * buf_pool_get ( const page_id_t page_id)
inlinestatic

Returns the buffer pool instance given a page id.

Parameters
[in]page_idpage id
Returns
buffer pool

◆ buf_pool_get_curr_size()

static ulint buf_pool_get_curr_size ( void  )
inlinestatic

Gets the current size of buffer buf_pool in bytes.

Returns
size in bytes

◆ buf_pool_get_n_pages()

static ulint buf_pool_get_n_pages ( void  )
inlinestatic

Gets the current size of buffer buf_pool in frames.

Returns
size in pages

◆ buf_pool_get_oldest_modification_approx()

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.

Note
Note that because of the relaxed order in each flush list, this functions no longer returns the smallest oldest_modification among all of the dirty pages. If you wanted to have a safe lsn, which is smaller than every oldest_modification, you would need to use another function: buf_pool_get_oldest_modification_lwm().

Returns zero if there were no dirty pages (flush lists were empty).

Returns
minimum oldest_modification of last pages from flush lists, zero if flush lists were empty

◆ buf_pool_get_oldest_modification_lwm()

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 = log_buffer_dirty_pages_added_up_to_lsn(*log_sys);

    lwm_lsn = buf_pool_get_oldest_modification_lwm();

    if (lwm_lsn == 0) lwm_lsn = dpa_lsn;

The order is important to avoid race conditions.

Remarks
It's guaranteed that the returned value will not be smaller than the last checkpoint lsn. It's not guaranteed that the returned value is the maximum possible. It's just the best effort for the low cost. It basically takes result of buf_pool_get_oldest_modification_approx() and subtracts maximum possible lag introduced by relaxed order in flush lists (srv_log_recent_closed_size).
Returns
safe low watermark for oldest_modification of dirty pages, or zero if flush lists were empty; if non-zero, it is then guaranteed not to be at block boundary (and it points to lsn inside data fragment of block)

◆ buf_pool_hash_zip()

static uint64_t buf_pool_hash_zip ( buf_block_t b)
inlinestatic

◆ buf_pool_hash_zip_frame()

static uint64_t buf_pool_hash_zip_frame ( void *  ptr)
inlinestatic

Compute the hash value for blocks in buf_pool->zip_hash.

◆ buf_pool_index()

static ulint buf_pool_index ( const buf_pool_t buf_pool)
inlinestatic

Calculates the index of a buffer pool to the buf_pool[] array.

Returns
the position of the buffer pool in buf_pool[] in: buffer pool

◆ buf_pool_init()

dberr_t buf_pool_init ( ulint  total_size,
ulint  n_instances 
)

Creates the buffer pool.

Parameters
[in]total_sizeSize of the total pool in bytes.
[in]n_instancesNumber of buffer pool instances to create.
Returns
DB_SUCCESS if success, DB_ERROR if not enough memory or error

◆ buf_pool_invalidate()

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.

◆ buf_pool_pending_io_reads_count()

size_t buf_pool_pending_io_reads_count ( )

Computes number of pending I/O read operations for the buffer pool.

Returns
number of pending i/o reads

◆ buf_pool_pending_io_writes_count()

size_t buf_pool_pending_io_writes_count ( )

Computes number of pending I/O write operations for the buffer pool.

Returns
number of pending i/o writes

◆ buf_pool_size_align()

static ulint buf_pool_size_align ( ulint  size)
inlinestatic

Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit, if needed.

Parameters
[in]sizesize in bytes
Returns
aligned size

◆ buf_pool_update_madvise()

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.

See also
buf_pool_should_madvise comment for a longer explanation.

◆ buf_pool_wait_for_no_pending_io()

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.

◆ buf_pool_watch_is_sentinel()

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.

Parameters
[in]buf_poolbuffer pool instance
[in]bpageblock
Returns
true if a sentinel for a buffer pool watch, false if not

◆ buf_pool_watch_occurred()

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).

Parameters
[in]page_idpage id
Returns
false if the given page was not read in, true if it was

◆ buf_pool_watch_unset()

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.

Parameters
[in]page_idpage id

◆ buf_print()

void buf_print ( void  )

Prints info of the buffer pool data structure.

Prints info of the buffer pool data structure.

◆ buf_print_io()

void buf_print_io ( FILE *  file)

Prints info of the buffer i/o.

in: file where to print

Parameters
filein/out: buffer where to print

◆ buf_ptr_get_fsp_addr()

static void buf_ptr_get_fsp_addr ( const void *  ptr,
space_id_t space,
fil_addr_t addr 
)
inlinestatic

Gets the space id, page offset, and byte offset within page of a pointer pointing to a buffer frame containing a file page.

Parameters
[in]ptrpointer to a buffer frame
[out]spacespace id
[out]addrpage offset and byte offset

◆ buf_read_page_handle_error()

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.

Parameters
[in,out]bpagepointer to the block

◆ buf_refresh_io_stats_all()

void buf_refresh_io_stats_all ( void  )

Refresh the statistics used to print per-second averages.

Refresh the statistics used to print per-second averages.

◆ buf_resize_thread()

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.

◆ buf_stats_get_pool_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 in/out: buffer pool info to fill

Also record aggregated stats if there are more than one buffer pool in the server

Parameters
buf_poolin: buffer pool
pool_idin: buffer pool ID
all_pool_infoin/out: buffer pool info to fill

◆ buf_validate()

bool buf_validate ( void  )

Validates the buffer pool data structure.

Returns
true

Validates the buffer pool data structure.

Returns
true

◆ buf_zip_decompress()

bool buf_zip_decompress ( buf_block_t block,
bool  check 
)

Decompress a block.

Returns
true if successful in: true=verify the page checksum
true if successful
Parameters
blockin/out: block
checkin: true=verify the page checksum

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const buf_pool_t buf_pool 
)

Print the given buf_pool_t object.

Parameters
[in,out]outthe output stream
[in]buf_poolthe buf_pool_t object to be printed
Returns
the output stream

Variable Documentation

◆ BUF_PAGE_STATE_BITS

constexpr uint32_t BUF_PAGE_STATE_BITS = 3
constexpr

The common buffer control block structure for compressed and uncompressed frames.

Number of bits used for buffer page states.

◆ buf_pool_ptr

buf_pool_t* buf_pool_ptr
extern

The buffer pools of the database.

◆ MAX_BUFFER_POOLS

constexpr ulint MAX_BUFFER_POOLS = (1 << MAX_BUFFER_POOLS_BITS)
constexpr

The maximum number of buffer pools that can be defined.

◆ MAX_BUFFER_POOLS_BITS

constexpr ulint MAX_BUFFER_POOLS_BITS = 6
constexpr

Number of bits to representing a buffer pool ID.

◆ MAX_PAGE_HASH_LOCKS

constexpr ulint MAX_PAGE_HASH_LOCKS = 1024
constexpr

The maximum number of page_hash locks.