1
/*****************************************************************************
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/buf0buf.h
21
The database buffer pool high-level routines
23
Created 11/5/1995 Heikki Tuuri
24
*******************************************************/
31
#include "mtr0types.h"
32
#include "buf0types.h"
33
#include "hash0hash.h"
35
#include "page0types.h"
36
#ifndef UNIV_HOTBACKUP
40
/** @name Modes for buf_page_get_gen */
42
#define BUF_GET 10 /*!< get always */
43
#define BUF_GET_IF_IN_POOL 11 /*!< get if in pool */
44
#define BUF_GET_NO_LATCH 14 /*!< get and bufferfix, but
46
separated this case, because
47
it is error-prone programming
48
not to set a latch, and it
49
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
55
/** @name Modes for buf_page_get_known_nowait */
57
#define BUF_MAKE_YOUNG 51 /*!< Move the block to the
58
start of the LRU list if there
59
is a danger that the block
60
would drift out of the buffer
62
#define BUF_KEEP_OLD 52 /*!< Preserve the current LRU
63
position of the block. */
66
#define MAX_BUFFER_POOLS 64 /*!< The maximum number of buffer
67
pools that can be defined */
69
#define BUF_POOL_WATCH_SIZE 1 /*!< Maximum number of concurrent
70
buffer pool watches */
72
extern buf_pool_t* buf_pool_ptr; /*!< The buffer pools
75
extern ibool buf_debug_prints;/*!< If this is set TRUE, the program
76
prints info whenever read or flush
78
#endif /* UNIV_DEBUG */
79
#else /* !UNIV_HOTBACKUP */
80
extern buf_block_t* back_block1; /*!< first block, for --apply-log */
81
extern buf_block_t* back_block2; /*!< second block, for page reorganize */
82
#endif /* !UNIV_HOTBACKUP */
84
/** Magic value to use instead of checksums when they are disabled */
85
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
87
/** @brief States of a control block
90
The enumeration values must be 0..7. */
92
BUF_BLOCK_ZIP_FREE = 0, /*!< contains a free
94
BUF_BLOCK_POOL_WATCH = 0, /*!< a sentinel for the buffer pool
95
watch, element of buf_pool->watch[] */
96
BUF_BLOCK_ZIP_PAGE, /*!< contains a clean
98
BUF_BLOCK_ZIP_DIRTY, /*!< contains a compressed
100
buf_pool->flush_list */
102
BUF_BLOCK_NOT_USED, /*!< is in the free list;
103
must be after the BUF_BLOCK_ZIP_
104
constants for compressed-only pages
105
@see buf_block_state_valid() */
106
BUF_BLOCK_READY_FOR_USE, /*!< when buf_LRU_get_free_block
107
returns a block, it is in this state */
108
BUF_BLOCK_FILE_PAGE, /*!< contains a buffered file page */
109
BUF_BLOCK_MEMORY, /*!< contains some main memory
111
BUF_BLOCK_REMOVE_HASH /*!< hash index should be removed
112
before putting to the free list */
115
#ifndef UNIV_HOTBACKUP
116
/********************************************************************//**
117
Acquire mutex on all buffer pool instances */
120
buf_pool_mutex_enter_all(void);
121
/*===========================*/
123
/********************************************************************//**
124
Release mutex on all buffer pool instances */
127
buf_pool_mutex_exit_all(void);
128
/*==========================*/
130
/********************************************************************//**
131
Creates the buffer pool.
132
@return own: buf_pool object, NULL if not enough memory or error */
137
ulint size, /*!< in: Size of the total pool in bytes */
138
ulint n_instances); /*!< in: Number of instances */
139
/********************************************************************//**
140
Frees the buffer pool at shutdown. This must not be invoked before
141
freeing all mutexes. */
146
ulint n_instances); /*!< in: numbere of instances to free */
148
/********************************************************************//**
149
Drops the adaptive hash index. To prevent a livelock, this function
150
is only to be called while holding btr_search_latch and while
151
btr_search_enabled == FALSE. */
154
buf_pool_drop_hash_index(void);
155
/*==========================*/
157
/********************************************************************//**
158
Relocate a buffer control block. Relocates the block on the LRU list
159
and in buf_pool->page_hash. Does not relocate bpage->list.
160
The caller must take care of relocating bpage->list. */
165
buf_page_t* bpage, /*!< in/out: control block being relocated;
166
buf_page_get_state(bpage) must be
167
BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */
168
buf_page_t* dpage) /*!< in/out: destination control block */
169
__attribute__((nonnull));
170
/********************************************************************//**
171
Resizes the buffer pool. */
174
buf_pool_resize(void);
175
/*=================*/
176
/*********************************************************************//**
177
Gets the current size of buffer buf_pool in bytes.
178
@return size in bytes */
181
buf_pool_get_curr_size(void);
182
/*========================*/
183
/*********************************************************************//**
184
Gets the current size of buffer buf_pool in frames.
185
@return size in pages */
188
buf_pool_get_n_pages(void);
189
/*=======================*/
190
/********************************************************************//**
191
Gets the smallest oldest_modification lsn for any page in the pool. Returns
192
zero if all modified pages have been flushed to disk.
193
@return oldest modification in pool, zero if none */
196
buf_pool_get_oldest_modification(void);
197
/*==================================*/
198
/********************************************************************//**
199
Allocates a buffer block.
200
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
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 */
208
/********************************************************************//**
209
Frees a buffer block which does not contain a file page. */
214
buf_block_t* block); /*!< in, own: block to be freed */
215
#endif /* !UNIV_HOTBACKUP */
216
/*********************************************************************//**
217
Copies contents of a buffer frame to a given buffer.
223
byte* buf, /*!< in: buffer to copy to */
224
const buf_frame_t* frame); /*!< in: buffer frame */
225
#ifndef UNIV_HOTBACKUP
226
/**************************************************************//**
227
NOTE! The following macros should be used instead of buf_page_get_gen,
228
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
230
#define buf_page_get(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
231
SP, ZS, OF, LA, NULL,\
232
BUF_GET, __FILE__, __LINE__, MTR)
233
/**************************************************************//**
234
Use these macros to bufferfix a page with no latching. Remember not to
235
read the contents of the page unless you know it is safe. Do not modify
236
the contents of the page! We have separated this case, because it is
237
error-prone programming not to set a latch, and it should be used
239
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
240
SP, ZS, OF, RW_NO_LATCH, NULL,\
241
BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
242
/********************************************************************//**
243
This is the general function used to get optimistic access to a database
245
@return TRUE if success */
248
buf_page_optimistic_get(
249
/*====================*/
250
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
251
buf_block_t* block, /*!< in: guessed block */
252
ib_uint64_t modify_clock,/*!< in: modify clock value if mode is
253
..._GUESS_ON_CLOCK */
254
const char* file, /*!< in: file name */
255
ulint line, /*!< in: line where called */
256
mtr_t* mtr); /*!< in: mini-transaction */
257
/********************************************************************//**
258
This is used to get access to a known database page, when no waiting can be
260
@return TRUE if success */
263
buf_page_get_known_nowait(
264
/*======================*/
265
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
266
buf_block_t* block, /*!< in: the known page */
267
ulint mode, /*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
268
const char* file, /*!< in: file name */
269
ulint line, /*!< in: line where called */
270
mtr_t* mtr); /*!< in: mini-transaction */
272
/*******************************************************************//**
273
Given a tablespace id and page number tries to get that page. If the
274
page is not in the buffer pool it is not loaded and NULL is returned.
275
Suitable for using when holding the kernel mutex. */
278
buf_page_try_get_func(
279
/*==================*/
280
ulint space_id,/*!< in: tablespace id */
281
ulint page_no,/*!< in: page number */
282
const char* file, /*!< in: file name */
283
ulint line, /*!< in: line where called */
284
mtr_t* mtr); /*!< in: mini-transaction */
286
/** Tries to get a page. If the page is not in the buffer pool it is
287
not loaded. Suitable for using when holding the kernel mutex.
288
@param space_id in: tablespace id
289
@param page_no in: page number
290
@param mtr in: mini-transaction
291
@return the page if in buffer pool, NULL if not */
292
#define buf_page_try_get(space_id, page_no, mtr) \
293
buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
295
/********************************************************************//**
296
Get read access to a compressed page (usually of type
297
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
298
The page must be released with buf_page_release_zip().
299
NOTE: the page is not protected by any latch. Mutual exclusion has to
300
be implemented at a higher level. In other words, all possible
301
accesses to a given page through this function must be protected by
302
the same set of mutexes or latches.
303
@return pointer to the block, or NULL if not compressed */
308
ulint space, /*!< in: space id */
309
ulint zip_size,/*!< in: compressed page size */
310
ulint offset);/*!< in: page number */
311
/********************************************************************//**
312
This is the general function used to get access to a database page.
313
@return pointer to the block or NULL */
318
ulint space, /*!< in: space id */
319
ulint zip_size,/*!< in: compressed page size in bytes
320
or 0 for uncompressed pages */
321
ulint offset, /*!< in: page number */
322
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
323
buf_block_t* guess, /*!< in: guessed block or NULL */
324
ulint mode, /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
326
BUF_GET_IF_IN_POOL_OR_WATCH */
327
const char* file, /*!< in: file name */
328
ulint line, /*!< in: line where called */
329
mtr_t* mtr); /*!< in: mini-transaction */
330
/********************************************************************//**
331
Initializes a page to the buffer buf_pool. The page is usually not read
332
from a file even if it cannot be found in the buffer buf_pool. This is one
333
of the functions which perform to a block a state transition NOT_USED =>
334
FILE_PAGE (the other is buf_page_get_gen).
335
@return pointer to the block, page bufferfixed */
340
ulint space, /*!< in: space id */
341
ulint offset, /*!< in: offset of the page within space in units of
343
ulint zip_size,/*!< in: compressed page size, or 0 */
344
mtr_t* mtr); /*!< in: mini-transaction handle */
345
#else /* !UNIV_HOTBACKUP */
346
/********************************************************************//**
347
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
350
buf_page_init_for_backup_restore(
351
/*=============================*/
352
ulint space, /*!< in: space id */
353
ulint offset, /*!< in: offset of the page within space
354
in units of a page */
355
ulint zip_size,/*!< in: compressed page size in bytes
356
or 0 for uncompressed pages */
357
buf_block_t* block); /*!< in: block to init */
358
#endif /* !UNIV_HOTBACKUP */
360
#ifndef UNIV_HOTBACKUP
361
/********************************************************************//**
362
Releases a compressed-only page acquired with buf_page_get_zip(). */
365
buf_page_release_zip(
366
/*=================*/
367
buf_page_t* bpage); /*!< in: buffer block */
368
/********************************************************************//**
369
Decrements the bufferfix count of a buffer control block and releases
370
a latch, if specified. */
375
buf_block_t* block, /*!< in: buffer block */
376
ulint rw_latch); /*!< in: RW_S_LATCH, RW_X_LATCH,
378
/********************************************************************//**
379
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
386
buf_page_t* bpage); /*!< in: buffer block of a file page */
387
/********************************************************************//**
388
Returns TRUE if the page can be found in the buffer pool hash table.
390
NOTE that it is possible that the page is not yet read from disk,
393
@return TRUE if found in the page hash table */
398
ulint space, /*!< in: space id */
399
ulint offset);/*!< in: page number */
400
/********************************************************************//**
401
Resets the check_index_page_at_flush field of a page if found in the buffer
405
buf_reset_check_index_page_at_flush(
406
/*================================*/
407
ulint space, /*!< in: space id */
408
ulint offset);/*!< in: page number */
409
#ifdef UNIV_DEBUG_FILE_ACCESSES
410
/********************************************************************//**
411
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
412
This function should be called when we free a file page and want the
413
debug version to check that it is not accessed any more unless
415
@return control block if found in page hash table, otherwise NULL */
418
buf_page_set_file_page_was_freed(
419
/*=============================*/
420
ulint space, /*!< in: space id */
421
ulint offset);/*!< in: page number */
422
/********************************************************************//**
423
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
424
This function should be called when we free a file page and want the
425
debug version to check that it is not accessed any more unless
427
@return control block if found in page hash table, otherwise NULL */
430
buf_page_reset_file_page_was_freed(
431
/*===============================*/
432
ulint space, /*!< in: space id */
433
ulint offset); /*!< in: page number */
434
#endif /* UNIV_DEBUG_FILE_ACCESSES */
435
/********************************************************************//**
436
Reads the freed_page_clock of a buffer block.
437
@return freed_page_clock */
440
buf_page_get_freed_page_clock(
441
/*==========================*/
442
const buf_page_t* bpage) /*!< in: block */
443
__attribute__((pure));
444
/********************************************************************//**
445
Reads the freed_page_clock of a buffer block.
446
@return freed_page_clock */
449
buf_block_get_freed_page_clock(
450
/*===========================*/
451
const buf_block_t* block) /*!< in: block */
452
__attribute__((pure));
454
/********************************************************************//**
455
Recommends a move of a block to the start of the LRU list if there is danger
456
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
458
@return TRUE if should be made younger */
461
buf_page_peek_if_too_old(
462
/*=====================*/
463
const buf_page_t* bpage); /*!< in: block to make younger */
464
/********************************************************************//**
465
Returns the current state of is_hashed of a page. FALSE if the page is
466
not in the pool. NOTE that this operation does not fix the page in the
467
pool if it is found there.
468
@return TRUE if page hash index is built in search system */
471
buf_page_peek_if_search_hashed(
472
/*===========================*/
473
ulint space, /*!< in: space id */
474
ulint offset);/*!< in: page number */
475
/********************************************************************//**
476
Gets the youngest modification log sequence number for a frame.
477
Returns zero if not file page or no modification occurred yet.
478
@return newest modification to page */
481
buf_page_get_newest_modification(
482
/*=============================*/
483
const buf_page_t* bpage); /*!< in: block containing the
485
/********************************************************************//**
486
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
491
buf_block_modify_clock_inc(
492
/*=======================*/
493
buf_block_t* block); /*!< in: block */
494
/********************************************************************//**
495
Returns the value of the modify clock. The caller must have an s-lock
496
or x-lock on the block.
500
buf_block_get_modify_clock(
501
/*=======================*/
502
buf_block_t* block); /*!< in: block */
503
#else /* !UNIV_HOTBACKUP */
504
# define buf_block_modify_clock_inc(block) ((void) 0)
505
#endif /* !UNIV_HOTBACKUP */
506
/********************************************************************//**
507
Calculates a page checksum which is stored to the page when it is written
508
to a file. Note that we must be careful to calculate the same value
509
on 32-bit and 64-bit architectures.
513
buf_calc_page_new_checksum(
514
/*=======================*/
515
const byte* page); /*!< in: buffer page */
516
/********************************************************************//**
517
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
518
looked at the first few bytes of the page. This calculates that old
520
NOTE: we must first store the new formula checksum to
521
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
522
because this takes that field as an input!
526
buf_calc_page_old_checksum(
527
/*=======================*/
528
const byte* page); /*!< in: buffer page */
529
/********************************************************************//**
530
Checks if a page is corrupt.
531
@return TRUE if corrupted */
534
buf_page_is_corrupted(
535
/*==================*/
536
const byte* read_buf, /*!< in: a database page */
537
ulint zip_size); /*!< in: size of compressed page;
538
0 for uncompressed pages */
539
#ifndef UNIV_HOTBACKUP
540
/**********************************************************************//**
541
Gets the space id, page offset, and byte offset within page of a
542
pointer pointing to a buffer frame containing a file page. */
545
buf_ptr_get_fsp_addr(
546
/*=================*/
547
const void* ptr, /*!< in: pointer to a buffer frame */
548
ulint* space, /*!< out: space id */
549
fil_addr_t* addr); /*!< out: page offset and byte offset */
550
/**********************************************************************//**
551
Gets the hash value of a block. This can be used in searches in the
553
@return lock hash value */
556
buf_block_get_lock_hash_val(
557
/*========================*/
558
const buf_block_t* block) /*!< in: block */
559
__attribute__((pure));
561
/*********************************************************************//**
562
Finds a block in the buffer pool that points to a
563
given compressed page.
564
@return buffer block pointing to the compressed page, or NULL */
567
buf_pool_contains_zip(
568
/*==================*/
569
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
570
const void* data); /*!< in: pointer to compressed page */
571
#endif /* UNIV_DEBUG */
572
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
573
/*********************************************************************//**
574
Validates the buffer pool data structure.
580
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
581
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
582
/*********************************************************************//**
583
Prints info of the buffer pool data structure. */
588
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
589
#endif /* !UNIV_HOTBACKUP */
590
/********************************************************************//**
591
Prints a page to stderr. */
596
const byte* read_buf, /*!< in: a database page */
597
ulint zip_size); /*!< in: compressed page size, or
598
0 for uncompressed pages */
599
/********************************************************************//**
601
@return TRUE if successful */
606
buf_block_t* block, /*!< in/out: block */
607
ibool check); /*!< in: TRUE=verify the page checksum */
608
#ifndef UNIV_HOTBACKUP
610
/*********************************************************************//**
611
Returns the number of latched pages in the buffer pool.
612
@return number of latched pages */
615
buf_get_latched_pages_number(void);
616
/*==============================*/
617
#endif /* UNIV_DEBUG */
618
/*********************************************************************//**
619
Returns the number of pending buf pool ios.
620
@return number of pending I/O operations */
623
buf_get_n_pending_ios(void);
624
/*=======================*/
625
/*********************************************************************//**
626
Prints info of the buffer i/o. */
631
FILE* file); /*!< in: file where to print */
632
/*********************************************************************//**
633
Returns the ratio in percents of modified pages in the buffer pool /
634
database pages in the buffer pool.
635
@return modified page percentage ratio */
638
buf_get_modified_ratio_pct(void);
639
/*============================*/
640
/**********************************************************************//**
641
Refreshes the statistics used to print per-second averages. */
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. */
651
buf_refresh_io_stats_all(void);
652
/*=================*/
653
/*********************************************************************//**
654
Asserts that all file pages in the buffer are in a replaceable state.
660
/*********************************************************************//**
661
Checks that there currently are no pending i/o-operations for the buffer
663
@return TRUE if there is no pending i/o */
666
buf_pool_check_no_pending_io(void);
667
/*==============================*/
668
/*********************************************************************//**
669
Invalidates the file pages in the buffer pool when an archive recovery is
670
completed. All the file pages buffered must be in a replaceable state when
671
this function is called: not latched and not modified. */
674
buf_pool_invalidate(void);
675
/*=====================*/
676
#endif /* !UNIV_HOTBACKUP */
678
/*========================================================================
679
--------------------------- LOWER LEVEL ROUTINES -------------------------
680
=========================================================================*/
682
#ifdef UNIV_SYNC_DEBUG
683
/*********************************************************************//**
684
Adds latch level info for the rw-lock protecting the buffer frame. This
685
should be called in the debug version after a successful latching of a
686
page if we know the latching order level of the acquired latch. */
689
buf_block_dbg_add_level(
690
/*====================*/
691
buf_block_t* block, /*!< in: buffer page
692
where we have acquired latch */
693
ulint level); /*!< in: latching order level */
694
#else /* UNIV_SYNC_DEBUG */
695
# define buf_block_dbg_add_level(block, level) /* nothing */
696
#endif /* UNIV_SYNC_DEBUG */
697
/*********************************************************************//**
698
Gets the state of a block.
704
const buf_page_t* bpage); /*!< in: pointer to the control block */
705
/*********************************************************************//**
706
Gets the state of a block.
712
const buf_block_t* block) /*!< in: pointer to the control block */
713
__attribute__((pure));
714
/*********************************************************************//**
715
Sets the state of a block. */
720
buf_page_t* bpage, /*!< in/out: pointer to control block */
721
enum buf_page_state state); /*!< in: state */
722
/*********************************************************************//**
723
Sets the state of a block. */
728
buf_block_t* block, /*!< in/out: pointer to control block */
729
enum buf_page_state state); /*!< in: state */
730
/*********************************************************************//**
731
Determines if a block is mapped to a tablespace.
732
@return TRUE if mapped */
737
const buf_page_t* bpage) /*!< in: pointer to control block */
738
__attribute__((pure));
739
#ifndef UNIV_HOTBACKUP
740
/*********************************************************************//**
741
Determines if a block should be on unzip_LRU list.
742
@return TRUE if block belongs to unzip_LRU */
745
buf_page_belongs_to_unzip_LRU(
746
/*==========================*/
747
const buf_page_t* bpage) /*!< in: pointer to control block */
748
__attribute__((pure));
750
/*********************************************************************//**
751
Gets the mutex of a block.
752
@return pointer to mutex protecting bpage */
757
const buf_page_t* bpage) /*!< in: pointer to control block */
758
__attribute__((pure));
760
/*********************************************************************//**
761
Get the flush type of a page.
762
@return flush type */
765
buf_page_get_flush_type(
766
/*====================*/
767
const buf_page_t* bpage) /*!< in: buffer page */
768
__attribute__((pure));
769
/*********************************************************************//**
770
Set the flush type of a page. */
773
buf_page_set_flush_type(
774
/*====================*/
775
buf_page_t* bpage, /*!< in: buffer page */
776
enum buf_flush flush_type); /*!< in: flush type */
777
/*********************************************************************//**
778
Map a block to a file page. */
781
buf_block_set_file_page(
782
/*====================*/
783
buf_block_t* block, /*!< in/out: pointer to control block */
784
ulint space, /*!< in: tablespace id */
785
ulint page_no);/*!< in: page number */
786
/*********************************************************************//**
787
Gets the io_fix state of a block.
788
@return io_fix state */
793
const buf_page_t* bpage) /*!< in: pointer to the control block */
794
__attribute__((pure));
795
/*********************************************************************//**
796
Gets the io_fix state of a block.
797
@return io_fix state */
800
buf_block_get_io_fix(
802
const buf_block_t* block) /*!< in: pointer to the control block */
803
__attribute__((pure));
804
/*********************************************************************//**
805
Sets the io_fix state of a block. */
810
buf_page_t* bpage, /*!< in/out: control block */
811
enum buf_io_fix io_fix);/*!< in: io_fix state */
812
/*********************************************************************//**
813
Sets the io_fix state of a block. */
816
buf_block_set_io_fix(
817
/*=================*/
818
buf_block_t* block, /*!< in/out: control block */
819
enum buf_io_fix io_fix);/*!< in: io_fix state */
821
/********************************************************************//**
822
Determine if a buffer block can be relocated in memory. The block
823
can be dirty, but it must not be I/O-fixed or bufferfixed. */
826
buf_page_can_relocate(
827
/*==================*/
828
const buf_page_t* bpage) /*!< control block being relocated */
829
__attribute__((pure));
831
/*********************************************************************//**
832
Determine if a block has been flagged old.
833
@return TRUE if old */
838
const buf_page_t* bpage) /*!< in: control block */
839
__attribute__((pure));
840
/*********************************************************************//**
846
buf_page_t* bpage, /*!< in/out: control block */
847
ibool old); /*!< in: old */
848
/*********************************************************************//**
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 */
853
buf_page_is_accessed(
854
/*=================*/
855
const buf_page_t* bpage) /*!< in: control block */
856
__attribute__((nonnull, pure));
857
/*********************************************************************//**
858
Flag a block accessed. */
861
buf_page_set_accessed(
862
/*==================*/
863
buf_page_t* bpage, /*!< in/out: control block */
864
ulint time_ms) /*!< in: ut_time_ms() */
865
__attribute__((nonnull));
866
/*********************************************************************//**
867
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.
870
@return control block, or NULL */
875
buf_page_t* bpage) /*!< in: control block, or NULL */
876
__attribute__((pure));
877
#endif /* !UNIV_HOTBACKUP */
879
/*********************************************************************//**
880
Gets a pointer to the memory frame of a block.
881
@return pointer to the frame */
886
const buf_block_t* block) /*!< in: pointer to the control block */
887
__attribute__((pure));
888
#else /* UNIV_DEBUG */
889
# define buf_block_get_frame(block) (block)->frame
890
#endif /* UNIV_DEBUG */
891
/*********************************************************************//**
892
Gets the space id of a block.
898
const buf_page_t* bpage) /*!< in: pointer to the control block */
899
__attribute__((pure));
900
/*********************************************************************//**
901
Gets the space id of a block.
907
const buf_block_t* block) /*!< in: pointer to the control block */
908
__attribute__((pure));
909
/*********************************************************************//**
910
Gets the page number of a block.
911
@return page number */
914
buf_page_get_page_no(
915
/*=================*/
916
const buf_page_t* bpage) /*!< in: pointer to the control block */
917
__attribute__((pure));
918
/*********************************************************************//**
919
Gets the page number of a block.
920
@return page number */
923
buf_block_get_page_no(
924
/*==================*/
925
const buf_block_t* block) /*!< in: pointer to the control block */
926
__attribute__((pure));
927
/*********************************************************************//**
928
Gets the compressed page size of a block.
929
@return compressed page size, or 0 */
932
buf_page_get_zip_size(
933
/*==================*/
934
const buf_page_t* bpage) /*!< in: pointer to the control block */
935
__attribute__((pure));
936
/*********************************************************************//**
937
Gets the compressed page size of a block.
938
@return compressed page size, or 0 */
941
buf_block_get_zip_size(
942
/*===================*/
943
const buf_block_t* block) /*!< in: pointer to the control block */
944
__attribute__((pure));
945
/*********************************************************************//**
946
Gets the compressed page descriptor corresponding to an uncompressed page
948
#define buf_block_get_page_zip(block) \
949
(UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
950
#ifndef UNIV_HOTBACKUP
951
/*******************************************************************//**
952
Gets the block to whose frame the pointer is pointing to.
953
@return pointer to block, never NULL */
958
const byte* ptr); /*!< in: pointer to a frame */
959
/********************************************************************//**
960
Find out if a pointer belongs to a buf_block_t. It can be a pointer to
961
the buf_block_t itself or a member of it
962
@return TRUE if ptr belongs to a buf_block_t struct */
965
buf_pointer_is_block_field(
966
/*=======================*/
967
const void* ptr); /*!< in: pointer not
969
/** Find out if a pointer corresponds to a buf_block_t::mutex.
970
@param m in: mutex candidate
971
@return TRUE if m is a buf_block_t::mutex */
972
#define buf_pool_is_block_mutex(m) \
973
buf_pointer_is_block_field((const void*)(m))
974
/** Find out if a pointer corresponds to a buf_block_t::lock.
975
@param l in: rw-lock candidate
976
@return TRUE if l is a buf_block_t::lock */
977
#define buf_pool_is_block_lock(l) \
978
buf_pointer_is_block_field((const void*)(l))
980
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
981
/*********************************************************************//**
982
Gets the compressed page descriptor corresponding to an uncompressed page
984
@return compressed page descriptor, or NULL */
986
const page_zip_des_t*
987
buf_frame_get_page_zip(
988
/*===================*/
989
const byte* ptr); /*!< in: pointer to the page */
990
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
991
/********************************************************************//**
992
Function which inits a page for read to the buffer buf_pool. If the page is
993
(1) already in buf_pool, or
994
(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
995
(3) if the space is deleted or being deleted,
996
then this function does nothing.
997
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
998
on the buffer frame. The io-handler must take care that the flag is cleared
999
and the lock released later.
1000
@return pointer to the block or NULL */
1003
buf_page_init_for_read(
1004
/*===================*/
1005
ulint* err, /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED */
1006
ulint mode, /*!< in: BUF_READ_IBUF_PAGES_ONLY, ... */
1007
ulint space, /*!< in: space id */
1008
ulint zip_size,/*!< in: compressed page size, or 0 */
1009
ibool unzip, /*!< in: TRUE=request uncompressed page */
1010
ib_int64_t tablespace_version,/*!< in: prevents reading from a wrong
1011
version of the tablespace in case we have done
1013
ulint offset);/*!< in: page number */
1014
/********************************************************************//**
1015
Completes an asynchronous read or write request of a file page to or from
1019
buf_page_io_complete(
1020
/*=================*/
1021
buf_page_t* bpage); /*!< in: pointer to the block in question */
1022
/********************************************************************//**
1023
Calculates a folded value of a file page address to use in the page hash
1025
@return the folded value */
1028
buf_page_address_fold(
1029
/*==================*/
1030
ulint space, /*!< in: space id */
1031
ulint offset) /*!< in: offset of the page within space */
1032
__attribute__((const));
1033
/********************************************************************//**
1034
Calculates the index of a buffer pool to the buf_pool[] array.
1035
@return the position of the buffer pool in buf_pool[] */
1040
const buf_pool_t* buf_pool) /*!< in: buffer pool */
1041
__attribute__((nonnull, const));
1042
/******************************************************************//**
1043
Returns the buffer pool instance given a page instance
1047
buf_pool_from_bpage(
1048
/*================*/
1049
const buf_page_t* bpage); /*!< in: buffer pool page */
1050
/******************************************************************//**
1051
Returns the buffer pool instance given a block instance
1055
buf_pool_from_block(
1056
/*================*/
1057
const buf_block_t* block); /*!< in: block */
1058
/******************************************************************//**
1059
Returns the buffer pool instance given space and offset of page
1060
@return buffer pool */
1065
ulint space, /*!< in: space id */
1066
ulint offset);/*!< in: offset of the page within space */
1067
/******************************************************************//**
1068
Returns the buffer pool instance given its array index
1069
@return buffer pool */
1072
buf_pool_from_array(
1073
/*================*/
1074
ulint index); /*!< in: array index to get
1075
buffer pool instance from */
1076
/******************************************************************//**
1077
Returns the control block of a file page, NULL if not found.
1078
@return block, NULL if not found */
1081
buf_page_hash_get_low(
1082
/*==================*/
1083
buf_pool_t* buf_pool, /*!< buffer pool instance */
1084
ulint space, /*!< in: space id */
1085
ulint offset, /*!< in: offset of the page
1087
ulint fold); /*!< in: buf_page_address_fold(
1089
/******************************************************************//**
1090
Returns the control block of a file page, NULL if not found.
1091
@return block, NULL if not found or not a real control block */
1096
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1097
ulint space, /*!< in: space id */
1098
ulint offset); /*!< in: offset of the page
1100
/******************************************************************//**
1101
Returns the control block of a file page, NULL if not found
1102
or an uncompressed page frame does not exist.
1103
@return block, NULL if not found */
1108
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1109
ulint space, /*!< in: space id */
1110
ulint offset); /*!< in: offset of the page
1112
/*********************************************************************//**
1113
Gets the current length of the free list of buffer blocks.
1114
@return length of the free list */
1117
buf_get_free_list_len(void);
1118
/*=======================*/
1120
/********************************************************************
1121
Determine if a block is a sentinel for a buffer pool watch.
1122
@return TRUE if a sentinel for a buffer pool watch, FALSE if not */
1125
buf_pool_watch_is_sentinel(
1126
/*=======================*/
1127
buf_pool_t* buf_pool, /*!< buffer pool instance */
1128
const buf_page_t* bpage) /*!< in: block */
1129
UNIV_WARN_UNUSED_RESULT;
1130
/****************************************************************//**
1131
Add watch for the given page to be read in. Caller must have the buffer pool
1132
@return NULL if watch set, block if the page is in the buffer pool */
1137
ulint space, /*!< in: space id */
1138
ulint offset, /*!< in: page number */
1139
ulint fold) /*!< in: buf_page_address_fold(space, offset) */
1140
UNIV_WARN_UNUSED_RESULT;
1141
/****************************************************************//**
1142
Stop watching if the page has been read in.
1143
buf_pool_watch_set(space,offset) must have returned NULL before. */
1146
buf_pool_watch_unset(
1147
/*=================*/
1148
ulint space, /*!< in: space id */
1149
ulint offset);/*!< in: page number */
1150
/****************************************************************//**
1151
Check if the page has been read in.
1152
This may only be called after buf_pool_watch_set(space,offset)
1153
has returned NULL and before invoking buf_pool_watch_unset(space,offset).
1154
@return FALSE if the given page was not read in, TRUE if it was */
1157
buf_pool_watch_occurred(
1158
/*====================*/
1159
ulint space, /*!< in: space id */
1160
ulint offset) /*!< in: page number */
1161
UNIV_WARN_UNUSED_RESULT;
1162
/********************************************************************//**
1163
Get total buffer pool statistics. */
1166
buf_get_total_list_len(
1167
/*===================*/
1168
ulint* LRU_len, /*!< out: length of all LRU lists */
1169
ulint* free_len, /*!< out: length of all free lists */
1170
ulint* flush_list_len);/*!< out: length of all flush lists */
1171
/********************************************************************//**
1172
Get total buffer pool statistics. */
1177
buf_pool_stat_t*tot_stat); /*!< out: buffer pool stats */
1179
#endif /* !UNIV_HOTBACKUP */
1181
/** The common buffer control block structure
1182
for compressed and uncompressed frames */
1184
struct buf_page_struct{
1185
/** @name General fields
1186
None of these bit-fields must be modified without holding
1187
buf_page_get_mutex() [buf_block_struct::mutex or
1188
buf_pool->zip_mutex], since they can be stored in the same
1189
machine word. Some of these fields are additionally protected
1190
by buf_pool->mutex. */
1193
unsigned space:32; /*!< tablespace id; also protected
1194
by buf_pool->mutex. */
1195
unsigned offset:32; /*!< page number; also protected
1196
by buf_pool->mutex. */
1198
unsigned state:3; /*!< state of the control block; also
1199
protected by buf_pool->mutex.
1200
State transitions from
1201
BUF_BLOCK_READY_FOR_USE to
1202
BUF_BLOCK_MEMORY need not be
1203
protected by buf_page_get_mutex().
1204
@see enum buf_page_state */
1205
#ifndef UNIV_HOTBACKUP
1206
unsigned flush_type:2; /*!< if this block is currently being
1207
flushed to disk, this tells the
1209
@see enum buf_flush */
1210
unsigned io_fix:2; /*!< type of pending I/O operation;
1211
also protected by buf_pool->mutex
1212
@see enum buf_io_fix */
1213
unsigned buf_fix_count:19;/*!< count of how manyfold this block
1214
is currently bufferfixed */
1215
unsigned buf_pool_index:6;/*!< index number of the buffer pool
1216
that this block belongs to */
1217
# if MAX_BUFFER_POOLS > 64
1218
# error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
1221
#endif /* !UNIV_HOTBACKUP */
1222
page_zip_des_t zip; /*!< compressed page; zip.data
1223
(but not the data it points to) is
1224
also protected by buf_pool->mutex;
1225
state == BUF_BLOCK_ZIP_PAGE and
1226
zip.data == NULL means an active
1228
#ifndef UNIV_HOTBACKUP
1229
buf_page_t* hash; /*!< node used in chaining to
1230
buf_pool->page_hash or
1231
buf_pool->zip_hash */
1233
ibool in_page_hash; /*!< TRUE if in buf_pool->page_hash */
1234
ibool in_zip_hash; /*!< TRUE if in buf_pool->zip_hash */
1235
#endif /* UNIV_DEBUG */
1237
/** @name Page flushing fields
1238
All these are protected by buf_pool->mutex. */
1241
UT_LIST_NODE_T(buf_page_t) list;
1242
/*!< based on state, this is a
1243
list node, protected either by
1244
buf_pool->mutex or by
1245
buf_pool->flush_list_mutex,
1246
in one of the following lists in
1249
- BUF_BLOCK_NOT_USED: free
1250
- BUF_BLOCK_FILE_PAGE: flush_list
1251
- BUF_BLOCK_ZIP_DIRTY: flush_list
1252
- BUF_BLOCK_ZIP_PAGE: zip_clean
1253
- BUF_BLOCK_ZIP_FREE: zip_free[]
1255
If bpage is part of flush_list
1256
then the node pointers are
1257
covered by buf_pool->flush_list_mutex.
1258
Otherwise these pointers are
1259
protected by buf_pool->mutex.
1261
The contents of the list node
1262
is undefined if !in_flush_list
1263
&& state == BUF_BLOCK_FILE_PAGE,
1264
or if state is one of
1266
BUF_BLOCK_REMOVE_HASH or
1267
BUF_BLOCK_READY_IN_USE. */
1270
ibool in_flush_list; /*!< TRUE if in buf_pool->flush_list;
1271
when buf_pool->flush_list_mutex is
1272
free, the following should hold:
1274
== (state == BUF_BLOCK_FILE_PAGE
1275
|| state == BUF_BLOCK_ZIP_DIRTY)
1276
Writes to this field must be
1277
covered by both block->mutex
1278
and buf_pool->flush_list_mutex. Hence
1279
reads can happen while holding
1280
any one of the two mutexes */
1281
ibool in_free_list; /*!< TRUE if in buf_pool->free; when
1282
buf_pool->mutex is free, the following
1283
should hold: in_free_list
1284
== (state == BUF_BLOCK_NOT_USED) */
1285
#endif /* UNIV_DEBUG */
1286
ib_uint64_t newest_modification;
1287
/*!< log sequence number of
1288
the youngest modification to
1289
this block, zero if not
1290
modified. Protected by block
1292
ib_uint64_t oldest_modification;
1293
/*!< log sequence number of
1294
the START of the log entry
1295
written of the oldest
1296
modification to this block
1297
which has not yet been flushed
1298
on disk; zero if all
1299
modifications are on disk.
1300
Writes to this field must be
1301
covered by both block->mutex
1302
and buf_pool->flush_list_mutex. Hence
1303
reads can happen while holding
1304
any one of the two mutexes */
1306
/** @name LRU replacement algorithm fields
1307
These fields are protected by buf_pool->mutex only (not
1308
buf_pool->zip_mutex or buf_block_struct::mutex). */
1311
UT_LIST_NODE_T(buf_page_t) LRU;
1312
/*!< node of the LRU list */
1314
ibool in_LRU_list; /*!< TRUE if the page is in
1315
the LRU list; used in
1317
#endif /* UNIV_DEBUG */
1318
unsigned old:1; /*!< TRUE if the block is in the old
1319
blocks in buf_pool->LRU_old */
1320
unsigned freed_page_clock:31;/*!< the value of
1321
buf_pool->freed_page_clock
1322
when this block was the last
1323
time put to the head of the
1324
LRU list; a thread is allowed
1325
to read this for heuristic
1326
purposes without holding any
1328
unsigned access_time:32; /*!< time of first access, or
1329
0 if the block was never accessed
1330
in the buffer pool */
1332
# ifdef UNIV_DEBUG_FILE_ACCESSES
1333
ibool file_page_was_freed;
1334
/*!< this is set to TRUE when fsp
1335
frees a page in buffer pool */
1336
# endif /* UNIV_DEBUG_FILE_ACCESSES */
1337
#endif /* !UNIV_HOTBACKUP */
1340
/** The buffer control block structure */
1342
struct buf_block_struct{
1344
/** @name General fields */
1347
buf_page_t page; /*!< page information; this must
1348
be the first field, so that
1349
buf_pool->page_hash can point
1350
to buf_page_t or buf_block_t */
1351
byte* frame; /*!< pointer to buffer frame which
1352
is of size UNIV_PAGE_SIZE, and
1353
aligned to an address divisible by
1355
#ifndef UNIV_HOTBACKUP
1356
UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1357
/*!< node of the decompressed LRU list;
1358
a block is in the unzip_LRU list
1359
if page.state == BUF_BLOCK_FILE_PAGE
1360
and page.zip.data != NULL */
1362
ibool in_unzip_LRU_list;/*!< TRUE if the page is in the
1363
decompressed LRU list;
1364
used in debugging */
1365
#endif /* UNIV_DEBUG */
1366
mutex_t mutex; /*!< mutex protecting this block:
1367
state (also protected by the buffer
1368
pool mutex), io_fix, buf_fix_count,
1369
and accessed; we introduce this new
1370
mutex in InnoDB-5.1 to relieve
1371
contention on the buffer pool mutex */
1372
rw_lock_t lock; /*!< read-write lock of the buffer
1374
unsigned lock_hash_val:32;/*!< hashed value of the page address
1375
in the record lock hash table;
1376
protected by buf_block_t::lock
1377
(or buf_block_t::mutex, buf_pool->mutex
1378
in buf_page_get_gen(),
1379
buf_page_init_for_read()
1380
and buf_page_create()) */
1381
ibool check_index_page_at_flush;
1382
/*!< TRUE if we know that this is
1383
an index page, and want the database
1384
to check its consistency before flush;
1385
note that there may be pages in the
1386
buffer pool which are index pages,
1387
but this flag is not set because
1388
we do not keep track of all pages;
1389
NOT protected by any mutex */
1391
/** @name Optimistic search field */
1394
ib_uint64_t modify_clock; /*!< this clock is incremented every
1395
time a pointer to a record on the
1396
page may become obsolete; this is
1397
used in the optimistic cursor
1398
positioning: if the modify clock has
1399
not changed, we know that the pointer
1400
is still valid; this field may be
1401
changed if the thread (1) owns the
1402
pool mutex and the page is not
1403
bufferfixed, or (2) the thread has an
1404
x-latch on the block */
1406
/** @name Hash search fields (unprotected)
1407
NOTE that these fields are NOT protected by any semaphore! */
1410
ulint n_hash_helps; /*!< counter which controls building
1411
of a new hash index for the page */
1412
ulint n_fields; /*!< recommended prefix length for hash
1413
search: number of full fields */
1414
ulint n_bytes; /*!< recommended prefix: number of bytes
1415
in an incomplete field */
1416
ibool left_side; /*!< TRUE or FALSE, depending on
1417
whether the leftmost record of several
1418
records with the same prefix should be
1419
indexed in the hash index */
1422
/** @name Hash search fields
1423
These 6 fields may only be modified when we have
1424
an x-latch on btr_search_latch AND
1425
- we are holding an s-latch or x-latch on buf_block_struct::lock or
1426
- we know that buf_block_struct::buf_fix_count == 0.
1428
An exception to this is when we init or create a page
1429
in the buffer pool in buf0buf.c. */
1433
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1434
ulint n_pointers; /*!< used in debugging: the number of
1435
pointers in the adaptive hash index
1436
pointing to this frame */
1437
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1438
unsigned is_hashed:1; /*!< TRUE if hash index has
1439
already been built on this
1440
page; note that it does not
1441
guarantee that the index is
1442
complete, though: there may
1443
have been hash collisions,
1444
record deletions, etc. */
1445
unsigned curr_n_fields:10;/*!< prefix length for hash indexing:
1446
number of full fields */
1447
unsigned curr_n_bytes:15;/*!< number of bytes in hash
1449
unsigned curr_left_side:1;/*!< TRUE or FALSE in hash indexing */
1450
dict_index_t* index; /*!< Index for which the adaptive
1451
hash index has been created. */
1453
# ifdef UNIV_SYNC_DEBUG
1454
/** @name Debug fields */
1456
rw_lock_t debug_latch; /*!< in the debug version, each thread
1457
which bufferfixes the block acquires
1458
an s-latch here; so we can use the
1459
debug utilities in sync0rw */
1462
#endif /* !UNIV_HOTBACKUP */
1465
/** Check if a buf_block_t object is in a valid state
1466
@param block buffer block
1467
@return TRUE if valid */
1468
#define buf_block_state_valid(block) \
1469
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1470
&& (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1472
#ifndef UNIV_HOTBACKUP
1473
/**********************************************************************//**
1474
Compute the hash fold value for blocks in buf_pool->zip_hash. */
1476
#define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1477
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1478
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1481
/** @brief The buffer pool statistics structure. */
1482
struct buf_pool_stat_struct{
1483
ulint n_page_gets; /*!< number of page gets performed;
1484
also successful searches through
1485
the adaptive hash index are
1486
counted as page gets; this field
1487
is NOT protected by the buffer
1489
ulint n_pages_read; /*!< number read operations */
1490
ulint n_pages_written;/*!< number write operations */
1491
ulint n_pages_created;/*!< number of pages created
1492
in the pool with no read */
1493
ulint n_ra_pages_read;/*!< number of pages read in
1494
as part of read ahead */
1495
ulint n_ra_pages_evicted;/*!< number of read ahead
1496
pages that are evicted without
1498
ulint n_pages_made_young; /*!< number of pages made young, in
1499
calls to buf_LRU_make_block_young() */
1500
ulint n_pages_not_made_young; /*!< number of pages not made
1501
young because the first access
1502
was not long enough ago, in
1503
buf_page_peek_if_too_old() */
1506
/** Statistics of buddy blocks of a given size. */
1507
struct buf_buddy_stat_struct {
1508
/** Number of blocks allocated from the buddy system. */
1510
/** Number of blocks relocated by the buddy system. */
1511
ib_uint64_t relocated;
1512
/** Total duration of block relocations, in microseconds. */
1513
ib_uint64_t relocated_usec;
1516
/** @brief The buffer pool structure.
1518
NOTE! The definition appears here only for other modules of this
1519
directory (buf) to see it. Do not use from outside! */
1521
struct buf_pool_struct{
1523
/** @name General fields */
1525
mutex_t mutex; /*!< Buffer pool mutex of this
1527
mutex_t zip_mutex; /*!< Zip mutex of this buffer
1528
pool instance, protects compressed
1529
only pages (of type buf_page_t, not
1531
ulint instance_no; /*!< Array index of this buffer
1533
ulint old_pool_size; /*!< Old pool size in bytes */
1534
ulint curr_pool_size; /*!< Current pool size in bytes */
1535
ulint LRU_old_ratio; /*!< Reserve this much of the buffer
1536
pool for "old" blocks */
1538
ulint buddy_n_frames; /*!< Number of frames allocated from
1539
the buffer pool to the buddy system */
1541
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1542
ulint mutex_exit_forbidden; /*!< Forbid release mutex */
1544
ulint n_chunks; /*!< number of buffer pool chunks */
1545
buf_chunk_t* chunks; /*!< buffer pool chunks */
1546
ulint curr_size; /*!< current pool size in pages */
1547
hash_table_t* page_hash; /*!< hash table of buf_page_t or
1548
buf_block_t file pages,
1549
buf_page_in_file() == TRUE,
1550
indexed by (space_id, offset) */
1551
hash_table_t* zip_hash; /*!< hash table of buf_block_t blocks
1552
whose frames are allocated to the
1554
indexed by block->frame */
1555
ulint n_pend_reads; /*!< number of pending read
1557
ulint n_pend_unzip; /*!< number of pending decompressions */
1559
time_t last_printout_time;
1560
/*!< when buf_print_io was last time
1562
buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES + 1];
1563
/*!< Statistics of buddy system,
1564
indexed by block size */
1565
buf_pool_stat_t stat; /*!< current statistics */
1566
buf_pool_stat_t old_stat; /*!< old statistics */
1570
/** @name Page flushing algorithm fields */
1574
mutex_t flush_list_mutex;/*!< mutex protecting the
1575
flush list access. This mutex
1576
protects flush_list, flush_rbt
1577
and bpage::list pointers when
1578
the bpage is on flush_list. It
1579
also protects writes to
1580
bpage::oldest_modification */
1581
UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1582
/*!< base node of the modified block
1584
ibool init_flush[BUF_FLUSH_N_TYPES];
1585
/*!< this is TRUE when a flush of the
1586
given type is being initialized */
1587
ulint n_flush[BUF_FLUSH_N_TYPES];
1588
/*!< this is the number of pending
1589
writes in the given flush type */
1590
os_event_t no_flush[BUF_FLUSH_N_TYPES];
1591
/*!< this is in the set state
1592
when there is no flush batch
1593
of the given type running */
1594
ib_rbt_t* flush_rbt; /*!< a red-black tree is used
1595
exclusively during recovery to
1596
speed up insertions in the
1597
flush_list. This tree contains
1599
oldest_modification LSN and is
1600
kept in sync with the
1602
Each member of the tree MUST
1603
also be on the flush_list.
1604
This tree is relevant only in
1605
recovery and is set to NULL
1606
once the recovery is over.
1607
Protected by flush_list_mutex */
1608
ulint freed_page_clock;/*!< a sequence number used
1609
to count the number of buffer
1610
blocks removed from the end of
1611
the LRU list; NOTE that this
1612
counter may wrap around at 4
1613
billion! A thread is allowed
1614
to read this for heuristic
1615
purposes without holding any
1617
ulint LRU_flush_ended;/*!< when an LRU flush ends for a page,
1618
this is incremented by one; this is
1619
set to zero when a buffer block is
1623
/** @name LRU replacement algorithm fields */
1626
UT_LIST_BASE_NODE_T(buf_page_t) free;
1627
/*!< base node of the free
1629
UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1630
/*!< base node of the LRU list */
1631
buf_page_t* LRU_old; /*!< pointer to the about
1632
buf_LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV
1633
oldest blocks in the LRU list;
1634
NULL if LRU length less than
1635
BUF_LRU_OLD_MIN_LEN;
1636
NOTE: when LRU_old != NULL, its length
1637
should always equal LRU_old_len */
1638
ulint LRU_old_len; /*!< length of the LRU list from
1639
the block to which LRU_old points
1640
onward, including that block;
1641
see buf0lru.c for the restrictions
1642
on this value; 0 if LRU_old == NULL;
1643
NOTE: LRU_old_len must be adjusted
1644
whenever LRU_old shrinks or grows! */
1646
UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1647
/*!< base node of the
1651
/** @name Buddy allocator fields
1652
The buddy allocator is used for allocating compressed page
1653
frames and buf_page_t descriptors of blocks that exist
1654
in the buffer pool only in compressed form. */
1656
UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1657
/*!< unmodified compressed pages */
1658
UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1659
/*!< buddy free lists */
1661
buf_page_t watch[BUF_POOL_WATCH_SIZE];
1662
/*!< Sentinel records for buffer
1663
pool watches. Protected by
1666
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1667
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1669
#if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1670
# error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1675
/** @name Accessors for buf_pool->mutex.
1676
Use these instead of accessing buf_pool->mutex directly. */
1679
/** Test if a buffer pool mutex is owned. */
1680
#define buf_pool_mutex_own(b) mutex_own(&b->mutex)
1681
/** Acquire a buffer pool mutex. */
1682
#define buf_pool_mutex_enter(b) do { \
1683
ut_ad(!mutex_own(&b->zip_mutex)); \
1684
mutex_enter(&b->mutex); \
1687
/** Test if flush list mutex is owned. */
1688
#define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1690
/** Acquire the flush list mutex. */
1691
#define buf_flush_list_mutex_enter(b) do { \
1692
mutex_enter(&b->flush_list_mutex); \
1694
/** Release the flush list mutex. */
1695
# define buf_flush_list_mutex_exit(b) do { \
1696
mutex_exit(&b->flush_list_mutex); \
1701
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1702
/** Forbid the release of the buffer pool mutex. */
1703
# define buf_pool_mutex_exit_forbid(b) do { \
1704
ut_ad(buf_pool_mutex_own(b)); \
1705
b->mutex_exit_forbidden++; \
1707
/** Allow the release of the buffer pool mutex. */
1708
# define buf_pool_mutex_exit_allow(b) do { \
1709
ut_ad(buf_pool_mutex_own(b)); \
1710
ut_a(b->mutex_exit_forbidden); \
1711
b->mutex_exit_forbidden--; \
1713
/** Release the buffer pool mutex. */
1714
# define buf_pool_mutex_exit(b) do { \
1715
ut_a(!b->mutex_exit_forbidden); \
1716
mutex_exit(&b->mutex); \
1719
/** Forbid the release of the buffer pool mutex. */
1720
# define buf_pool_mutex_exit_forbid(b) ((void) 0)
1721
/** Allow the release of the buffer pool mutex. */
1722
# define buf_pool_mutex_exit_allow(b) ((void) 0)
1723
/** Release the buffer pool mutex. */
1724
# define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
1726
#endif /* !UNIV_HOTBACKUP */
1729
/**********************************************************************
1730
Let us list the consistency conditions for different control block states.
1732
NOT_USED: is in free list, not in LRU list, not in flush list, nor
1734
READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
1736
MEMORY: is not in free list, LRU list, or flush list, nor page
1738
FILE_PAGE: space and offset are defined, is in page hash table
1739
if io_fix == BUF_IO_WRITE,
1740
pool: no_flush[flush_type] is in reset state,
1741
pool: n_flush[flush_type] > 0
1743
(1) if buf_fix_count == 0, then
1744
is in LRU list, not in free list
1746
if and only if oldest_modification > 0
1748
if and only if io_fix == BUF_IO_READ
1750
if and only if io_fix == BUF_IO_WRITE
1752
(2) if buf_fix_count > 0, then
1753
is not in LRU list, not in free list
1755
if and only if oldest_modification > 0
1756
if io_fix == BUF_IO_READ,
1758
if io_fix == BUF_IO_WRITE,
1763
NOT_USED => READY_FOR_USE
1764
READY_FOR_USE => MEMORY
1765
READY_FOR_USE => FILE_PAGE
1767
FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
1768
(1) buf_fix_count == 0,
1769
(2) oldest_modification == 0, and
1774
#include "buf0buf.ic"