~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 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
16
 
35
 
/********************************************************************//**
 
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
/************************************************************************
36
25
Remove a block from the flush list of modified blocks. */
37
26
UNIV_INTERN
38
27
void
39
28
buf_flush_remove(
40
29
/*=============*/
41
 
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
42
 
/********************************************************************//**
 
30
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
31
/************************************************************************
43
32
Updates the flush system data structures when a write is completed. */
44
33
UNIV_INTERN
45
34
void
46
35
buf_flush_write_complete(
47
36
/*=====================*/
48
 
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
49
 
/*********************************************************************//**
 
37
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
38
/*************************************************************************
50
39
Flushes pages from the end of the LRU list if there is too small
51
40
a margin of replaceable pages there. */
52
41
UNIV_INTERN
53
42
void
54
43
buf_flush_free_margin(void);
55
44
/*=======================*/
56
 
#endif /* !UNIV_HOTBACKUP */
57
 
/********************************************************************//**
 
45
/************************************************************************
58
46
Initializes a page for writing to the tablespace. */
59
47
UNIV_INTERN
60
48
void
61
49
buf_flush_init_for_writing(
62
50
/*=======================*/
63
 
        byte*           page,           /*!< in/out: page */
64
 
        void*           page_zip_,      /*!< in/out: compressed page, or NULL */
65
 
        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
66
54
                                        to the page */
67
 
#ifndef UNIV_HOTBACKUP
68
 
/*******************************************************************//**
 
55
/***********************************************************************
69
56
This utility flushes dirty blocks from the end of the LRU list or flush_list.
70
57
NOTE 1: in the case of an LRU flush the calling thread may own latches to
71
58
pages: to avoid deadlocks, this function must be written so that it cannot
72
59
end up waiting for these latches! NOTE 2: in the case of a flush list flush,
73
 
the calling thread is not allowed to own any latches on pages!
74
 
@return number of blocks for which the write request was queued;
75
 
ULINT_UNDEFINED if there was a flush of the same type already running */
 
60
the calling thread is not allowed to own any latches on pages! */
76
61
UNIV_INTERN
77
62
ulint
78
63
buf_flush_batch(
79
64
/*============*/
80
 
        enum buf_flush  flush_type,     /*!< in: BUF_FLUSH_LRU or
 
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
81
70
                                        BUF_FLUSH_LIST; if BUF_FLUSH_LIST,
82
71
                                        then the caller must not own any
83
72
                                        latches on pages */
84
 
        ulint           min_n,          /*!< in: wished minimum mumber of blocks
 
73
        ulint           min_n,          /* in: wished minimum mumber of blocks
85
74
                                        flushed (it is not guaranteed that the
86
75
                                        actual number is that big, though) */
87
 
        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
88
77
                                        blocks whose oldest_modification is
89
78
                                        smaller than this should be flushed
90
79
                                        (if their number does not exceed
91
80
                                        min_n), otherwise ignored */
92
 
/******************************************************************//**
 
81
/**********************************************************************
93
82
Waits until a flush batch of the given type ends */
94
83
UNIV_INTERN
95
84
void
96
85
buf_flush_wait_batch_end(
97
86
/*=====================*/
98
 
        enum buf_flush  type);  /*!< in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
99
 
/********************************************************************//**
 
87
        enum buf_flush  type);  /* in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
 
88
/************************************************************************
100
89
This function should be called at a mini-transaction commit, if a page was
101
90
modified in it. Puts the block to the list of modified blocks, if it not
102
91
already in it. */
104
93
void
105
94
buf_flush_note_modification(
106
95
/*========================*/
107
 
        buf_block_t*    block,  /*!< in: block which is modified */
108
 
        mtr_t*          mtr);   /*!< in: mtr */
109
 
/********************************************************************//**
 
96
        buf_block_t*    block,  /* in: block which is modified */
 
97
        mtr_t*          mtr);   /* in: mtr */
 
98
/************************************************************************
110
99
This function should be called when recovery has modified a buffer page. */
111
100
UNIV_INLINE
112
101
void
113
102
buf_flush_recv_note_modification(
114
103
/*=============================*/
115
 
        buf_block_t*    block,          /*!< in: block which is modified */
116
 
        ib_uint64_t     start_lsn,      /*!< in: start lsn of the first mtr in a
117
 
                                        set of mtr's */
118
 
        ib_uint64_t     end_lsn);       /*!< in: end lsn of the last mtr in the
119
 
                                        set of mtr's */
120
 
/********************************************************************//**
 
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
/************************************************************************
121
110
Returns TRUE if the file page block is immediately suitable for replacement,
122
 
i.e., transition FILE_PAGE => NOT_USED allowed.
123
 
@return TRUE if can replace immediately */
 
111
i.e., transition FILE_PAGE => NOT_USED allowed. */
124
112
UNIV_INTERN
125
113
ibool
126
114
buf_flush_ready_for_replace(
127
115
/*========================*/
128
 
        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
129
118
                                buf_page_in_file(bpage) and in the LRU list */
130
 
 
131
 
/** @brief Statistics for selecting flush rate based on redo log
132
 
generation speed.
133
 
 
134
 
These statistics are generated for heuristics used in estimating the
135
 
rate at which we should flush the dirty blocks to avoid bursty IO
136
 
activity. Note that the rate of flushing not only depends on how many
137
 
dirty pages we have in the buffer pool but it is also a fucntion of
138
 
how much redo the workload is generating and at what rate. */
139
 
 
140
 
struct buf_flush_stat_struct
141
 
{
142
 
        ib_uint64_t     redo;           /**< amount of redo generated. */
143
 
        ulint           n_flushed;      /**< number of pages flushed. */
144
 
};
145
 
 
146
 
/** Statistics for selecting flush rate of dirty pages. */
147
 
typedef struct buf_flush_stat_struct buf_flush_stat_t;
148
 
/*********************************************************************
149
 
Update the historical stats that we are collecting for flush rate
150
 
heuristics at the end of each interval. */
151
 
UNIV_INTERN
152
 
void
153
 
buf_flush_stat_update(void);
154
 
/*=======================*/
155
 
/*********************************************************************
156
 
Determines the fraction of dirty pages that need to be flushed based
157
 
on the speed at which we generate redo log. Note that if redo log
158
 
is generated at significant rate without a corresponding increase
159
 
in the number of dirty pages (for example, an in-memory workload)
160
 
it can cause IO bursts of flushing. This function implements heuristics
161
 
to avoid this burstiness.
162
 
@return number of dirty pages to be flushed / second */
163
 
UNIV_INTERN
164
 
ulint
165
 
buf_flush_get_desired_flush_rate(void);
166
 
/*==================================*/
167
 
 
168
119
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
169
 
/******************************************************************//**
170
 
Validates the flush list.
171
 
@return TRUE if ok */
 
120
/**********************************************************************
 
121
Validates the flush list. */
172
122
UNIV_INTERN
173
123
ibool
174
124
buf_flush_validate(void);
175
125
/*====================*/
 
126
                /* out: TRUE if ok */
176
127
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
177
128
 
178
 
/** 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
179
130
available to replacement in the free list and at the end of the LRU list (to
180
131
make sure that a read-ahead batch can be read efficiently in a single
181
132
sweep). */
 
133
 
182
134
#define BUF_FLUSH_FREE_BLOCK_MARGIN     (5 + BUF_READ_AHEAD_AREA)
183
 
/** Extra margin to apply above BUF_FLUSH_FREE_BLOCK_MARGIN */
184
135
#define BUF_FLUSH_EXTRA_MARGIN          (BUF_FLUSH_FREE_BLOCK_MARGIN / 4 + 100)
185
 
#endif /* !UNIV_HOTBACKUP */
186
136
 
187
137
#ifndef UNIV_NONINL
188
138
#include "buf0flu.ic"