~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/buf0lru.h

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
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.
8
 
 
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.
12
 
 
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
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/buf0lru.h
 
1
/******************************************************
21
2
The database buffer pool LRU replacement algorithm
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 11/5/1995 Heikki Tuuri
24
7
*******************************************************/
25
8
 
26
9
#ifndef buf0lru_h
27
10
#define buf0lru_h
28
11
 
29
 
#include <sys/types.h>
30
12
#include "univ.i"
31
13
#include "ut0byte.h"
32
14
#include "buf0types.h"
43
25
        BUF_LRU_NOT_FREED
44
26
};
45
27
 
46
 
/******************************************************************//**
 
28
/**********************************************************************
47
29
Tries to remove LRU flushed blocks from the end of the LRU list and put them
48
30
to the free list. This is beneficial for the efficiency of the insert buffer
49
31
operation, as flushed pages from non-unique non-clustered indexes are here
53
35
wasted. */
54
36
UNIV_INTERN
55
37
void
56
 
buf_LRU_try_free_flushed_blocks(
57
 
/*============================*/
58
 
        buf_pool_t*     buf_pool);      /*!< in: buffer pool instance */
59
 
/******************************************************************//**
 
38
buf_LRU_try_free_flushed_blocks(void);
 
39
/*==================================*/
 
40
/**********************************************************************
60
41
Returns TRUE if less than 25 % of the buffer pool is available. This can be
61
42
used in heuristics to prevent huge transactions eating up the whole buffer
62
 
pool for their locks.
63
 
@return TRUE if less than 25 % of buffer pool left */
 
43
pool for their locks. */
64
44
UNIV_INTERN
65
45
ibool
66
46
buf_LRU_buf_pool_running_out(void);
67
47
/*==============================*/
 
48
                                /* out: TRUE if less than 25 % of buffer pool
 
49
                                left */
68
50
 
69
51
/*#######################################################################
70
52
These are low-level functions
71
53
#########################################################################*/
72
54
 
73
 
/** Minimum LRU list length for which the LRU_old pointer is defined */
74
 
#define BUF_LRU_OLD_MIN_LEN     512     /* 8 megabytes of 16k pages */
75
 
 
76
 
/** Maximum LRU list search length in buf_flush_LRU_recommendation() */
77
 
#define BUF_LRU_FREE_SEARCH_LEN(b)      (5 + 2 * BUF_READ_AHEAD_AREA(b))
78
 
 
79
 
/******************************************************************//**
 
55
/* Minimum LRU list length for which the LRU_old pointer is defined */
 
56
 
 
57
#define BUF_LRU_OLD_MIN_LEN     80
 
58
 
 
59
#define BUF_LRU_FREE_SEARCH_LEN         (5 + 2 * BUF_READ_AHEAD_AREA)
 
60
 
 
61
/**********************************************************************
80
62
Invalidates all pages belonging to a given tablespace when we are deleting
81
63
the data file(s) of that tablespace. A PROBLEM: if readahead is being started,
82
64
what guarantees that it will not try to read in pages after this operation has
85
67
void
86
68
buf_LRU_invalidate_tablespace(
87
69
/*==========================*/
88
 
        ulint   id);    /*!< in: space id */
89
 
/********************************************************************//**
 
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. */
 
75
UNIV_INTERN
 
76
ulint
 
77
buf_LRU_get_recent_limit(void);
 
78
/*==========================*/
 
79
                        /* out: the limit; zero if could not determine it */
 
80
/************************************************************************
90
81
Insert a compressed block into buf_pool->zip_clean in the LRU order. */
91
82
UNIV_INTERN
92
83
void
93
84
buf_LRU_insert_zip_clean(
94
85
/*=====================*/
95
 
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
 
86
        buf_page_t*     bpage); /* in: pointer to the block in question */
96
87
 
97
 
/******************************************************************//**
 
88
/**********************************************************************
98
89
Try to free a block.  If bpage is a descriptor of a compressed-only
99
 
page, the descriptor object will be freed as well.
100
 
 
101
 
NOTE: If this function returns BUF_LRU_FREED, it will temporarily
102
 
release buf_pool->mutex.  Furthermore, the page frame will no longer be
103
 
accessible via bpage.
104
 
 
105
 
The caller must hold buf_pool->mutex and buf_page_get_mutex(bpage) and
106
 
release these two mutexes after the call.  No other
107
 
buf_page_get_mutex() may be held when calling this function.
108
 
@return BUF_LRU_FREED if freed, BUF_LRU_CANNOT_RELOCATE or
109
 
BUF_LRU_NOT_FREED otherwise. */
 
90
page, the descriptor object will be freed as well.  If this function
 
91
returns BUF_LRU_FREED, it will not temporarily release
 
92
buf_pool_mutex. */
110
93
UNIV_INTERN
111
94
enum buf_lru_free_block_status
112
95
buf_LRU_free_block(
113
96
/*===============*/
114
 
        buf_page_t*     bpage,  /*!< in: block to be freed */
115
 
        ibool           zip,    /*!< in: TRUE if should remove also the
 
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
116
102
                                compressed page of an uncompressed page */
117
103
        ibool*          buf_pool_mutex_released);
118
 
                                /*!< in: pointer to a variable that will
119
 
                                be assigned TRUE if buf_pool->mutex
 
104
                                /* in: pointer to a variable that will
 
105
                                be assigned TRUE if buf_pool_mutex
120
106
                                was temporarily released, or NULL */
121
 
/******************************************************************//**
122
 
Try to free a replaceable block.
123
 
@return TRUE if found and freed */
 
107
/**********************************************************************
 
108
Try to free a replaceable block. */
124
109
UNIV_INTERN
125
110
ibool
126
111
buf_LRU_search_and_free_block(
127
112
/*==========================*/
128
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
129
 
        ulint           n_iterations);  /*!< in: how many times this has
130
 
                                        been called repeatedly without
131
 
                                        result: a high value means that
132
 
                                        we should search farther; if
133
 
                                        n_iterations < 10, then we search
134
 
                                        n_iterations / 10 * buf_pool->curr_size
135
 
                                        pages from the end of the LRU list; if
136
 
                                        n_iterations < 5, then we will
137
 
                                        also search n_iterations / 5
138
 
                                        of the unzip_LRU list. */
139
 
/******************************************************************//**
 
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
/**********************************************************************
140
123
Returns a free block from the buf_pool.  The block is taken off the
141
 
free list.  If it is empty, returns NULL.
142
 
@return a free control block, or NULL if the buf_block->free list is empty */
 
124
free list.  If it is empty, returns NULL. */
143
125
UNIV_INTERN
144
126
buf_block_t*
145
 
buf_LRU_get_free_only(
146
 
/*==================*/
147
 
        buf_pool_t*     buf_pool);      /*!< buffer pool instance */
148
 
/******************************************************************//**
 
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
/**********************************************************************
149
132
Returns a free block from the buf_pool. The block is taken off the
150
133
free list. If it is empty, blocks are moved from the end of the
151
 
LRU list to the free list.
152
 
@return the free control block, in state BUF_BLOCK_READY_FOR_USE */
 
134
LRU list to the free list. */
153
135
UNIV_INTERN
154
136
buf_block_t*
155
137
buf_LRU_get_free_block(
156
138
/*===================*/
157
 
        buf_pool_t*     buf_pool,       /*!< in: preferred buffer pool */
158
 
        ulint           zip_size);      /*!< in: compressed page size in bytes,
159
 
                                        or 0 if uncompressed tablespace */
 
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 */
160
143
 
161
 
/******************************************************************//**
 
144
/**********************************************************************
162
145
Puts a block back to the free list. */
163
146
UNIV_INTERN
164
147
void
165
148
buf_LRU_block_free_non_file_page(
166
149
/*=============================*/
167
 
        buf_block_t*    block); /*!< in: block, must not contain a file page */
168
 
/******************************************************************//**
 
150
        buf_block_t*    block); /* in: block, must not contain a file page */
 
151
/**********************************************************************
169
152
Adds a block to the LRU list. */
170
153
UNIV_INTERN
171
154
void
172
155
buf_LRU_add_block(
173
156
/*==============*/
174
 
        buf_page_t*     bpage,  /*!< in: control block */
175
 
        ibool           old);   /*!< in: TRUE if should be put to the old
 
157
        buf_page_t*     bpage,  /* in: control block */
 
158
        ibool           old);   /* in: TRUE if should be put to the old
176
159
                                blocks in the LRU list, else put to the
177
160
                                start; if the LRU list is very short, added to
178
161
                                the start regardless of this parameter */
179
 
/******************************************************************//**
 
162
/**********************************************************************
180
163
Adds a block to the LRU list of decompressed zip pages. */
181
164
UNIV_INTERN
182
165
void
183
166
buf_unzip_LRU_add_block(
184
167
/*====================*/
185
 
        buf_block_t*    block,  /*!< in: control block */
186
 
        ibool           old);   /*!< in: TRUE if should be put to the end
 
168
        buf_block_t*    block,  /* in: control block */
 
169
        ibool           old);   /* in: TRUE if should be put to the end
187
170
                                of the list, else put to the start */
188
 
/******************************************************************//**
 
171
/**********************************************************************
189
172
Moves a block to the start of the LRU list. */
190
173
UNIV_INTERN
191
174
void
192
175
buf_LRU_make_block_young(
193
176
/*=====================*/
194
 
        buf_page_t*     bpage); /*!< in: control block */
195
 
/******************************************************************//**
 
177
        buf_page_t*     bpage); /* in: control block */
 
178
/**********************************************************************
196
179
Moves a block to the end of the LRU list. */
197
180
UNIV_INTERN
198
181
void
199
182
buf_LRU_make_block_old(
200
183
/*===================*/
201
 
        buf_page_t*     bpage); /*!< in: control block */
202
 
/**********************************************************************//**
203
 
Updates buf_LRU_old_ratio.
204
 
@return updated old_pct */
205
 
UNIV_INTERN
206
 
ulint
207
 
buf_LRU_old_ratio_update(
208
 
/*=====================*/
209
 
        uint    old_pct,/*!< in: Reserve this percentage of
210
 
                        the buffer pool for "old" blocks. */
211
 
        ibool   adjust);/*!< in: TRUE=adjust the LRU list;
212
 
                        FALSE=just assign buf_LRU_old_ratio
213
 
                        during the initialization of InnoDB */
214
 
/********************************************************************//**
 
184
        buf_page_t*     bpage); /* in: control block */
 
185
/************************************************************************
215
186
Update the historical stats that we are collecting for LRU eviction
216
187
policy at the end of each interval. */
217
188
UNIV_INTERN
220
191
/*=====================*/
221
192
 
222
193
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
223
 
/**********************************************************************//**
224
 
Validates the LRU list.
225
 
@return TRUE */
 
194
/**************************************************************************
 
195
Validates the LRU list. */
226
196
UNIV_INTERN
227
197
ibool
228
198
buf_LRU_validate(void);
229
199
/*==================*/
230
200
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
231
201
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
232
 
/**********************************************************************//**
 
202
/**************************************************************************
233
203
Prints the LRU list. */
234
204
UNIV_INTERN
235
205
void
237
207
/*===============*/
238
208
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
239
209
 
240
 
/** @name Heuristics for detecting index scan @{ */
241
 
/** Reserve this much/BUF_LRU_OLD_RATIO_DIV of the buffer pool for
242
 
"old" blocks.  Protected by buf_pool->mutex. */
243
 
extern uint     buf_LRU_old_ratio;
244
 
/** The denominator of buf_LRU_old_ratio. */
245
 
#define BUF_LRU_OLD_RATIO_DIV   1024
246
 
/** Maximum value of buf_LRU_old_ratio.
247
 
@see buf_LRU_old_adjust_len
248
 
@see buf_LRU_old_ratio_update */
249
 
#define BUF_LRU_OLD_RATIO_MAX   BUF_LRU_OLD_RATIO_DIV
250
 
/** Minimum value of buf_LRU_old_ratio.
251
 
@see buf_LRU_old_adjust_len
252
 
@see buf_LRU_old_ratio_update
253
 
The minimum must exceed
254
 
(BUF_LRU_OLD_TOLERANCE + 5) * BUF_LRU_OLD_RATIO_DIV / BUF_LRU_OLD_MIN_LEN. */
255
 
#define BUF_LRU_OLD_RATIO_MIN   51
256
 
 
257
 
#if BUF_LRU_OLD_RATIO_MIN >= BUF_LRU_OLD_RATIO_MAX
258
 
# error "BUF_LRU_OLD_RATIO_MIN >= BUF_LRU_OLD_RATIO_MAX"
259
 
#endif
260
 
#if BUF_LRU_OLD_RATIO_MAX > BUF_LRU_OLD_RATIO_DIV
261
 
# error "BUF_LRU_OLD_RATIO_MAX > BUF_LRU_OLD_RATIO_DIV"
262
 
#endif
263
 
 
264
 
/** Move blocks to "new" LRU list only if the first access was at
265
 
least this many milliseconds ago.  Not protected by any mutex or latch. */
266
 
extern uint     buf_LRU_old_threshold_ms;
267
 
/* @} */
268
 
 
269
 
/** @brief Statistics for selecting the LRU list for eviction.
270
 
 
 
210
/**********************************************************************
271
211
These statistics are not 'of' LRU but 'for' LRU.  We keep count of I/O
272
212
and page_zip_decompress() operations.  Based on the statistics we decide
273
213
if we want to evict from buf_pool->unzip_LRU or buf_pool->LRU. */
 
214
 
 
215
/** Statistics for selecting the LRU list for eviction. */
274
216
struct buf_LRU_stat_struct
275
217
{
276
218
        ulint   io;     /**< Counter of buffer pool I/O operations. */
277
219
        ulint   unzip;  /**< Counter of page_zip_decompress operations. */
278
220
};
279
221
 
280
 
/** Statistics for selecting the LRU list for eviction. */
281
222
typedef struct buf_LRU_stat_struct buf_LRU_stat_t;
282
223
 
283
224
/** Current operation counters.  Not protected by any mutex.
285
226
extern buf_LRU_stat_t   buf_LRU_stat_cur;
286
227
 
287
228
/** Running sum of past values of buf_LRU_stat_cur.
288
 
Updated by buf_LRU_stat_update().  Protected by buf_pool->mutex. */
 
229
Updated by buf_LRU_stat_update().  Protected by buf_pool_mutex. */
289
230
extern buf_LRU_stat_t   buf_LRU_stat_sum;
290
231
 
291
 
/********************************************************************//**
 
232
/************************************************************************
292
233
Increments the I/O counter in buf_LRU_stat_cur. */
293
234
#define buf_LRU_stat_inc_io() buf_LRU_stat_cur.io++
294
 
/********************************************************************//**
 
235
/************************************************************************
295
236
Increments the page_zip_decompress() counter in buf_LRU_stat_cur. */
296
237
#define buf_LRU_stat_inc_unzip() buf_LRU_stat_cur.unzip++
297
238