~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-11-07 00:15:51 UTC
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: monty@inaugust.com-20081107001551-8vxb6sf1ti0i5p09
Cleaned up some headers for PCH.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The database buffer pool LRU replacement algorithm
 
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
 
6
Created 11/5/1995 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef buf0lru_h
 
10
#define buf0lru_h
 
11
 
 
12
#include "univ.i"
 
13
#include "ut0byte.h"
 
14
#include "buf0types.h"
 
15
 
 
16
/** The return type of buf_LRU_free_block() */
 
17
enum buf_lru_free_block_status {
 
18
        /** freed */
 
19
        BUF_LRU_FREED = 0,
 
20
        /** not freed because the caller asked to remove the
 
21
        uncompressed frame but the control block cannot be
 
22
        relocated */
 
23
        BUF_LRU_CANNOT_RELOCATE,
 
24
        /** not freed because of some other reason */
 
25
        BUF_LRU_NOT_FREED
 
26
};
 
27
 
 
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
 
35
wasted. */
 
36
UNIV_INTERN
 
37
void
 
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. */
 
44
UNIV_INTERN
 
45
ibool
 
46
buf_LRU_buf_pool_running_out(void);
 
47
/*==============================*/
 
48
                                /* out: TRUE if less than 25 % of buffer pool
 
49
                                left */
 
50
 
 
51
/*#######################################################################
 
52
These are low-level functions
 
53
#########################################################################*/
 
54
 
 
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
/**********************************************************************
 
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
 
65
completed? */
 
66
UNIV_INTERN
 
67
void
 
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. */
 
75
UNIV_INTERN
 
76
ulint
 
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. */
 
82
UNIV_INTERN
 
83
void
 
84
buf_LRU_insert_zip_clean(
 
85
/*=====================*/
 
86
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
87
 
 
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
 
92
buf_pool_mutex. */
 
93
UNIV_INTERN
 
94
enum buf_lru_free_block_status
 
95
buf_LRU_free_block(
 
96
/*===============*/
 
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. */
 
109
UNIV_INTERN
 
110
ibool
 
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. */
 
125
UNIV_INTERN
 
126
buf_block_t*
 
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. */
 
135
UNIV_INTERN
 
136
buf_block_t*
 
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 */
 
143
 
 
144
/**********************************************************************
 
145
Puts a block back to the free list. */
 
146
UNIV_INTERN
 
147
void
 
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. */
 
153
UNIV_INTERN
 
154
void
 
155
buf_LRU_add_block(
 
156
/*==============*/
 
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. */
 
164
UNIV_INTERN
 
165
void
 
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. */
 
173
UNIV_INTERN
 
174
void
 
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. */
 
180
UNIV_INTERN
 
181
void
 
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. */
 
188
UNIV_INTERN
 
189
void
 
190
buf_LRU_stat_update(void);
 
191
/*=====================*/
 
192
 
 
193
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
 
194
/**************************************************************************
 
195
Validates the LRU list. */
 
196
UNIV_INTERN
 
197
ibool
 
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. */
 
204
UNIV_INTERN
 
205
void
 
206
buf_LRU_print(void);
 
207
/*===============*/
 
208
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
 
209
 
 
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. */
 
214
 
 
215
/** Statistics for selecting the LRU list for eviction. */
 
216
struct buf_LRU_stat_struct
 
217
{
 
218
        ulint   io;     /**< Counter of buffer pool I/O operations. */
 
219
        ulint   unzip;  /**< Counter of page_zip_decompress operations. */
 
220
};
 
221
 
 
222
typedef struct buf_LRU_stat_struct buf_LRU_stat_t;
 
223
 
 
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;
 
227
 
 
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;
 
231
 
 
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++
 
238
 
 
239
#ifndef UNIV_NONINL
 
240
#include "buf0lru.ic"
 
241
#endif
 
242
 
 
243
#endif