1
1
/*****************************************************************************
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
Copyright (C) 2008, Google Inc.
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
4
Copyright (c) 2008, Google Inc.
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
31
31
*******************************************************/
33
33
#include "mtr0mtr.h"
34
#ifndef UNIV_HOTBACKUP
34
35
#include "buf0flu.h"
35
36
#include "buf0lru.h"
36
37
#include "buf0rea.h"
39
/*********************************************************************//**
40
Gets the current size of buffer buf_pool in bytes.
41
@return size in bytes */
44
buf_pool_get_curr_size(void)
45
/*========================*/
47
return(srv_buf_pool_curr_size);
50
/********************************************************************//**
51
Calculates the index of a buffer pool to the buf_pool[] array.
52
@return the position of the buffer pool in buf_pool[] */
57
const buf_pool_t* buf_pool) /*!< in: buffer pool */
59
ulint i = buf_pool - buf_pool_ptr;
60
ut_ad(i < MAX_BUFFER_POOLS);
61
ut_ad(i < srv_buf_pool_instances);
65
/******************************************************************//**
66
Returns the buffer pool instance given a page instance
72
const buf_page_t* bpage) /*!< in: buffer pool page */
75
i = bpage->buf_pool_index;
76
ut_ad(i < srv_buf_pool_instances);
77
return(&buf_pool_ptr[i]);
80
/******************************************************************//**
81
Returns the buffer pool instance given a block instance
87
const buf_block_t* block) /*!< in: block */
89
return(buf_pool_from_bpage(&block->page));
92
/*********************************************************************//**
93
Gets the current size of buffer buf_pool in pages.
94
@return size in pages*/
97
buf_pool_get_n_pages(void)
98
/*======================*/
100
return(buf_pool_get_curr_size() / UNIV_PAGE_SIZE);
103
39
/********************************************************************//**
104
40
Reads the freed_page_clock of a buffer block.
109
45
/*==========================*/
110
46
const buf_page_t* bpage) /*!< in: block */
112
/* This is sometimes read without holding buf_pool->mutex. */
48
/* This is sometimes read without holding buf_pool_mutex. */
113
49
return(bpage->freed_page_clock);
136
72
/*=====================*/
137
73
const buf_page_t* bpage) /*!< in: block to make younger */
139
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
141
75
if (UNIV_UNLIKELY(buf_pool->freed_page_clock == 0)) {
142
76
/* If eviction has not started yet, do not update the
143
77
statistics or move blocks in the LRU list. This is
159
93
return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
160
94
> ((ulint) bpage->freed_page_clock
161
95
+ (buf_pool->curr_size
162
* (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
96
* (BUF_LRU_OLD_RATIO_DIV - buf_LRU_old_ratio)
163
97
/ (BUF_LRU_OLD_RATIO_DIV * 4))));
167
101
/*********************************************************************//**
102
Gets the current size of buffer buf_pool in bytes.
103
@return size in bytes */
106
buf_pool_get_curr_size(void)
107
/*========================*/
109
return(buf_pool->curr_size * UNIV_PAGE_SIZE);
112
/********************************************************************//**
113
Gets the smallest oldest_modification lsn for any page in the pool. Returns
114
zero if all modified pages have been flushed to disk.
115
@return oldest modification in pool, zero if none */
118
buf_pool_get_oldest_modification(void)
119
/*==================================*/
124
buf_pool_mutex_enter();
126
bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
131
ut_ad(bpage->in_flush_list);
132
lsn = bpage->oldest_modification;
135
buf_pool_mutex_exit();
137
/* The returned answer may be out of date: the flush_list can
138
change after the mutex has been released. */
142
#endif /* !UNIV_HOTBACKUP */
144
/*********************************************************************//**
168
145
Gets the state of a block.
316
293
/*===============*/
317
294
const buf_page_t* bpage) /*!< in: pointer to control block */
319
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
321
296
switch (buf_page_get_state(bpage)) {
322
297
case BUF_BLOCK_ZIP_FREE:
325
300
case BUF_BLOCK_ZIP_PAGE:
326
301
case BUF_BLOCK_ZIP_DIRTY:
327
return(&buf_pool->zip_mutex);
302
return(&buf_pool_zip_mutex);
329
304
return(&((buf_block_t*) bpage)->mutex);
425
400
buf_page_t* bpage, /*!< in/out: control block */
426
401
enum buf_io_fix io_fix) /*!< in: io_fix state */
429
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
430
ut_ad(buf_pool_mutex_own(buf_pool));
403
ut_ad(buf_pool_mutex_own());
432
404
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
434
406
bpage->io_fix = io_fix;
456
428
/*==================*/
457
429
const buf_page_t* bpage) /*!< control block being relocated */
460
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
461
ut_ad(buf_pool_mutex_own(buf_pool));
431
ut_ad(buf_pool_mutex_own());
463
432
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
464
433
ut_ad(buf_page_in_file(bpage));
465
434
ut_ad(bpage->in_LRU_list);
478
447
const buf_page_t* bpage) /*!< in: control block */
481
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
482
ut_ad(buf_pool_mutex_own(buf_pool));
484
449
ut_ad(buf_page_in_file(bpage));
450
ut_ad(buf_pool_mutex_own());
486
452
return(bpage->old);
495
461
buf_page_t* bpage, /*!< in/out: control block */
496
462
ibool old) /*!< in: old */
499
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
500
#endif /* UNIV_DEBUG */
501
464
ut_a(buf_page_in_file(bpage));
502
ut_ad(buf_pool_mutex_own(buf_pool));
465
ut_ad(buf_pool_mutex_own());
503
466
ut_ad(bpage->in_LRU_list);
505
468
#ifdef UNIV_LRU_DEBUG
545
508
buf_page_t* bpage, /*!< in/out: control block */
546
509
ulint time_ms) /*!< in: ut_time_ms() */
549
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
550
ut_ad(buf_pool_mutex_own(buf_pool));
552
511
ut_a(buf_page_in_file(bpage));
512
ut_ad(buf_pool_mutex_own());
554
514
if (!bpage->access_time) {
555
515
/* Make this the time of the first access. */
757
717
/********************************************************************//**
718
Allocates a buffer block.
719
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
724
ulint zip_size) /*!< in: compressed page size in bytes,
725
or 0 if uncompressed tablespace */
729
block = buf_LRU_get_free_block(zip_size);
731
buf_block_set_state(block, BUF_BLOCK_MEMORY);
736
/********************************************************************//**
758
737
Frees a buffer block which does not contain a file page. */
848
825
buf_block_t* block) /*!< in: block */
850
827
#ifdef UNIV_SYNC_DEBUG
851
buf_pool_t* buf_pool = buf_pool_from_bpage((buf_page_t*)block);
853
ut_ad((buf_pool_mutex_own(buf_pool)
828
ut_ad((buf_pool_mutex_own()
854
829
&& (block->page.buf_fix_count == 0))
855
830
|| rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
856
831
#endif /* UNIV_SYNC_DEBUG */
931
906
/******************************************************************//**
932
Returns the buffer pool instance given space and offset of page
933
@return buffer pool */
938
ulint space, /*!< in: space id */
939
ulint offset) /*!< in: offset of the page within space */
943
ulint ignored_offset;
945
ignored_offset = offset >> 6; /* 2log of BUF_READ_AHEAD_AREA (64)*/
946
fold = buf_page_address_fold(space, ignored_offset);
947
index = fold % srv_buf_pool_instances;
948
return(&buf_pool_ptr[index]);
951
/******************************************************************//**
952
Returns the buffer pool instance given its array index
953
@return buffer pool */
958
ulint index) /*!< in: array index to get
959
buffer pool instance from */
961
ut_ad(index < MAX_BUFFER_POOLS);
962
ut_ad(index < srv_buf_pool_instances);
963
return(&buf_pool_ptr[index]);
966
/******************************************************************//**
967
907
Returns the control block of a file page, NULL if not found.
968
908
@return block, NULL if not found */
971
buf_page_hash_get_low(
972
/*==================*/
973
buf_pool_t* buf_pool, /*!< buffer pool instance */
974
ulint space, /*!< in: space id */
975
ulint offset, /*!< in: offset of the page
977
ulint fold) /*!< in: buf_page_address_fold(
913
ulint space, /*!< in: space id */
914
ulint offset) /*!< in: offset of the page within space */
980
916
buf_page_t* bpage;
983
ut_ad(buf_pool_mutex_own(buf_pool));
984
ut_ad(fold == buf_page_address_fold(space, offset));
920
ut_ad(buf_pool_mutex_own());
986
922
/* Look for the page in the hash table */
924
fold = buf_page_address_fold(space, offset);
988
926
HASH_SEARCH(hash, buf_pool->page_hash, fold, buf_page_t*, bpage,
989
927
ut_ad(bpage->in_page_hash && !bpage->in_zip_hash
990
928
&& buf_page_in_file(bpage)),
1007
945
/******************************************************************//**
1008
Returns the control block of a file page, NULL if not found.
1009
@return block, NULL if not found or not a real control block */
1014
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1015
ulint space, /*!< in: space id */
1016
ulint offset) /*!< in: offset of the page
1020
ulint fold = buf_page_address_fold(space, offset);
1022
bpage = buf_page_hash_get_low(buf_pool, space, offset, fold);
1024
if (bpage && buf_pool_watch_is_sentinel(buf_pool, bpage)) {
1031
/******************************************************************//**
1032
946
Returns the control block of a file page, NULL if not found
1033
947
or an uncompressed page frame does not exist.
1034
948
@return block, NULL if not found */
1037
951
buf_block_hash_get(
1038
952
/*===============*/
1039
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1040
ulint space, /*!< in: space id */
1041
ulint offset) /*!< in: offset of the page
953
ulint space, /*!< in: space id */
954
ulint offset) /*!< in: offset of the page within space */
1046
block = buf_page_get_block(buf_page_hash_get(buf_pool, space, offset));
956
return(buf_page_get_block(buf_page_hash_get(space, offset)));
1051
959
/********************************************************************//**
1063
971
ulint offset) /*!< in: page number */
1065
973
const buf_page_t* bpage;
1066
buf_pool_t* buf_pool = buf_pool_get(space, offset);
1068
buf_pool_mutex_enter(buf_pool);
1070
bpage = buf_page_hash_get(buf_pool, space, offset);
1072
buf_pool_mutex_exit(buf_pool);
975
buf_pool_mutex_enter();
977
bpage = buf_page_hash_get(space, offset);
979
buf_pool_mutex_exit();
1074
981
return(bpage != NULL);
1091
997
switch (buf_page_get_state(bpage)) {
1092
998
case BUF_BLOCK_ZIP_PAGE:
1093
999
case BUF_BLOCK_ZIP_DIRTY:
1094
mutex_enter(&buf_pool->zip_mutex);
1000
mutex_enter(&buf_pool_zip_mutex);
1095
1001
bpage->buf_fix_count--;
1096
mutex_exit(&buf_pool->zip_mutex);
1002
mutex_exit(&buf_pool_zip_mutex);
1098
1004
case BUF_BLOCK_FILE_PAGE:
1099
1005
block = (buf_block_t*) bpage;
1124
1029
buf_page_release(
1125
1030
/*=============*/
1126
1031
buf_block_t* block, /*!< in: buffer block */
1127
ulint rw_latch) /*!< in: RW_S_LATCH, RW_X_LATCH,
1032
ulint rw_latch, /*!< in: RW_S_LATCH, RW_X_LATCH,
1034
mtr_t* mtr) /*!< in: mtr */
1132
1038
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
1133
1039
ut_a(block->page.buf_fix_count > 0);
1041
if (rw_latch == RW_X_LATCH && mtr->modifications) {
1042
buf_pool_mutex_enter();
1043
buf_flush_note_modification(block, mtr);
1044
buf_pool_mutex_exit();
1135
1047
mutex_enter(&block->mutex);
1137
1049
#ifdef UNIV_SYNC_DEBUG
1164
1076
sync_thread_add_level(&block->lock, level);
1166
1078
#endif /* UNIV_SYNC_DEBUG */
1167
/********************************************************************//**
1168
Acquire mutex on all buffer pool instances. */
1171
buf_pool_mutex_enter_all(void)
1172
/*==========================*/
1176
for (i = 0; i < srv_buf_pool_instances; i++) {
1177
buf_pool_t* buf_pool;
1179
buf_pool = buf_pool_from_array(i);
1180
buf_pool_mutex_enter(buf_pool);
1184
/********************************************************************//**
1185
Release mutex on all buffer pool instances. */
1188
buf_pool_mutex_exit_all(void)
1189
/*=========================*/
1193
for (i = 0; i < srv_buf_pool_instances; i++) {
1194
buf_pool_t* buf_pool;
1196
buf_pool = buf_pool_from_array(i);
1197
buf_pool_mutex_exit(buf_pool);
1200
1079
#endif /* !UNIV_HOTBACKUP */