~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/buf0buf.h

  • Committer: Monty Taylor
  • Date: 2010-10-13 17:53:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1845.
  • Revision ID: mordred@inaugust.com-20101013175336-amzhjftgztblvua5
Updated pandora-build files to version 0.161

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
34
34
#include "ut0byte.h"
35
35
#include "page0types.h"
36
36
#ifndef UNIV_HOTBACKUP
37
 
#include "ut0rbt.h"
38
37
#include "os0proc.h"
39
38
 
40
39
/** @name Modes for buf_page_get_gen */
47
46
                                        it is error-prone programming
48
47
                                        not to set a latch, and it
49
48
                                        should be used with care */
50
 
#define BUF_GET_IF_IN_POOL_OR_WATCH     15
51
 
                                        /*!< Get the page only if it's in the
52
 
                                        buffer pool, if not then set a watch
53
 
                                        on the page. */
54
49
/* @} */
55
50
/** @name Modes for buf_page_get_known_nowait */
56
51
/* @{ */
63
58
                                        position of the block. */
64
59
/* @} */
65
60
 
66
 
#define MAX_BUFFER_POOLS 64             /*!< The maximum number of buffer
67
 
                                        pools that can be defined */
68
 
 
69
 
#define BUF_POOL_WATCH_SIZE 1           /*!< Maximum number of concurrent
70
 
                                        buffer pool watches */
71
 
 
72
 
extern  buf_pool_t*     buf_pool_ptr[MAX_BUFFER_POOLS]; /*!< The buffer pools
73
 
                                        of the database */
 
61
extern buf_pool_t*      buf_pool;       /*!< The buffer pool of the database */
74
62
#ifdef UNIV_DEBUG
75
63
extern ibool            buf_debug_prints;/*!< If this is set TRUE, the program
76
64
                                        prints info whenever read or flush
91
79
enum buf_page_state {
92
80
        BUF_BLOCK_ZIP_FREE = 0,         /*!< contains a free
93
81
                                        compressed page */
94
 
        BUF_BLOCK_POOL_WATCH = 0,       /*!< a sentinel for the buffer pool
95
 
                                        watch, element of buf_pool_watch[] */
96
82
        BUF_BLOCK_ZIP_PAGE,             /*!< contains a clean
97
83
                                        compressed page */
98
84
        BUF_BLOCK_ZIP_DIRTY,            /*!< contains a compressed
114
100
 
115
101
#ifndef UNIV_HOTBACKUP
116
102
/********************************************************************//**
117
 
Acquire mutex on all buffer pool instances */
118
 
UNIV_INLINE
119
 
void
120
 
buf_pool_mutex_enter_all(void);
121
 
/*===========================*/
122
 
 
123
 
/********************************************************************//**
124
 
Release mutex on all buffer pool instances */
125
 
UNIV_INLINE
126
 
void
127
 
buf_pool_mutex_exit_all(void);
128
 
/*==========================*/
129
 
 
130
 
/********************************************************************//**
131
103
Creates the buffer pool.
132
104
@return own: buf_pool object, NULL if not enough memory or error */
133
105
UNIV_INTERN
134
 
ulint
135
 
buf_pool_init(
136
 
/*=========*/
137
 
        ulint   size,           /*!< in: Size of the total pool in bytes */
138
 
        ulint   n_instances);   /*!< in: Number of instances */
 
106
buf_pool_t*
 
107
buf_pool_init(void);
 
108
/*===============*/
139
109
/********************************************************************//**
140
110
Frees the buffer pool at shutdown.  This must not be invoked before
141
111
freeing all mutexes. */
142
112
UNIV_INTERN
143
113
void
144
 
buf_pool_free(
145
 
/*==========*/
146
 
        ulint   n_instances);   /*!< in: numbere of instances to free */
 
114
buf_pool_free(void);
 
115
/*===============*/
147
116
 
148
117
/********************************************************************//**
149
118
Drops the adaptive hash index.  To prevent a livelock, this function
180
149
ulint
181
150
buf_pool_get_curr_size(void);
182
151
/*========================*/
183
 
/*********************************************************************//**
184
 
Gets the current size of buffer buf_pool in frames.
185
 
@return size in pages */
186
 
UNIV_INLINE
187
 
ulint
188
 
buf_pool_get_n_pages(void);
189
 
/*=======================*/
190
152
/********************************************************************//**
191
153
Gets the smallest oldest_modification lsn for any page in the pool. Returns
192
154
zero if all modified pages have been flushed to disk.
193
155
@return oldest modification in pool, zero if none */
194
 
UNIV_INTERN
 
156
UNIV_INLINE
195
157
ib_uint64_t
196
158
buf_pool_get_oldest_modification(void);
197
159
/*==================================*/
198
160
/********************************************************************//**
199
161
Allocates a buffer block.
200
162
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
201
 
UNIV_INTERN
 
163
UNIV_INLINE
202
164
buf_block_t*
203
165
buf_block_alloc(
204
166
/*============*/
205
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
206
 
        ulint           zip_size);      /*!< in: compressed page size in bytes,
207
 
                                        or 0 if uncompressed tablespace */
 
167
        ulint   zip_size);      /*!< in: compressed page size in bytes,
 
168
                                or 0 if uncompressed tablespace */
208
169
/********************************************************************//**
209
170
Frees a buffer block which does not contain a file page. */
210
171
UNIV_INLINE
239
200
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR)        buf_page_get_gen(\
240
201
                                SP, ZS, OF, RW_NO_LATCH, NULL,\
241
202
                                BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
 
203
/**************************************************************//**
 
204
NOTE! The following macros should be used instead of
 
205
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
 
206
RW_X_LATCH are allowed as LA! */
 
207
#define buf_page_optimistic_get(LA, BL, MC, MTR)                             \
 
208
        buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
242
209
/********************************************************************//**
243
210
This is the general function used to get optimistic access to a database
244
211
page.
245
212
@return TRUE if success */
246
213
UNIV_INTERN
247
214
ibool
248
 
buf_page_optimistic_get(
249
 
/*====================*/
 
215
buf_page_optimistic_get_func(
 
216
/*=========================*/
250
217
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
251
218
        buf_block_t*    block,  /*!< in: guessed block */
252
219
        ib_uint64_t     modify_clock,/*!< in: modify clock value if mode is
322
289
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
323
290
        buf_block_t*    guess,  /*!< in: guessed block or NULL */
324
291
        ulint           mode,   /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
325
 
                                BUF_GET_NO_LATCH or
326
 
                                BUF_GET_IF_IN_POOL_OR_WATCH */
 
292
                                BUF_GET_NO_LATCH */
327
293
        const char*     file,   /*!< in: file name */
328
294
        ulint           line,   /*!< in: line where called */
329
295
        mtr_t*          mtr);   /*!< in: mini-transaction */
373
339
buf_page_release(
374
340
/*=============*/
375
341
        buf_block_t*    block,          /*!< in: buffer block */
376
 
        ulint           rw_latch);      /*!< in: RW_S_LATCH, RW_X_LATCH,
 
342
        ulint           rw_latch,       /*!< in: RW_S_LATCH, RW_X_LATCH,
377
343
                                        RW_NO_LATCH */
 
344
        mtr_t*          mtr);           /*!< in: mtr */
378
345
/********************************************************************//**
379
346
Moves a page to the start of the buffer pool LRU list. This high-level
380
 
function can be used to prevent an important page from slipping out of
 
347
function can be used to prevent an important page from from slipping out of
381
348
the buffer pool. */
382
349
UNIV_INTERN
383
350
void
484
451
                                        page frame */
485
452
/********************************************************************//**
486
453
Increments the modify clock of a frame by 1. The caller must (1) own the
487
 
buf_pool->mutex and block bufferfix count has to be zero, (2) or own an x-lock
 
454
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
488
455
on the block. */
489
456
UNIV_INLINE
490
457
void
566
533
buf_block_t*
567
534
buf_pool_contains_zip(
568
535
/*==================*/
569
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
570
 
        const void*     data);          /*!< in: pointer to compressed page */
 
536
        const void*     data);  /*!< in: pointer to compressed page */
571
537
#endif /* UNIV_DEBUG */
572
538
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
573
539
/*********************************************************************//**
641
607
Refreshes the statistics used to print per-second averages. */
642
608
UNIV_INTERN
643
609
void
644
 
buf_refresh_io_stats(
645
 
/*=================*/
646
 
        buf_pool_t*     buf_pool);      /*!< buffer pool instance */
647
 
/**********************************************************************//**
648
 
Refreshes the statistics used to print per-second averages. */
649
 
UNIV_INTERN
650
 
void
651
 
buf_refresh_io_stats_all(void);
652
 
/*=================*/
 
610
buf_refresh_io_stats(void);
 
611
/*======================*/
653
612
/*********************************************************************//**
654
613
Asserts that all file pages in the buffer are in a replaceable state.
655
614
@return TRUE */
746
705
/*==========================*/
747
706
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
748
707
        __attribute__((pure));
 
708
/*********************************************************************//**
 
709
Determine the approximate LRU list position of a block.
 
710
@return LRU list position */
 
711
UNIV_INLINE
 
712
ulint
 
713
buf_page_get_LRU_position(
 
714
/*======================*/
 
715
        const buf_page_t*       bpage)  /*!< in: control block */
 
716
        __attribute__((pure));
749
717
 
750
718
/*********************************************************************//**
751
719
Gets the mutex of a block.
846
814
        buf_page_t*     bpage,  /*!< in/out: control block */
847
815
        ibool           old);   /*!< in: old */
848
816
/*********************************************************************//**
849
 
Determine the time of first access of a block in the buffer pool.
850
 
@return ut_time_ms() at the time of first access, 0 if not accessed */
 
817
Determine if a block has been accessed in the buffer pool.
 
818
@return TRUE if accessed */
851
819
UNIV_INLINE
852
 
unsigned
 
820
ibool
853
821
buf_page_is_accessed(
854
822
/*=================*/
855
823
        const buf_page_t*       bpage)  /*!< in: control block */
856
 
        __attribute__((nonnull, pure));
 
824
        __attribute__((pure));
857
825
/*********************************************************************//**
858
826
Flag a block accessed. */
859
827
UNIV_INLINE
861
829
buf_page_set_accessed(
862
830
/*==================*/
863
831
        buf_page_t*     bpage,          /*!< in/out: control block */
864
 
        ulint           time_ms)        /*!< in: ut_time_ms() */
865
 
        __attribute__((nonnull));
 
832
        ibool           accessed);      /*!< in: accessed */
866
833
/*********************************************************************//**
867
834
Gets the buf_block_t handle of a buffered file block if an uncompressed
868
 
page frame exists, or NULL. Note: even though bpage is not declared a
869
 
const we don't update its value. It is safe to make this pure.
 
835
page frame exists, or NULL.
870
836
@return control block, or NULL */
871
837
UNIV_INLINE
872
838
buf_block_t*
1031
997
        ulint   offset) /*!< in: offset of the page within space */
1032
998
        __attribute__((const));
1033
999
/******************************************************************//**
1034
 
Returns the buffer pool instance given a page instance
1035
 
@return buf_pool */
1036
 
UNIV_INLINE
1037
 
buf_pool_t*
1038
 
buf_pool_from_bpage(
1039
 
/*================*/
1040
 
        const buf_page_t*       bpage); /*!< in: buffer pool page */
1041
 
/******************************************************************//**
1042
 
Returns the buffer pool instance given a block instance
1043
 
@return buf_pool */
1044
 
UNIV_INLINE
1045
 
buf_pool_t*
1046
 
buf_pool_from_block(
1047
 
/*================*/
1048
 
        const buf_block_t*      block); /*!< in: block */
1049
 
/******************************************************************//**
1050
 
Returns the buffer pool instance given space and offset of page
1051
 
@return buffer pool */
1052
 
UNIV_INLINE
1053
 
buf_pool_t*
1054
 
buf_pool_get(
1055
 
/*==========*/
1056
 
        ulint   space,  /*!< in: space id */
1057
 
        ulint   offset);/*!< in: offset of the page within space */
1058
 
/******************************************************************//**
1059
 
Returns the buffer pool instance given its array index
1060
 
@return buffer pool */
1061
 
UNIV_INLINE
1062
 
buf_pool_t*
1063
 
buf_pool_from_array(
1064
 
/*====================*/
1065
 
        ulint   index); /*!< in: array index to get buffer pool instance from */
1066
 
/******************************************************************//**
1067
1000
Returns the control block of a file page, NULL if not found.
1068
1001
@return block, NULL if not found */
1069
1002
UNIV_INLINE
1070
1003
buf_page_t*
1071
 
buf_page_hash_get_low(
1072
 
/*==================*/
1073
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
1074
 
        ulint           space,          /*!< in: space id */
1075
 
        ulint           offset,         /*!< in: offset of the page
1076
 
                                        within space */
1077
 
        ulint           fold);          /*!< in: buf_page_address_fold(
1078
 
                                        space, offset) */
1079
 
/******************************************************************//**
1080
 
Returns the control block of a file page, NULL if not found.
1081
 
@return block, NULL if not found or not a real control block */
1082
 
UNIV_INLINE
1083
 
buf_page_t*
1084
1004
buf_page_hash_get(
1085
1005
/*==============*/
1086
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1087
 
        ulint           space,          /*!< in: space id */
1088
 
        ulint           offset);        /*!< in: offset of the page
1089
 
                                        within space */
 
1006
        ulint   space,  /*!< in: space id */
 
1007
        ulint   offset);/*!< in: offset of the page within space */
1090
1008
/******************************************************************//**
1091
1009
Returns the control block of a file page, NULL if not found
1092
1010
or an uncompressed page frame does not exist.
1095
1013
buf_block_t*
1096
1014
buf_block_hash_get(
1097
1015
/*===============*/
1098
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1099
 
        ulint           space,          /*!< in: space id */
1100
 
        ulint           offset);        /*!< in: offset of the page
1101
 
                                        within space */
 
1016
        ulint   space,  /*!< in: space id */
 
1017
        ulint   offset);/*!< in: offset of the page within space */
 
1018
/*******************************************************************//**
 
1019
Increments the pool clock by one and returns its new value. Remember that
 
1020
in the 32 bit version the clock wraps around at 4 billion!
 
1021
@return new clock value */
 
1022
UNIV_INLINE
 
1023
ulint
 
1024
buf_pool_clock_tic(void);
 
1025
/*====================*/
1102
1026
/*********************************************************************//**
1103
1027
Gets the current length of the free list of buffer blocks.
1104
1028
@return length of the free list */
1106
1030
ulint
1107
1031
buf_get_free_list_len(void);
1108
1032
/*=======================*/
1109
 
 
1110
 
/********************************************************************
1111
 
Determine if a block is a sentinel for a buffer pool watch.
1112
 
@return TRUE if a sentinel for a buffer pool watch, FALSE if not */
1113
 
UNIV_INTERN
1114
 
ibool
1115
 
buf_pool_watch_is_sentinel(
1116
 
/*=======================*/
1117
 
        buf_pool_t*             buf_pool,       /*!< buffer pool instance */
1118
 
        const buf_page_t*       bpage)          /*!< in: block */
1119
 
  UNIV_WARN_UNUSED_RESULT;
1120
 
/****************************************************************//**
1121
 
Add watch for the given page to be read in. Caller must have the buffer pool
1122
 
@return NULL if watch set, block if the page is in the buffer pool */
1123
 
UNIV_INTERN
1124
 
buf_page_t*
1125
 
buf_pool_watch_set(
1126
 
/*===============*/
1127
 
        ulint   space,  /*!< in: space id */
1128
 
        ulint   offset, /*!< in: page number */
1129
 
        ulint   fold)   /*!< in: buf_page_address_fold(space, offset) */
1130
 
  UNIV_WARN_UNUSED_RESULT;
1131
 
/****************************************************************//**
1132
 
Stop watching if the page has been read in.
1133
 
buf_pool_watch_set(space,offset) must have returned NULL before. */
1134
 
UNIV_INTERN
1135
 
void
1136
 
buf_pool_watch_unset(
1137
 
/*=================*/
1138
 
        ulint   space,  /*!< in: space id */
1139
 
        ulint   offset);/*!< in: page number */
1140
 
/****************************************************************//**
1141
 
Check if the page has been read in.
1142
 
This may only be called after buf_pool_watch_set(space,offset)
1143
 
has returned NULL and before invoking buf_pool_watch_unset(space,offset).
1144
 
@return FALSE if the given page was not read in, TRUE if it was */
1145
 
UNIV_INTERN
1146
 
ibool
1147
 
buf_pool_watch_occurred(
1148
 
/*====================*/
1149
 
        ulint   space,  /*!< in: space id */
1150
 
        ulint   offset) /*!< in: page number */
1151
 
  UNIV_WARN_UNUSED_RESULT;
1152
 
/********************************************************************//**
1153
 
Get total buffer pool statistics. */
1154
 
UNIV_INTERN
1155
 
void
1156
 
buf_get_total_list_len(
1157
 
/*===================*/
1158
 
        ulint*          LRU_len,        /*!< out: length of all LRU lists */
1159
 
        ulint*          free_len,       /*!< out: length of all free lists */
1160
 
        ulint*          flush_list_len);/*!< out: length of all flush lists */
1161
 
/********************************************************************//**
1162
 
Get total buffer pool statistics. */
1163
 
UNIV_INTERN
1164
 
void
1165
 
buf_get_total_stat(
1166
 
/*===============*/
1167
 
        buf_pool_stat_t*tot_stat);      /*!< out: buffer pool stats */
1168
 
 
1169
1033
#endif /* !UNIV_HOTBACKUP */
1170
1034
 
 
1035
 
1171
1036
/** The common buffer control block structure
1172
1037
for compressed and uncompressed frames */
1173
1038
 
1175
1040
        /** @name General fields
1176
1041
        None of these bit-fields must be modified without holding
1177
1042
        buf_page_get_mutex() [buf_block_struct::mutex or
1178
 
        buf_pool->zip_mutex], since they can be stored in the same
 
1043
        buf_pool_zip_mutex], since they can be stored in the same
1179
1044
        machine word.  Some of these fields are additionally protected
1180
 
        by buf_pool->mutex. */
 
1045
        by buf_pool_mutex. */
1181
1046
        /* @{ */
1182
1047
 
1183
1048
        unsigned        space:32;       /*!< tablespace id; also protected
1184
 
                                        by buf_pool->mutex. */
 
1049
                                        by buf_pool_mutex. */
1185
1050
        unsigned        offset:32;      /*!< page number; also protected
1186
 
                                        by buf_pool->mutex. */
 
1051
                                        by buf_pool_mutex. */
1187
1052
 
1188
1053
        unsigned        state:3;        /*!< state of the control block; also
1189
 
                                        protected by buf_pool->mutex.
 
1054
                                        protected by buf_pool_mutex.
1190
1055
                                        State transitions from
1191
1056
                                        BUF_BLOCK_READY_FOR_USE to
1192
1057
                                        BUF_BLOCK_MEMORY need not be
1197
1062
                                        flushed to disk, this tells the
1198
1063
                                        flush_type.
1199
1064
                                        @see enum buf_flush */
 
1065
        unsigned        accessed:1;     /*!< TRUE if the page has been accessed
 
1066
                                        while in the buffer pool: read-ahead
 
1067
                                        may read in pages which have not been
 
1068
                                        accessed yet; a thread is allowed to
 
1069
                                        read this for heuristic purposes
 
1070
                                        without holding any mutex or latch */
1200
1071
        unsigned        io_fix:2;       /*!< type of pending I/O operation;
1201
 
                                        also protected by buf_pool->mutex
 
1072
                                        also protected by buf_pool_mutex
1202
1073
                                        @see enum buf_io_fix */
1203
 
        unsigned        buf_fix_count:25;/*!< count of how manyfold this block
 
1074
        unsigned        buf_fix_count:24;/*!< count of how manyfold this block
1204
1075
                                        is currently bufferfixed */
1205
1076
        /* @} */
1206
1077
#endif /* !UNIV_HOTBACKUP */
1207
1078
        page_zip_des_t  zip;            /*!< compressed page; zip.data
1208
1079
                                        (but not the data it points to) is
1209
 
                                        also protected by buf_pool_mutex;
1210
 
                                        state == BUF_BLOCK_ZIP_PAGE and
1211
 
                                        zip.data == NULL means an active
1212
 
                                        buf_pool_watch */
 
1080
                                        also protected by buf_pool_mutex */
1213
1081
#ifndef UNIV_HOTBACKUP
1214
1082
        buf_page_t*     hash;           /*!< node used in chaining to
1215
1083
                                        buf_pool->page_hash or
1225
1093
 
1226
1094
        UT_LIST_NODE_T(buf_page_t) list;
1227
1095
                                        /*!< based on state, this is a
1228
 
                                        list node, protected either by
1229
 
                                        buf_pool_mutex or by
1230
 
                                        flush_list_mutex, in one of the
 
1096
                                        list node, protected only by
 
1097
                                        buf_pool_mutex, in one of the
1231
1098
                                        following lists in buf_pool:
1232
1099
 
1233
1100
                                        - BUF_BLOCK_NOT_USED:   free
1234
1101
                                        - BUF_BLOCK_FILE_PAGE:  flush_list
1235
1102
                                        - BUF_BLOCK_ZIP_DIRTY:  flush_list
1236
1103
                                        - BUF_BLOCK_ZIP_PAGE:   zip_clean
1237
 
                                        - BUF_BLOCK_ZIP_FREE:   zip_free[]
1238
 
 
1239
 
                                        If bpage is part of flush_list
1240
 
                                        then the node pointers are
1241
 
                                        covered by flush_list_mutex.
1242
 
                                        Otherwise these pointers are
1243
 
                                        protected by buf_pool_mutex.
1244
 
 
1245
 
                                        The contents of the list node
1246
 
                                        is undefined if !in_flush_list
1247
 
                                        && state == BUF_BLOCK_FILE_PAGE,
1248
 
                                        or if state is one of
1249
 
                                        BUF_BLOCK_MEMORY,
1250
 
                                        BUF_BLOCK_REMOVE_HASH or
1251
 
                                        BUF_BLOCK_READY_IN_USE. */
1252
 
 
 
1104
                                        - BUF_BLOCK_ZIP_FREE:   zip_free[] */
1253
1105
#ifdef UNIV_DEBUG
1254
1106
        ibool           in_flush_list;  /*!< TRUE if in buf_pool->flush_list;
1255
 
                                        when flush_list_mutex is free, the
 
1107
                                        when buf_pool_mutex is free, the
1256
1108
                                        following should hold: in_flush_list
1257
1109
                                        == (state == BUF_BLOCK_FILE_PAGE
1258
 
                                            || state == BUF_BLOCK_ZIP_DIRTY)
1259
 
                                        Writes to this field must be
1260
 
                                        covered by both block->mutex
1261
 
                                        and flush_list_mutex. Hence
1262
 
                                        reads can happen while holding
1263
 
                                        any one of the two mutexes */
 
1110
                                            || state == BUF_BLOCK_ZIP_DIRTY) */
1264
1111
        ibool           in_free_list;   /*!< TRUE if in buf_pool->free; when
1265
1112
                                        buf_pool_mutex is free, the following
1266
1113
                                        should hold: in_free_list
1270
1117
                                        /*!< log sequence number of
1271
1118
                                        the youngest modification to
1272
1119
                                        this block, zero if not
1273
 
                                        modified. Protected by block
1274
 
                                        mutex */
 
1120
                                        modified */
1275
1121
        ib_uint64_t     oldest_modification;
1276
1122
                                        /*!< log sequence number of
1277
1123
                                        the START of the log entry
1279
1125
                                        modification to this block
1280
1126
                                        which has not yet been flushed
1281
1127
                                        on disk; zero if all
1282
 
                                        modifications are on disk.
1283
 
                                        Writes to this field must be
1284
 
                                        covered by both block->mutex
1285
 
                                        and flush_list_mutex. Hence
1286
 
                                        reads can happen while holding
1287
 
                                        any one of the two mutexes */
 
1128
                                        modifications are on disk */
1288
1129
        /* @} */
1289
1130
        /** @name LRU replacement algorithm fields
1290
 
        These fields are protected by buf_pool->mutex only (not
1291
 
        buf_pool->zip_mutex or buf_block_struct::mutex). */
 
1131
        These fields are protected by buf_pool_mutex only (not
 
1132
        buf_pool_zip_mutex or buf_block_struct::mutex). */
1292
1133
        /* @{ */
1293
1134
 
1294
1135
        UT_LIST_NODE_T(buf_page_t) LRU;
1299
1140
                                        debugging */
1300
1141
#endif /* UNIV_DEBUG */
1301
1142
        unsigned        old:1;          /*!< TRUE if the block is in the old
1302
 
                                        blocks in buf_pool->LRU_old */
1303
 
        unsigned        freed_page_clock:31;/*!< the value of
 
1143
                                        blocks in the LRU list */
 
1144
        unsigned        LRU_position:31;/*!< value which monotonically
 
1145
                                        decreases (or may stay
 
1146
                                        constant if old==TRUE) toward
 
1147
                                        the end of the LRU list, if
 
1148
                                        buf_pool->ulint_clock has not
 
1149
                                        wrapped around: NOTE that this
 
1150
                                        value can only be used in
 
1151
                                        heuristic algorithms, because
 
1152
                                        of the possibility of a
 
1153
                                        wrap-around! */
 
1154
        unsigned        freed_page_clock:32;/*!< the value of
1304
1155
                                        buf_pool->freed_page_clock
1305
1156
                                        when this block was the last
1306
1157
                                        time put to the head of the
1308
1159
                                        to read this for heuristic
1309
1160
                                        purposes without holding any
1310
1161
                                        mutex or latch */
1311
 
        unsigned        access_time:32; /*!< time of first access, or
1312
 
                                        0 if the block was never accessed
1313
 
                                        in the buffer pool */
1314
1162
        /* @} */
1315
1163
# ifdef UNIV_DEBUG_FILE_ACCESSES
1316
1164
        ibool           file_page_was_freed;
1318
1166
                                        frees a page in buffer pool */
1319
1167
# endif /* UNIV_DEBUG_FILE_ACCESSES */
1320
1168
#endif /* !UNIV_HOTBACKUP */
1321
 
        buf_pool_t*     buf_pool;       /*!< buffer pool instance this
1322
 
                                        page belongs to */
1323
1169
};
1324
1170
 
1325
1171
/** The buffer control block structure */
1357
1203
        rw_lock_t       lock;           /*!< read-write lock of the buffer
1358
1204
                                        frame */
1359
1205
        unsigned        lock_hash_val:32;/*!< hashed value of the page address
1360
 
                                        in the record lock hash table;
1361
 
                                        protected by buf_block_t::lock
1362
 
                                        (or buf_block_t::mutex, buf_pool->mutex
1363
 
                                        in buf_page_get_gen(),
1364
 
                                        buf_page_init_for_read()
1365
 
                                        and buf_page_create()) */
1366
 
        ibool           check_index_page_at_flush;
 
1206
                                        in the record lock hash table */
 
1207
        unsigned        check_index_page_at_flush:1;
1367
1208
                                        /*!< TRUE if we know that this is
1368
1209
                                        an index page, and want the database
1369
1210
                                        to check its consistency before flush;
1370
1211
                                        note that there may be pages in the
1371
1212
                                        buffer pool which are index pages,
1372
1213
                                        but this flag is not set because
1373
 
                                        we do not keep track of all pages;
1374
 
                                        NOT protected by any mutex */
 
1214
                                        we do not keep track of all pages */
1375
1215
        /* @} */
1376
1216
        /** @name Optimistic search field */
1377
1217
        /* @{ */
1463
1303
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1464
1304
/* @} */
1465
1305
 
1466
 
/** @brief The buffer pool statistics structure. */
1467
 
struct buf_pool_stat_struct{
1468
 
        ulint   n_page_gets;    /*!< number of page gets performed;
1469
 
                                also successful searches through
1470
 
                                the adaptive hash index are
1471
 
                                counted as page gets; this field
1472
 
                                is NOT protected by the buffer
1473
 
                                pool mutex */
1474
 
        ulint   n_pages_read;   /*!< number read operations */
1475
 
        ulint   n_pages_written;/*!< number write operations */
1476
 
        ulint   n_pages_created;/*!< number of pages created
1477
 
                                in the pool with no read */
1478
 
        ulint   n_ra_pages_read;/*!< number of pages read in
1479
 
                                as part of read ahead */
1480
 
        ulint   n_ra_pages_evicted;/*!< number of read ahead
1481
 
                                pages that are evicted without
1482
 
                                being accessed */
1483
 
        ulint   n_pages_made_young; /*!< number of pages made young, in
1484
 
                                calls to buf_LRU_make_block_young() */
1485
 
        ulint   n_pages_not_made_young; /*!< number of pages not made
1486
 
                                young because the first access
1487
 
                                was not long enough ago, in
1488
 
                                buf_page_peek_if_too_old() */
1489
 
};
1490
 
 
1491
 
/** Statistics of buddy blocks of a given size. */
1492
 
struct buf_buddy_stat_struct {
1493
 
        /** Number of blocks allocated from the buddy system. */
1494
 
        ulint           used;
1495
 
        /** Number of blocks relocated by the buddy system. */
1496
 
        ib_uint64_t     relocated;
1497
 
        /** Total duration of block relocations, in microseconds. */
1498
 
        ib_uint64_t     relocated_usec;
1499
 
};
1500
 
 
1501
1306
/** @brief The buffer pool structure.
1502
1307
 
1503
1308
NOTE! The definition appears here only for other modules of this
1507
1312
 
1508
1313
        /** @name General fields */
1509
1314
        /* @{ */
1510
 
        mutex_t         mutex;          /*!< Buffer pool mutex of this
1511
 
                                        instance */
1512
 
        mutex_t         zip_mutex;      /*!< Zip mutex of this buffer
1513
 
                                        pool instance, protects compressed
1514
 
                                        only pages (of type buf_page_t, not
1515
 
                                        buf_block_t */
1516
 
        ulint           instance_no;    /*!< Array index of this buffer
1517
 
                                        pool instance */
1518
 
        ulint           old_pool_size;  /*!< Old pool size in bytes */
1519
 
        ulint           curr_pool_size; /*!< Current pool size in bytes */
1520
 
        ulint           LRU_old_ratio;  /*!< Reserve this much of the buffer
1521
 
                                        pool for "old" blocks */
1522
 
#ifdef UNIV_DEBUG
1523
 
        ulint           buddy_n_frames; /*!< Number of frames allocated from
1524
 
                                        the buffer pool to the buddy system */
1525
 
#endif
1526
 
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1527
 
        ulint           mutex_exit_forbidden; /*!< Forbid release mutex */
1528
 
#endif
 
1315
 
1529
1316
        ulint           n_chunks;       /*!< number of buffer pool chunks */
1530
1317
        buf_chunk_t*    chunks;         /*!< buffer pool chunks */
1531
1318
        ulint           curr_size;      /*!< current pool size in pages */
1537
1324
                                        whose frames are allocated to the
1538
1325
                                        zip buddy system,
1539
1326
                                        indexed by block->frame */
1540
 
        ulint           n_pend_reads;   /*!< number of pending read
1541
 
                                        operations */
 
1327
        ulint           n_pend_reads;   /*!< number of pending read operations */
1542
1328
        ulint           n_pend_unzip;   /*!< number of pending decompressions */
1543
1329
 
1544
 
        time_t          last_printout_time;
1545
 
                                        /*!< when buf_print_io was last time
 
1330
        time_t          last_printout_time; /*!< when buf_print was last time
1546
1331
                                        called */
1547
 
        buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES + 1];
1548
 
                                        /*!< Statistics of buddy system,
1549
 
                                        indexed by block size */
1550
 
        buf_pool_stat_t stat;           /*!< current statistics */
1551
 
        buf_pool_stat_t old_stat;       /*!< old statistics */
1552
 
 
 
1332
        ulint           n_pages_read;   /*!< number read operations */
 
1333
        ulint           n_pages_written;/*!< number write operations */
 
1334
        ulint           n_pages_created;/*!< number of pages created
 
1335
                                        in the pool with no read */
 
1336
        ulint           n_page_gets;    /*!< number of page gets performed;
 
1337
                                        also successful searches through
 
1338
                                        the adaptive hash index are
 
1339
                                        counted as page gets; this field
 
1340
                                        is NOT protected by the buffer
 
1341
                                        pool mutex */
 
1342
        ulint           n_page_gets_old;/*!< n_page_gets when buf_print was
 
1343
                                        last time called: used to calculate
 
1344
                                        hit rate */
 
1345
        ulint           n_pages_read_old;/*!< n_pages_read when buf_print was
 
1346
                                        last time called */
 
1347
        ulint           n_pages_written_old;/*!< number write operations */
 
1348
        ulint           n_pages_created_old;/*!< number of pages created in
 
1349
                                        the pool with no read */
1553
1350
        /* @} */
1554
 
 
1555
1351
        /** @name Page flushing algorithm fields */
1556
 
 
1557
1352
        /* @{ */
1558
1353
 
1559
 
        mutex_t         flush_list_mutex;/*!< mutex protecting the
1560
 
                                        flush list access. This mutex
1561
 
                                        protects flush_list, flush_rbt
1562
 
                                        and bpage::list pointers when
1563
 
                                        the bpage is on flush_list. It
1564
 
                                        also protects writes to
1565
 
                                        bpage::oldest_modification */
1566
1354
        UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1567
1355
                                        /*!< base node of the modified block
1568
1356
                                        list */
1576
1364
                                        /*!< this is in the set state
1577
1365
                                        when there is no flush batch
1578
1366
                                        of the given type running */
1579
 
        ib_rbt_t*       flush_rbt;      /*!< a red-black tree is used
1580
 
                                        exclusively during recovery to
1581
 
                                        speed up insertions in the
1582
 
                                        flush_list. This tree contains
1583
 
                                        blocks in order of
1584
 
                                        oldest_modification LSN and is
1585
 
                                        kept in sync with the
1586
 
                                        flush_list.
1587
 
                                        Each member of the tree MUST
1588
 
                                        also be on the flush_list.
1589
 
                                        This tree is relevant only in
1590
 
                                        recovery and is set to NULL
1591
 
                                        once the recovery is over.
1592
 
                                        Protected by flush_list_mutex */
 
1367
        ulint           ulint_clock;    /*!< a sequence number used to count
 
1368
                                        time. NOTE! This counter wraps
 
1369
                                        around at 4 billion (if ulint ==
 
1370
                                        32 bits)! */
1593
1371
        ulint           freed_page_clock;/*!< a sequence number used
1594
1372
                                        to count the number of buffer
1595
1373
                                        blocks removed from the end of
1603
1381
                                        this is incremented by one; this is
1604
1382
                                        set to zero when a buffer block is
1605
1383
                                        allocated */
 
1384
 
1606
1385
        /* @} */
1607
 
 
1608
1386
        /** @name LRU replacement algorithm fields */
1609
1387
        /* @{ */
1610
1388
 
1613
1391
                                        block list */
1614
1392
        UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1615
1393
                                        /*!< base node of the LRU list */
1616
 
        buf_page_t*     LRU_old;        /*!< pointer to the about
1617
 
                                        buf_LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV
1618
 
                                        oldest blocks in the LRU list;
1619
 
                                        NULL if LRU length less than
1620
 
                                        BUF_LRU_OLD_MIN_LEN;
 
1394
        buf_page_t*     LRU_old;        /*!< pointer to the about 3/8 oldest
 
1395
                                        blocks in the LRU list; NULL if LRU
 
1396
                                        length less than BUF_LRU_OLD_MIN_LEN;
1621
1397
                                        NOTE: when LRU_old != NULL, its length
1622
1398
                                        should always equal LRU_old_len */
1623
1399
        ulint           LRU_old_len;    /*!< length of the LRU list from
1624
1400
                                        the block to which LRU_old points
1625
1401
                                        onward, including that block;
1626
1402
                                        see buf0lru.c for the restrictions
1627
 
                                        on this value; 0 if LRU_old == NULL;
 
1403
                                        on this value; not defined if
 
1404
                                        LRU_old == NULL;
1628
1405
                                        NOTE: LRU_old_len must be adjusted
1629
1406
                                        whenever LRU_old shrinks or grows! */
1630
1407
 
1642
1419
                                        /*!< unmodified compressed pages */
1643
1420
        UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1644
1421
                                        /*!< buddy free lists */
1645
 
 
1646
 
        buf_page_t                      watch[BUF_POOL_WATCH_SIZE];
1647
 
                                        /*!< Sentinel records for buffer
1648
 
                                        pool watches. Protected by
1649
 
                                        buf_pool->mutex. */
1650
 
 
1651
1422
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1652
1423
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1653
1424
#endif
1669
1440
/* @{ */
1670
1441
 
1671
1442
/** Test if buf_pool_mutex is owned. */
1672
 
#define buf_pool_mutex_own(b) mutex_own(&b->mutex)
 
1443
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
1673
1444
/** Acquire the buffer pool mutex. */
1674
 
#define buf_pool_mutex_enter(b) do {            \
1675
 
        ut_ad(!mutex_own(&b->zip_mutex));       \
1676
 
        mutex_enter(&b->mutex);         \
1677
 
} while (0)
1678
 
 
1679
 
/** Test if flush list mutex is owned. */
1680
 
#define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1681
 
 
1682
 
/** Acquire the flush list mutex. */
1683
 
#define buf_flush_list_mutex_enter(b) do {      \
1684
 
        mutex_enter(&b->flush_list_mutex);      \
1685
 
} while (0)
1686
 
/** Release the flush list mutex. */
1687
 
# define buf_flush_list_mutex_exit(b) do {      \
1688
 
        mutex_exit(&b->flush_list_mutex);       \
1689
 
} while (0)
1690
 
 
1691
 
 
 
1445
#define buf_pool_mutex_enter() do {             \
 
1446
        ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
 
1447
        mutex_enter(&buf_pool_mutex);           \
 
1448
} while (0)
1692
1449
 
1693
1450
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
 
1451
/** Flag to forbid the release of the buffer pool mutex.
 
1452
Protected by buf_pool_mutex. */
 
1453
extern ulint    buf_pool_mutex_exit_forbidden;
1694
1454
/** Forbid the release of the buffer pool mutex. */
1695
 
# define buf_pool_mutex_exit_forbid(b) do {     \
1696
 
        ut_ad(buf_pool_mutex_own(b));           \
1697
 
        b->mutex_exit_forbidden++;              \
 
1455
# define buf_pool_mutex_exit_forbid() do {      \
 
1456
        ut_ad(buf_pool_mutex_own());            \
 
1457
        buf_pool_mutex_exit_forbidden++;        \
1698
1458
} while (0)
1699
1459
/** Allow the release of the buffer pool mutex. */
1700
 
# define buf_pool_mutex_exit_allow(b) do {      \
1701
 
        ut_ad(buf_pool_mutex_own(b));           \
1702
 
        ut_a(b->mutex_exit_forbidden);  \
1703
 
        b->mutex_exit_forbidden--;              \
 
1460
# define buf_pool_mutex_exit_allow() do {       \
 
1461
        ut_ad(buf_pool_mutex_own());            \
 
1462
        ut_a(buf_pool_mutex_exit_forbidden);    \
 
1463
        buf_pool_mutex_exit_forbidden--;        \
1704
1464
} while (0)
1705
1465
/** Release the buffer pool mutex. */
1706
 
# define buf_pool_mutex_exit(b) do {            \
1707
 
        ut_a(!b->mutex_exit_forbidden);         \
1708
 
        mutex_exit(&b->mutex);                  \
 
1466
# define buf_pool_mutex_exit() do {             \
 
1467
        ut_a(!buf_pool_mutex_exit_forbidden);   \
 
1468
        mutex_exit(&buf_pool_mutex);            \
1709
1469
} while (0)
1710
1470
#else
1711
1471
/** Forbid the release of the buffer pool mutex. */
1712
 
# define buf_pool_mutex_exit_forbid(b) ((void) 0)
 
1472
# define buf_pool_mutex_exit_forbid() ((void) 0)
1713
1473
/** Allow the release of the buffer pool mutex. */
1714
 
# define buf_pool_mutex_exit_allow(b) ((void) 0)
 
1474
# define buf_pool_mutex_exit_allow() ((void) 0)
1715
1475
/** Release the buffer pool mutex. */
1716
 
# define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
 
1476
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1717
1477
#endif
1718
1478
#endif /* !UNIV_HOTBACKUP */
1719
1479
/* @} */