~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-10 00:14:40 UTC
  • Revision ID: brian@tangent.org-20090210001440-qjg8eofh3h93064b
Adding Multi-threaded Scheduler into the system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2010, 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/buf0flu.h
 
1
/******************************************************
21
2
The database buffer pool flush algorithm
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 11/5/1995 Heikki Tuuri
24
7
*******************************************************/
25
8
 
27
10
#define buf0flu_h
28
11
 
29
12
#include "univ.i"
 
13
#include "buf0types.h"
30
14
#include "ut0byte.h"
31
 
#ifndef UNIV_HOTBACKUP
32
15
#include "mtr0types.h"
33
 
#include "buf0types.h"
34
 
#include "log0log.h"
35
16
 
36
 
/********************************************************************//**
 
17
/************************************************************************
 
18
Inserts a modified block into the flush list. */
 
19
UNIV_INTERN
 
20
void
 
21
buf_flush_insert_into_flush_list(
 
22
/*=============================*/
 
23
        buf_page_t*     bpage); /* in: block which is modified */
 
24
/************************************************************************
37
25
Remove a block from the flush list of modified blocks. */
38
26
UNIV_INTERN
39
27
void
40
28
buf_flush_remove(
41
29
/*=============*/
42
 
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
43
 
/*******************************************************************//**
44
 
Relocates a buffer control block on the flush_list.
45
 
Note that it is assumed that the contents of bpage has already been
46
 
copied to dpage. */
47
 
UNIV_INTERN
48
 
void
49
 
buf_flush_relocate_on_flush_list(
50
 
/*=============================*/
51
 
        buf_page_t*     bpage,  /*!< in/out: control block being moved */
52
 
        buf_page_t*     dpage); /*!< in/out: destination block */
53
 
/********************************************************************//**
 
30
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
31
/************************************************************************
54
32
Updates the flush system data structures when a write is completed. */
55
33
UNIV_INTERN
56
34
void
57
35
buf_flush_write_complete(
58
36
/*=====================*/
59
 
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
60
 
/*********************************************************************//**
 
37
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
38
/*************************************************************************
61
39
Flushes pages from the end of the LRU list if there is too small
62
 
a margin of replaceable pages there. If buffer pool is NULL it
63
 
means flush free margin on all buffer pool instances. */
64
 
UNIV_INTERN
65
 
void
66
 
buf_flush_free_margin(
67
 
/*==================*/
68
 
         buf_pool_t*    buf_pool);
69
 
/*********************************************************************//**
70
 
Flushes pages from the end of all the LRU lists. */
71
 
UNIV_INTERN
72
 
void
73
 
buf_flush_free_margins(void);
74
 
/*=========================*/
75
 
#endif /* !UNIV_HOTBACKUP */
76
 
/********************************************************************//**
 
40
a margin of replaceable pages there. */
 
41
UNIV_INTERN
 
42
void
 
43
buf_flush_free_margin(void);
 
44
/*=======================*/
 
45
/************************************************************************
77
46
Initializes a page for writing to the tablespace. */
78
47
UNIV_INTERN
79
48
void
80
49
buf_flush_init_for_writing(
81
50
/*=======================*/
82
 
        byte*           page,           /*!< in/out: page */
83
 
        void*           page_zip_,      /*!< in/out: compressed page, or NULL */
84
 
        ib_uint64_t     newest_lsn);    /*!< in: newest modification lsn
 
51
        byte*           page,           /* in/out: page */
 
52
        void*           page_zip_,      /* in/out: compressed page, or NULL */
 
53
        ib_uint64_t     newest_lsn);    /* in: newest modification lsn
85
54
                                        to the page */
86
 
#ifndef UNIV_HOTBACKUP
87
 
# if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
88
 
/********************************************************************//**
89
 
Writes a flushable page asynchronously from the buffer pool to a file.
90
 
NOTE: buf_pool->mutex and block->mutex must be held upon entering this
91
 
function, and they will be released by this function after flushing.
92
 
This is loosely based on buf_flush_batch() and buf_flush_page().
93
 
@return TRUE if the page was flushed and the mutexes released */
94
 
UNIV_INTERN
95
 
ibool
96
 
buf_flush_page_try(
97
 
/*===============*/
98
 
        buf_pool_t*     buf_pool,       /*!< in/out: buffer pool instance */
99
 
        buf_block_t*    block)          /*!< in/out: buffer control block */
100
 
        __attribute__((nonnull, warn_unused_result));
101
 
# endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
102
 
/*******************************************************************//**
103
 
This utility flushes dirty blocks from the end of the LRU list.
104
 
NOTE: The calling thread may own latches to pages: to avoid deadlocks,
105
 
this function must be written so that it cannot end up waiting for these
106
 
latches!
107
 
@return number of blocks for which the write request was queued;
108
 
ULINT_UNDEFINED if there was a flush of the same type already running */
109
 
UNIV_INTERN
110
 
ulint
111
 
buf_flush_LRU(
112
 
/*==========*/
113
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
114
 
        ulint           min_n);         /*!< in: wished minimum mumber of blocks
115
 
                                        flushed (it is not guaranteed that the
116
 
                                        actual number is that big, though) */
117
 
/*******************************************************************//**
118
 
This utility flushes dirty blocks from the end of the flush_list of
119
 
all buffer pool instances.
120
 
NOTE: The calling thread is not allowed to own any latches on pages!
121
 
@return number of blocks for which the write request was queued;
122
 
ULINT_UNDEFINED if there was a flush of the same type already running */
123
 
UNIV_INTERN
124
 
ulint
125
 
buf_flush_list(
 
55
/***********************************************************************
 
56
This utility flushes dirty blocks from the end of the LRU list or flush_list.
 
57
NOTE 1: in the case of an LRU flush the calling thread may own latches to
 
58
pages: to avoid deadlocks, this function must be written so that it cannot
 
59
end up waiting for these latches! NOTE 2: in the case of a flush list flush,
 
60
the calling thread is not allowed to own any latches on pages! */
 
61
UNIV_INTERN
 
62
ulint
 
63
buf_flush_batch(
126
64
/*============*/
127
 
        ulint           min_n,          /*!< in: wished minimum mumber of blocks
 
65
                                        /* out: number of blocks for which the
 
66
                                        write request was queued;
 
67
                                        ULINT_UNDEFINED if there was a flush
 
68
                                        of the same type already running */
 
69
        enum buf_flush  flush_type,     /* in: BUF_FLUSH_LRU or
 
70
                                        BUF_FLUSH_LIST; if BUF_FLUSH_LIST,
 
71
                                        then the caller must not own any
 
72
                                        latches on pages */
 
73
        ulint           min_n,          /* in: wished minimum mumber of blocks
128
74
                                        flushed (it is not guaranteed that the
129
75
                                        actual number is that big, though) */
130
 
        ib_uint64_t     lsn_limit);     /*!< in the case BUF_FLUSH_LIST all
 
76
        ib_uint64_t     lsn_limit);     /* in the case BUF_FLUSH_LIST all
131
77
                                        blocks whose oldest_modification is
132
78
                                        smaller than this should be flushed
133
79
                                        (if their number does not exceed
134
80
                                        min_n), otherwise ignored */
135
 
/******************************************************************//**
 
81
/**********************************************************************
136
82
Waits until a flush batch of the given type ends */
137
83
UNIV_INTERN
138
84
void
139
85
buf_flush_wait_batch_end(
140
86
/*=====================*/
141
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
142
 
        enum buf_flush  type);          /*!< in: BUF_FLUSH_LRU
143
 
                                        or BUF_FLUSH_LIST */
144
 
/********************************************************************//**
 
87
        enum buf_flush  type);  /* in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
 
88
/************************************************************************
145
89
This function should be called at a mini-transaction commit, if a page was
146
90
modified in it. Puts the block to the list of modified blocks, if it not
147
91
already in it. */
149
93
void
150
94
buf_flush_note_modification(
151
95
/*========================*/
152
 
        buf_block_t*    block,  /*!< in: block which is modified */
153
 
        mtr_t*          mtr);   /*!< in: mtr */
154
 
/********************************************************************//**
 
96
        buf_block_t*    block,  /* in: block which is modified */
 
97
        mtr_t*          mtr);   /* in: mtr */
 
98
/************************************************************************
155
99
This function should be called when recovery has modified a buffer page. */
156
100
UNIV_INLINE
157
101
void
158
102
buf_flush_recv_note_modification(
159
103
/*=============================*/
160
 
        buf_block_t*    block,          /*!< in: block which is modified */
161
 
        ib_uint64_t     start_lsn,      /*!< in: start lsn of the first mtr in a
162
 
                                        set of mtr's */
163
 
        ib_uint64_t     end_lsn);       /*!< in: end lsn of the last mtr in the
164
 
                                        set of mtr's */
165
 
/********************************************************************//**
 
104
        buf_block_t*    block,          /* in: block which is modified */
 
105
        ib_uint64_t     start_lsn,      /* in: start lsn of the first mtr in a
 
106
                                        set of mtr's */
 
107
        ib_uint64_t     end_lsn);       /* in: end lsn of the last mtr in the
 
108
                                        set of mtr's */
 
109
/************************************************************************
166
110
Returns TRUE if the file page block is immediately suitable for replacement,
167
 
i.e., transition FILE_PAGE => NOT_USED allowed.
168
 
@return TRUE if can replace immediately */
 
111
i.e., transition FILE_PAGE => NOT_USED allowed. */
169
112
UNIV_INTERN
170
113
ibool
171
114
buf_flush_ready_for_replace(
172
115
/*========================*/
173
 
        buf_page_t*     bpage); /*!< in: buffer control block, must be
 
116
                                /* out: TRUE if can replace immediately */
 
117
        buf_page_t*     bpage); /* in: buffer control block, must be
174
118
                                buf_page_in_file(bpage) and in the LRU list */
175
 
 
176
 
/** @brief Statistics for selecting flush rate based on redo log
177
 
generation speed.
178
 
 
179
 
These statistics are generated for heuristics used in estimating the
180
 
rate at which we should flush the dirty blocks to avoid bursty IO
181
 
activity. Note that the rate of flushing not only depends on how many
182
 
dirty pages we have in the buffer pool but it is also a fucntion of
183
 
how much redo the workload is generating and at what rate. */
184
 
 
185
 
struct buf_flush_stat_struct
186
 
{
187
 
        ib_uint64_t     redo;           /**< amount of redo generated. */
188
 
        ulint           n_flushed;      /**< number of pages flushed. */
189
 
};
190
 
 
191
 
/** Statistics for selecting flush rate of dirty pages. */
192
 
typedef struct buf_flush_stat_struct buf_flush_stat_t;
193
 
/*********************************************************************
194
 
Update the historical stats that we are collecting for flush rate
195
 
heuristics at the end of each interval. */
196
 
UNIV_INTERN
197
 
void
198
 
buf_flush_stat_update(void);
199
 
/*=======================*/
200
 
/*********************************************************************
201
 
Determines the fraction of dirty pages that need to be flushed based
202
 
on the speed at which we generate redo log. Note that if redo log
203
 
is generated at significant rate without a corresponding increase
204
 
in the number of dirty pages (for example, an in-memory workload)
205
 
it can cause IO bursts of flushing. This function implements heuristics
206
 
to avoid this burstiness.
207
 
@return number of dirty pages to be flushed / second */
208
 
UNIV_INTERN
209
 
ulint
210
 
buf_flush_get_desired_flush_rate(void);
211
 
/*==================================*/
212
 
 
213
119
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
214
 
/******************************************************************//**
215
 
Validates the flush list.
216
 
@return TRUE if ok */
 
120
/**********************************************************************
 
121
Validates the flush list. */
217
122
UNIV_INTERN
218
123
ibool
219
 
buf_flush_validate(
220
 
/*===============*/
221
 
        buf_pool_t*     buf_pool);
 
124
buf_flush_validate(void);
 
125
/*====================*/
 
126
                /* out: TRUE if ok */
222
127
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
223
128
 
224
 
/********************************************************************//**
225
 
Initialize the red-black tree to speed up insertions into the flush_list
226
 
during recovery process. Should be called at the start of recovery
227
 
process before any page has been read/written. */
228
 
UNIV_INTERN
229
 
void
230
 
buf_flush_init_flush_rbt(void);
231
 
/*==========================*/
232
 
 
233
 
/********************************************************************//**
234
 
Frees up the red-black tree. */
235
 
UNIV_INTERN
236
 
void
237
 
buf_flush_free_flush_rbt(void);
238
 
/*==========================*/
239
 
 
240
 
/** When buf_flush_free_margin is called, it tries to make this many blocks
 
129
/* When buf_flush_free_margin is called, it tries to make this many blocks
241
130
available to replacement in the free list and at the end of the LRU list (to
242
131
make sure that a read-ahead batch can be read efficiently in a single
243
132
sweep). */
244
 
#define BUF_FLUSH_FREE_BLOCK_MARGIN(b)  (5 + BUF_READ_AHEAD_AREA(b))
245
 
/** Extra margin to apply above BUF_FLUSH_FREE_BLOCK_MARGIN */
246
 
#define BUF_FLUSH_EXTRA_MARGIN(b)       ((BUF_FLUSH_FREE_BLOCK_MARGIN(b) / 4 \
247
 
                                        + 100) / srv_buf_pool_instances)
248
 
#endif /* !UNIV_HOTBACKUP */
 
133
 
 
134
#define BUF_FLUSH_FREE_BLOCK_MARGIN     (5 + BUF_READ_AHEAD_AREA)
 
135
#define BUF_FLUSH_EXTRA_MARGIN          (BUF_FLUSH_FREE_BLOCK_MARGIN / 4 + 100)
249
136
 
250
137
#ifndef UNIV_NONINL
251
138
#include "buf0flu.ic"