1
/******************************************************
2
The database buffer pool LRU replacement algorithm
6
Created 11/5/1995 Heikki Tuuri
7
*******************************************************/
14
#include "buf0types.h"
16
/** The return type of buf_LRU_free_block() */
17
enum buf_lru_free_block_status {
20
/** not freed because the caller asked to remove the
21
uncompressed frame but the control block cannot be
23
BUF_LRU_CANNOT_RELOCATE,
24
/** not freed because of some other reason */
28
/**********************************************************************
29
Tries to remove LRU flushed blocks from the end of the LRU list and put them
30
to the free list. This is beneficial for the efficiency of the insert buffer
31
operation, as flushed pages from non-unique non-clustered indexes are here
32
taken out of the buffer pool, and their inserts redirected to the insert
33
buffer. Otherwise, the flushed blocks could get modified again before read
34
operations need new buffer blocks, and the i/o work done in flushing would be
38
buf_LRU_try_free_flushed_blocks(void);
39
/*==================================*/
40
/**********************************************************************
41
Returns TRUE if less than 25 % of the buffer pool is available. This can be
42
used in heuristics to prevent huge transactions eating up the whole buffer
43
pool for their locks. */
46
buf_LRU_buf_pool_running_out(void);
47
/*==============================*/
48
/* out: TRUE if less than 25 % of buffer pool
51
/*#######################################################################
52
These are low-level functions
53
#########################################################################*/
55
/* Minimum LRU list length for which the LRU_old pointer is defined */
57
#define BUF_LRU_OLD_MIN_LEN 80
59
#define BUF_LRU_FREE_SEARCH_LEN (5 + 2 * BUF_READ_AHEAD_AREA)
61
/**********************************************************************
62
Invalidates all pages belonging to a given tablespace when we are deleting
63
the data file(s) of that tablespace. A PROBLEM: if readahead is being started,
64
what guarantees that it will not try to read in pages after this operation has
68
buf_LRU_invalidate_tablespace(
69
/*==========================*/
70
ulint id); /* in: space id */
71
/**********************************************************************
72
Gets the minimum LRU_position field for the blocks in an initial segment
73
(determined by BUF_LRU_INITIAL_RATIO) of the LRU list. The limit is not
74
guaranteed to be precise, because the ulint_clock may wrap around. */
77
buf_LRU_get_recent_limit(void);
78
/*==========================*/
79
/* out: the limit; zero if could not determine it */
80
/************************************************************************
81
Insert a compressed block into buf_pool->zip_clean in the LRU order. */
84
buf_LRU_insert_zip_clean(
85
/*=====================*/
86
buf_page_t* bpage); /* in: pointer to the block in question */
88
/**********************************************************************
89
Try to free a block. If bpage is a descriptor of a compressed-only
90
page, the descriptor object will be freed as well. If this function
91
returns BUF_LRU_FREED, it will not temporarily release
94
enum buf_lru_free_block_status
97
/* out: BUF_LRU_FREED if freed,
98
BUF_LRU_CANNOT_RELOCATE or
99
BUF_LRU_NOT_FREED otherwise. */
100
buf_page_t* bpage, /* in: block to be freed */
101
ibool zip, /* in: TRUE if should remove also the
102
compressed page of an uncompressed page */
103
ibool* buf_pool_mutex_released);
104
/* in: pointer to a variable that will
105
be assigned TRUE if buf_pool_mutex
106
was temporarily released, or NULL */
107
/**********************************************************************
108
Try to free a replaceable block. */
111
buf_LRU_search_and_free_block(
112
/*==========================*/
113
/* out: TRUE if found and freed */
114
ulint n_iterations); /* in: how many times this has been called
115
repeatedly without result: a high value means
116
that we should search farther; if
117
n_iterations < 10, then we search
118
n_iterations / 10 * buf_pool->curr_size
119
pages from the end of the LRU list; if
120
n_iterations < 5, then we will also search
121
n_iterations / 5 of the unzip_LRU list. */
122
/**********************************************************************
123
Returns a free block from the buf_pool. The block is taken off the
124
free list. If it is empty, returns NULL. */
127
buf_LRU_get_free_only(void);
128
/*=======================*/
129
/* out: a free control block, or NULL
130
if the buf_block->free list is empty */
131
/**********************************************************************
132
Returns a free block from the buf_pool. The block is taken off the
133
free list. If it is empty, blocks are moved from the end of the
134
LRU list to the free list. */
137
buf_LRU_get_free_block(
138
/*===================*/
139
/* out: the free control block,
140
in state BUF_BLOCK_READY_FOR_USE */
141
ulint zip_size); /* in: compressed page size in bytes,
142
or 0 if uncompressed tablespace */
144
/**********************************************************************
145
Puts a block back to the free list. */
148
buf_LRU_block_free_non_file_page(
149
/*=============================*/
150
buf_block_t* block); /* in: block, must not contain a file page */
151
/**********************************************************************
152
Adds a block to the LRU list. */
157
buf_page_t* bpage, /* in: control block */
158
ibool old); /* in: TRUE if should be put to the old
159
blocks in the LRU list, else put to the
160
start; if the LRU list is very short, added to
161
the start regardless of this parameter */
162
/**********************************************************************
163
Adds a block to the LRU list of decompressed zip pages. */
166
buf_unzip_LRU_add_block(
167
/*====================*/
168
buf_block_t* block, /* in: control block */
169
ibool old); /* in: TRUE if should be put to the end
170
of the list, else put to the start */
171
/**********************************************************************
172
Moves a block to the start of the LRU list. */
175
buf_LRU_make_block_young(
176
/*=====================*/
177
buf_page_t* bpage); /* in: control block */
178
/**********************************************************************
179
Moves a block to the end of the LRU list. */
182
buf_LRU_make_block_old(
183
/*===================*/
184
buf_page_t* bpage); /* in: control block */
185
/************************************************************************
186
Update the historical stats that we are collecting for LRU eviction
187
policy at the end of each interval. */
190
buf_LRU_stat_update(void);
191
/*=====================*/
193
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
194
/**************************************************************************
195
Validates the LRU list. */
198
buf_LRU_validate(void);
199
/*==================*/
200
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
201
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
202
/**************************************************************************
203
Prints the LRU list. */
208
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
210
/**********************************************************************
211
These statistics are not 'of' LRU but 'for' LRU. We keep count of I/O
212
and page_zip_decompress() operations. Based on the statistics we decide
213
if we want to evict from buf_pool->unzip_LRU or buf_pool->LRU. */
215
/** Statistics for selecting the LRU list for eviction. */
216
struct buf_LRU_stat_struct
218
ulint io; /**< Counter of buffer pool I/O operations. */
219
ulint unzip; /**< Counter of page_zip_decompress operations. */
222
typedef struct buf_LRU_stat_struct buf_LRU_stat_t;
224
/** Current operation counters. Not protected by any mutex.
225
Cleared by buf_LRU_stat_update(). */
226
extern buf_LRU_stat_t buf_LRU_stat_cur;
228
/** Running sum of past values of buf_LRU_stat_cur.
229
Updated by buf_LRU_stat_update(). Protected by buf_pool_mutex. */
230
extern buf_LRU_stat_t buf_LRU_stat_sum;
232
/************************************************************************
233
Increments the I/O counter in buf_LRU_stat_cur. */
234
#define buf_LRU_stat_inc_io() buf_LRU_stat_cur.io++
235
/************************************************************************
236
Increments the page_zip_decompress() counter in buf_LRU_stat_cur. */
237
#define buf_LRU_stat_inc_unzip() buf_LRU_stat_cur.unzip++
240
#include "buf0lru.ic"