1
/*****************************************************************************
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/buf0flu.h
21
The database buffer pool flush algorithm
23
Created 11/5/1995 Heikki Tuuri
24
*******************************************************/
31
#ifndef UNIV_HOTBACKUP
32
#include "mtr0types.h"
33
#include "buf0types.h"
35
/********************************************************************//**
36
Remove a block from the flush list of modified blocks. */
41
buf_page_t* bpage); /*!< in: pointer to the block in question */
42
/********************************************************************//**
43
Relocates a buffer control block on the flush_list.
44
Note that it is assumed that the contents of bpage has already been
48
buf_flush_relocate_on_flush_list(
49
/*=============================*/
50
buf_page_t* bpage, /*!< in/out: control block being moved */
51
buf_page_t* dpage); /*!< in/out: destination block */
52
/********************************************************************//**
53
Updates the flush system data structures when a write is completed. */
56
buf_flush_write_complete(
57
/*=====================*/
58
buf_page_t* bpage); /*!< in: pointer to the block in question */
59
/*********************************************************************//**
60
Flushes pages from the end of the LRU list if there is too small
61
a margin of replaceable pages there. */
64
buf_flush_free_margin(void);
65
/*=======================*/
66
#endif /* !UNIV_HOTBACKUP */
67
/********************************************************************//**
68
Initializes a page for writing to the tablespace. */
71
buf_flush_init_for_writing(
72
/*=======================*/
73
byte* page, /*!< in/out: page */
74
void* page_zip_, /*!< in/out: compressed page, or NULL */
75
ib_uint64_t newest_lsn); /*!< in: newest modification lsn
77
#ifndef UNIV_HOTBACKUP
78
/*******************************************************************//**
79
This utility flushes dirty blocks from the end of the LRU list or flush_list.
80
NOTE 1: in the case of an LRU flush the calling thread may own latches to
81
pages: to avoid deadlocks, this function must be written so that it cannot
82
end up waiting for these latches! NOTE 2: in the case of a flush list flush,
83
the calling thread is not allowed to own any latches on pages!
84
@return number of blocks for which the write request was queued;
85
ULINT_UNDEFINED if there was a flush of the same type already running */
90
enum buf_flush flush_type, /*!< in: BUF_FLUSH_LRU or
91
BUF_FLUSH_LIST; if BUF_FLUSH_LIST,
92
then the caller must not own any
94
ulint min_n, /*!< in: wished minimum mumber of blocks
95
flushed (it is not guaranteed that the
96
actual number is that big, though) */
97
ib_uint64_t lsn_limit); /*!< in the case BUF_FLUSH_LIST all
98
blocks whose oldest_modification is
99
smaller than this should be flushed
100
(if their number does not exceed
101
min_n), otherwise ignored */
102
/******************************************************************//**
103
Waits until a flush batch of the given type ends */
106
buf_flush_wait_batch_end(
107
/*=====================*/
108
enum buf_flush type); /*!< in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
109
/********************************************************************//**
110
This function should be called at a mini-transaction commit, if a page was
111
modified in it. Puts the block to the list of modified blocks, if it not
115
buf_flush_note_modification(
116
/*========================*/
117
buf_block_t* block, /*!< in: block which is modified */
118
mtr_t* mtr); /*!< in: mtr */
119
/********************************************************************//**
120
This function should be called when recovery has modified a buffer page. */
123
buf_flush_recv_note_modification(
124
/*=============================*/
125
buf_block_t* block, /*!< in: block which is modified */
126
ib_uint64_t start_lsn, /*!< in: start lsn of the first mtr in a
128
ib_uint64_t end_lsn); /*!< in: end lsn of the last mtr in the
130
/********************************************************************//**
131
Returns TRUE if the file page block is immediately suitable for replacement,
132
i.e., transition FILE_PAGE => NOT_USED allowed.
133
@return TRUE if can replace immediately */
136
buf_flush_ready_for_replace(
137
/*========================*/
138
buf_page_t* bpage); /*!< in: buffer control block, must be
139
buf_page_in_file(bpage) and in the LRU list */
141
/** @brief Statistics for selecting flush rate based on redo log
144
These statistics are generated for heuristics used in estimating the
145
rate at which we should flush the dirty blocks to avoid bursty IO
146
activity. Note that the rate of flushing not only depends on how many
147
dirty pages we have in the buffer pool but it is also a fucntion of
148
how much redo the workload is generating and at what rate. */
150
struct buf_flush_stat_struct
152
ib_uint64_t redo; /*!< amount of redo generated. */
153
ulint n_flushed; /*!< number of pages flushed. */
156
/** Statistics for selecting flush rate of dirty pages. */
157
typedef struct buf_flush_stat_struct buf_flush_stat_t;
158
/*********************************************************************
159
Update the historical stats that we are collecting for flush rate
160
heuristics at the end of each interval. */
163
buf_flush_stat_update(void);
164
/*=======================*/
165
/*********************************************************************
166
Determines the fraction of dirty pages that need to be flushed based
167
on the speed at which we generate redo log. Note that if redo log
168
is generated at significant rate without a corresponding increase
169
in the number of dirty pages (for example, an in-memory workload)
170
it can cause IO bursts of flushing. This function implements heuristics
171
to avoid this burstiness.
172
@return number of dirty pages to be flushed / second */
175
buf_flush_get_desired_flush_rate(void);
176
/*==================================*/
178
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
179
/******************************************************************//**
180
Validates the flush list.
181
@return TRUE if ok */
184
buf_flush_validate(void);
185
/*====================*/
186
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
188
/******************************************************************//**
189
Initialize the red-black tree to speed up insertions into the flush_list
190
during recovery process. Should be called at the start of recovery
191
process before any page has been read/written. */
194
buf_flush_init_flush_rbt(void);
195
/*==========================*/
197
/******************************************************************//**
198
Frees up the red-black tree. */
201
buf_flush_free_flush_rbt(void);
202
/*==========================*/
204
/** When buf_flush_free_margin is called, it tries to make this many blocks
205
available to replacement in the free list and at the end of the LRU list (to
206
make sure that a read-ahead batch can be read efficiently in a single
208
#define BUF_FLUSH_FREE_BLOCK_MARGIN (5 + BUF_READ_AHEAD_AREA)
209
/** Extra margin to apply above BUF_FLUSH_FREE_BLOCK_MARGIN */
210
#define BUF_FLUSH_EXTRA_MARGIN (BUF_FLUSH_FREE_BLOCK_MARGIN / 4 + 100)
211
#endif /* !UNIV_HOTBACKUP */
214
#include "buf0flu.ic"