1
1
/*****************************************************************************
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
Copyright (c) 2008, Google Inc.
6
6
Portions of this file contain modifications contributed and copyrighted by
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
Gets the current size of buffer buf_pool in pages.
52
@return size in pages*/
55
buf_pool_get_n_pages(void)
56
/*======================*/
58
return(buf_pool_get_curr_size() / UNIV_PAGE_SIZE);
61
39
/********************************************************************//**
62
40
Reads the freed_page_clock of a buffer block.
94
72
/*=====================*/
95
73
const buf_page_t* bpage) /*!< in: block to make younger */
97
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
99
75
if (UNIV_UNLIKELY(buf_pool->freed_page_clock == 0)) {
100
76
/* If eviction has not started yet, do not update the
101
77
statistics or move blocks in the LRU list. This is
117
93
return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
118
94
> ((ulint) bpage->freed_page_clock
119
95
+ (buf_pool->curr_size
120
* (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
96
* (BUF_LRU_OLD_RATIO_DIV - buf_LRU_old_ratio)
121
97
/ (BUF_LRU_OLD_RATIO_DIV * 4))));
125
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
/*********************************************************************//**
126
145
Gets the state of a block.
274
293
/*===============*/
275
294
const buf_page_t* bpage) /*!< in: pointer to control block */
277
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
279
296
switch (buf_page_get_state(bpage)) {
280
297
case BUF_BLOCK_ZIP_FREE:
283
300
case BUF_BLOCK_ZIP_PAGE:
284
301
case BUF_BLOCK_ZIP_DIRTY:
285
return(&buf_pool->zip_mutex);
302
return(&buf_pool_zip_mutex);
287
304
return(&((buf_block_t*) bpage)->mutex);
383
400
buf_page_t* bpage, /*!< in/out: control block */
384
401
enum buf_io_fix io_fix) /*!< in: io_fix state */
387
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
388
ut_ad(buf_pool_mutex_own(buf_pool));
403
ut_ad(buf_pool_mutex_own());
390
404
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
392
406
bpage->io_fix = io_fix;
414
428
/*==================*/
415
429
const buf_page_t* bpage) /*!< control block being relocated */
418
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
419
ut_ad(buf_pool_mutex_own(buf_pool));
431
ut_ad(buf_pool_mutex_own());
421
432
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
422
433
ut_ad(buf_page_in_file(bpage));
423
434
ut_ad(bpage->in_LRU_list);
453
461
buf_page_t* bpage, /*!< in/out: control block */
454
462
ibool old) /*!< in: old */
457
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
458
#endif /* UNIV_DEBUG */
459
464
ut_a(buf_page_in_file(bpage));
460
ut_ad(buf_pool_mutex_own(buf_pool));
465
ut_ad(buf_pool_mutex_own());
461
466
ut_ad(bpage->in_LRU_list);
463
468
#ifdef UNIV_LRU_DEBUG
503
508
buf_page_t* bpage, /*!< in/out: control block */
504
509
ulint time_ms) /*!< in: ut_time_ms() */
507
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
508
ut_ad(buf_pool_mutex_own(buf_pool));
510
511
ut_a(buf_page_in_file(bpage));
512
ut_ad(buf_pool_mutex_own());
512
514
if (!bpage->access_time) {
513
515
/* Make this the time of the first access. */
703
705
/*========================*/
704
706
const buf_block_t* block) /*!< in: block */
707
ut_ad(buf_page_in_file(&block->page));
708
#ifdef UNIV_SYNC_DEBUG
709
ut_ad(rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_EXCLUSIVE)
710
|| rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_SHARED));
711
#endif /* UNIV_SYNC_DEBUG */
712
708
return(block->lock_hash_val);
715
711
/********************************************************************//**
712
Allocates a buffer block.
713
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
718
ulint zip_size) /*!< in: compressed page size in bytes,
719
or 0 if uncompressed tablespace */
723
block = buf_LRU_get_free_block(zip_size);
725
buf_block_set_state(block, BUF_BLOCK_MEMORY);
730
/********************************************************************//**
716
731
Frees a buffer block which does not contain a file page. */
806
819
buf_block_t* block) /*!< in: block */
808
821
#ifdef UNIV_SYNC_DEBUG
809
buf_pool_t* buf_pool = buf_pool_from_bpage((buf_page_t*)block);
811
ut_ad((buf_pool_mutex_own(buf_pool)
822
ut_ad((buf_pool_mutex_own()
812
823
&& (block->page.buf_fix_count == 0))
813
824
|| rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
814
825
#endif /* UNIV_SYNC_DEBUG */
889
900
/******************************************************************//**
890
Returns the buffer pool instance given a page instance
896
const buf_page_t* bpage) /*!< in: buffer pool page */
898
/* Every page must be in some buffer pool. */
899
ut_ad(bpage->buf_pool != NULL);
901
return(bpage->buf_pool);
904
/******************************************************************//**
905
Returns the buffer pool instance given a block instance
911
const buf_block_t* block) /*!< in: block */
913
return(buf_pool_from_bpage(&block->page));
916
/******************************************************************//**
917
Returns the buffer pool instance given space and offset of page
918
@return buffer pool */
923
ulint space, /*!< in: space id */
924
ulint offset) /*!< in: offset of the page within space */
928
ulint ignored_offset;
930
ignored_offset = offset >> 6; /* 2log of BUF_READ_AHEAD_AREA (64)*/
931
fold = buf_page_address_fold(space, ignored_offset);
932
index = fold % srv_buf_pool_instances;
933
return buf_pool_ptr[index];
936
/******************************************************************//**
937
Returns the buffer pool instance given its array index
938
@return buffer pool */
943
ulint index) /*!< in: array index to get
944
buffer pool instance from */
946
return buf_pool_ptr[index];
949
/******************************************************************//**
950
901
Returns the control block of a file page, NULL if not found.
951
902
@return block, NULL if not found */
954
buf_page_hash_get_low(
955
/*==================*/
956
buf_pool_t* buf_pool, /*!< buffer pool instance */
957
ulint space, /*!< in: space id */
958
ulint offset, /*!< in: offset of the page
960
ulint fold) /*!< in: buf_page_address_fold(
907
ulint space, /*!< in: space id */
908
ulint offset) /*!< in: offset of the page within space */
963
910
buf_page_t* bpage;
966
ut_ad(buf_pool_mutex_own(buf_pool));
967
ut_ad(fold == buf_page_address_fold(space, offset));
914
ut_ad(buf_pool_mutex_own());
969
916
/* Look for the page in the hash table */
918
fold = buf_page_address_fold(space, offset);
971
920
HASH_SEARCH(hash, buf_pool->page_hash, fold, buf_page_t*, bpage,
972
921
ut_ad(bpage->in_page_hash && !bpage->in_zip_hash
973
922
&& buf_page_in_file(bpage)),
976
925
ut_a(buf_page_in_file(bpage));
977
926
ut_ad(bpage->in_page_hash);
978
927
ut_ad(!bpage->in_zip_hash);
979
#if UNIV_WORD_SIZE == 4
980
/* On 32-bit systems, there is no padding in
981
buf_page_t. On other systems, Valgrind could complain
982
about uninitialized pad bytes. */
983
928
UNIV_MEM_ASSERT_RW(bpage, sizeof *bpage);
990
/******************************************************************//**
991
Returns the control block of a file page, NULL if not found.
992
@return block, NULL if not found or not a real control block */
997
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
998
ulint space, /*!< in: space id */
999
ulint offset) /*!< in: offset of the page
1003
ulint fold = buf_page_address_fold(space, offset);
1005
bpage = buf_page_hash_get_low(buf_pool, space, offset, fold);
1007
if (bpage && buf_pool_watch_is_sentinel(buf_pool, bpage)) {
1020
940
buf_block_hash_get(
1021
941
/*===============*/
1022
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1023
ulint space, /*!< in: space id */
1024
ulint offset) /*!< in: offset of the page
942
ulint space, /*!< in: space id */
943
ulint offset) /*!< in: offset of the page within space */
1029
block = buf_page_get_block(buf_page_hash_get(buf_pool, space, offset));
945
return(buf_page_get_block(buf_page_hash_get(space, offset)));
1034
948
/********************************************************************//**
1046
960
ulint offset) /*!< in: page number */
1048
962
const buf_page_t* bpage;
1049
buf_pool_t* buf_pool = buf_pool_get(space, offset);
1051
buf_pool_mutex_enter(buf_pool);
1053
bpage = buf_page_hash_get(buf_pool, space, offset);
1055
buf_pool_mutex_exit(buf_pool);
964
buf_pool_mutex_enter();
966
bpage = buf_page_hash_get(space, offset);
968
buf_pool_mutex_exit();
1057
970
return(bpage != NULL);
1074
986
switch (buf_page_get_state(bpage)) {
1075
987
case BUF_BLOCK_ZIP_PAGE:
1076
988
case BUF_BLOCK_ZIP_DIRTY:
1077
mutex_enter(&buf_pool->zip_mutex);
989
mutex_enter(&buf_pool_zip_mutex);
1078
990
bpage->buf_fix_count--;
1079
mutex_exit(&buf_pool->zip_mutex);
991
mutex_exit(&buf_pool_zip_mutex);
1081
993
case BUF_BLOCK_FILE_PAGE:
1082
994
block = (buf_block_t*) bpage;
1107
1018
buf_page_release(
1108
1019
/*=============*/
1109
1020
buf_block_t* block, /*!< in: buffer block */
1110
ulint rw_latch) /*!< in: RW_S_LATCH, RW_X_LATCH,
1021
ulint rw_latch, /*!< in: RW_S_LATCH, RW_X_LATCH,
1023
mtr_t* mtr) /*!< in: mtr */
1115
1027
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
1116
1028
ut_a(block->page.buf_fix_count > 0);
1030
if (rw_latch == RW_X_LATCH && mtr->modifications) {
1031
buf_pool_mutex_enter();
1032
buf_flush_note_modification(block, mtr);
1033
buf_pool_mutex_exit();
1118
1036
mutex_enter(&block->mutex);
1120
1038
#ifdef UNIV_SYNC_DEBUG
1147
1065
sync_thread_add_level(&block->lock, level);
1149
1067
#endif /* UNIV_SYNC_DEBUG */
1150
/********************************************************************//**
1151
Acquire mutex on all buffer pool instances. */
1154
buf_pool_mutex_enter_all(void)
1155
/*==========================*/
1159
for (i = 0; i < srv_buf_pool_instances; i++) {
1160
buf_pool_t* buf_pool;
1162
buf_pool = buf_pool_from_array(i);
1163
buf_pool_mutex_enter(buf_pool);
1167
/********************************************************************//**
1168
Release mutex on all buffer pool instances. */
1171
buf_pool_mutex_exit_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_exit(buf_pool);
1183
1068
#endif /* !UNIV_HOTBACKUP */