MySQL 8.4.2
Source Code Documentation
buf0buf.ic File Reference

The database buffer buf_pool. More...

#include "mtr0mtr.h"
#include "buf0flu.h"
#include "buf0lru.h"
#include "buf0rea.h"
#include "fsp0types.h"
#include "sync0debug.h"
#include "ut0new.h"

Classes

struct  buf_chunk_t
 A chunk of buffers. More...
 

Functions

static ulint buf_pool_get_curr_size (void)
 Gets the current size of buffer buf_pool in bytes. 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 ulint buf_pool_get_n_pages (void)
 Gets the current size of buffer buf_pool in pages. 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 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 bool buf_page_is_private (const buf_page_t *bpage, bool hold_block_mutex, bool hold_zip_free_mutex)
 Assert that a given buffer pool page is private to the caller: no pointers to it exist in any buffer pool list or hash table. 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)
 
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...
 
static buf_frame_tbuf_frame_align (byte *ptr)
 
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...
 
static buf_page_tbuf_page_alloc_descriptor (void)
 Allocates a buf_page_t descriptor. 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...
 
static lsn_t buf_page_get_newest_modification (const buf_page_t *bpage)
 
static void buf_block_modify_clock_inc (buf_block_t *block)
 Increment the modify clock. 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 void buf_block_buf_fix_inc_func (ut::Location location, buf_block_t *block)
 
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...
 
static void buf_block_buf_fix_dec (buf_block_t *block)
 Decrements the bufferfix count. 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)
 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...
 
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...
 
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...
 
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 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...
 
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...
 

Detailed Description

The database buffer buf_pool.

Created 11/5/1995 Heikki Tuuri

Function Documentation

◆ buf_block_buf_fix_dec()

static void buf_block_buf_fix_dec ( buf_block_t block)
inlinestatic

Decrements the bufferfix count.

Parameters
blockin/out: block to bufferunfix

◆ buf_block_buf_fix_inc_func()

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

◆ 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
blockin: buffer page where we have acquired latch
levelin: latching 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.

Parameters
blockin, own: block to be freed

◆ 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
Parameters
blockin: 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
Parameters
blockin: 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
Parameters
blockin: pointer to the control block

◆ 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
Parameters
blockin: pointer to the control block

◆ 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_modify_clock_inc()

static void buf_block_modify_clock_inc ( buf_block_t block)
inlinestatic

Increment the modify clock.

The caller must (1) 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_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
blockin/out: control block
io_fixin: io_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
blockin/out: pointer to control block
statein: state

◆ 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_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.

Returns
buf
Parameters
bufin: buffer to copy to
framein: buffer frame

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

Returns
the nth chunk's buffer block.
Parameters
buf_poolin: buffer pool instance
nin: nth chunk in the buffer pool
chunk_sizein: chunk size

◆ 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_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.

Returns
: the allocated descriptor.

◆ 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
Parameters
bpagein: 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.

Parameters
bpagecontrol block being relocated

◆ 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
Parameters
bpagein: 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
Parameters
bpagein: block

◆ 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
Parameters
bpagein: pointer to the control block

◆ 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
Parameters
bpagein: pointer to control block

◆ buf_page_get_newest_modification()

static lsn_t buf_page_get_newest_modification ( const buf_page_t bpage)
inlinestatic

◆ 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
Parameters
bpagein: pointer to the control block

◆ 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 
)
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_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
Parameters
bpagein: pointer to control block

◆ buf_page_is_accessed()

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

◆ 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_is_private()

static bool buf_page_is_private ( const buf_page_t bpage,
bool  hold_block_mutex,
bool  hold_zip_free_mutex 
)
inlinestatic

Assert that a given buffer pool page is private to the caller: no pointers to it exist in any buffer pool list or hash table.

Accessing pages by iterating over buffer pool chunks is not considered here. Furthermore, assert that no buffer pool locks except for LRU list mutex and page hash are held.

Parameters
[in]bpagepointer to a buffer pool page
[in]hold_block_mutexflag whether holding block mutex
[in]hold_zip_free_mutexflag whether holding zip free mutex

◆ 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_release_latch()

static void buf_page_release_latch ( buf_block_t block,
ulint  rw_latch 
)
inlinestatic

Releases a latch, if specified.

Parameters
blockin: buffer block
rw_latchin: RW_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().

Parameters
bpagein: buffer block

◆ buf_page_set_accessed()

static void buf_page_set_accessed ( buf_page_t bpage)
inlinestatic

Flag a block accessed.

Parameters
bpagein/out: control block

◆ 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
bpagein: buffer page
flush_typein: flush 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
bpagein/out: control block
io_fixin: io_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]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_unset_sticky()

static void buf_page_unset_sticky ( buf_page_t bpage)
inlinestatic

Removes stickiness of a block.

Parameters
bpagein/out: control block

◆ 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
Parameters
indexin: 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
Parameters
blockin: 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
Parameters
bpagein: 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 pages.

Returns
size in pages

◆ 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[]
Parameters
buf_poolin: buffer pool

◆ 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_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
ptrin: pointer to a buffer frame
spaceout: space id
addrout: page offset and byte offset