1
/*****************************************************************************
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
Copyright (C) 2008, Google Inc.
6
Portions of this file contain modifications contributed and copyrighted by
7
Google, Inc. Those modifications are gratefully acknowledged and are described
8
briefly in the InnoDB documentation. The contributions by Google are
9
incorporated with their permission, and subject to the conditions contained in
10
the file COPYING.Google.
12
This program is free software; you can redistribute it and/or modify it under
13
the terms of the GNU General Public License as published by the Free Software
14
Foundation; version 2 of the License.
16
This program is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
St, Fifth Floor, Boston, MA 02110-1301 USA
24
*****************************************************************************/
26
/**************************************************//**
27
@file include/buf0buf.ic
1
/******************************************************
28
2
The database buffer buf_pool
30
6
Created 11/5/1995 Heikki Tuuri
31
7
*******************************************************/
34
9
#include "buf0flu.h"
35
10
#include "buf0lru.h"
36
11
#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
/********************************************************************//**
104
Reads the freed_page_clock of a buffer block.
105
@return freed_page_clock */
14
/************************************************************************
15
Reads the freed_page_clock of a buffer block. */
108
18
buf_page_get_freed_page_clock(
109
19
/*==========================*/
110
const buf_page_t* bpage) /*!< in: block */
20
/* out: freed_page_clock */
21
const buf_page_t* bpage) /* in: block */
112
/* This is sometimes read without holding buf_pool->mutex. */
113
23
return(bpage->freed_page_clock);
116
/********************************************************************//**
117
Reads the freed_page_clock of a buffer block.
118
@return freed_page_clock */
26
/************************************************************************
27
Reads the freed_page_clock of a buffer block. */
121
30
buf_block_get_freed_page_clock(
122
31
/*===========================*/
123
const buf_block_t* block) /*!< in: block */
32
/* out: freed_page_clock */
33
const buf_block_t* block) /* in: block */
125
35
return(buf_page_get_freed_page_clock(&block->page));
128
/********************************************************************//**
38
/************************************************************************
129
39
Recommends a move of a block to the start of the LRU list if there is danger
130
40
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
132
@return TRUE if should be made younger */
135
44
buf_page_peek_if_too_old(
136
45
/*=====================*/
137
const buf_page_t* bpage) /*!< in: block to make younger */
139
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
141
if (UNIV_UNLIKELY(buf_pool->freed_page_clock == 0)) {
142
/* If eviction has not started yet, do not update the
143
statistics or move blocks in the LRU list. This is
144
either the warm-up phase or an in-memory workload. */
146
} else if (buf_LRU_old_threshold_ms && bpage->old) {
147
unsigned access_time = buf_page_is_accessed(bpage);
150
&& ((ib_uint32_t) (ut_time_ms() - access_time))
151
>= buf_LRU_old_threshold_ms) {
155
buf_pool->stat.n_pages_not_made_young++;
46
/* out: TRUE if should be made
48
const buf_page_t* bpage) /* in: block to make younger */
50
return(buf_pool->freed_page_clock
51
>= buf_page_get_freed_page_clock(bpage)
52
+ 1 + (buf_pool->curr_size / 4));
55
/*************************************************************************
56
Gets the current size of buffer buf_pool in bytes. */
59
buf_pool_get_curr_size(void)
60
/*========================*/
61
/* out: size in bytes */
63
return(buf_pool->curr_size * UNIV_PAGE_SIZE);
66
/************************************************************************
67
Gets the smallest oldest_modification lsn for any page in the pool. Returns
68
zero if all modified pages have been flushed to disk. */
71
buf_pool_get_oldest_modification(void)
72
/*==================================*/
73
/* out: oldest modification in pool,
79
buf_pool_mutex_enter();
81
bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
158
/* FIXME: bpage->freed_page_clock is 31 bits */
159
return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
160
> ((ulint) bpage->freed_page_clock
161
+ (buf_pool->curr_size
162
* (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
163
/ (BUF_LRU_OLD_RATIO_DIV * 4))));
86
ut_ad(bpage->in_flush_list);
87
lsn = bpage->oldest_modification;
167
/*********************************************************************//**
168
Gets the state of a block.
90
buf_pool_mutex_exit();
95
/***********************************************************************
96
Increments the buf_pool clock by one and returns its new value. Remember
97
that in the 32 bit version the clock wraps around at 4 billion! */
100
buf_pool_clock_tic(void)
101
/*====================*/
102
/* out: new clock value */
104
ut_ad(buf_pool_mutex_own());
106
buf_pool->ulint_clock++;
108
return(buf_pool->ulint_clock);
111
/*************************************************************************
112
Gets the state of a block. */
171
114
enum buf_page_state
172
115
buf_page_get_state(
173
116
/*===============*/
174
const buf_page_t* bpage) /*!< in: pointer to the control block */
118
const buf_page_t* bpage) /* in: pointer to the control block */
176
120
enum buf_page_state state = (enum buf_page_state) bpage->state;
307
251
&& buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
310
/*********************************************************************//**
311
Gets the mutex of a block.
312
@return pointer to mutex protecting bpage */
254
/*************************************************************************
255
Determine the approximate LRU list position of a block. */
258
buf_page_get_LRU_position(
259
/*======================*/
260
/* out: LRU list position */
261
const buf_page_t* bpage) /* in: control block */
263
ut_ad(buf_page_in_file(bpage));
265
return(bpage->LRU_position);
268
/*************************************************************************
269
Gets the mutex of a block. */
315
272
buf_page_get_mutex(
316
273
/*===============*/
317
const buf_page_t* bpage) /*!< in: pointer to control block */
274
/* out: pointer to mutex
276
const buf_page_t* bpage) /* in: pointer to control block */
319
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
321
278
switch (buf_page_get_state(bpage)) {
322
279
case BUF_BLOCK_ZIP_FREE:
325
282
case BUF_BLOCK_ZIP_PAGE:
326
283
case BUF_BLOCK_ZIP_DIRTY:
327
return(&buf_pool->zip_mutex);
284
return(&buf_pool_zip_mutex);
329
286
return(&((buf_block_t*) bpage)->mutex);
333
/*********************************************************************//**
334
Get the flush type of a page.
335
@return flush type */
290
/*************************************************************************
291
Get the flush type of a page. */
338
294
buf_page_get_flush_type(
339
295
/*====================*/
340
const buf_page_t* bpage) /*!< in: buffer page */
296
/* out: flush type */
297
const buf_page_t* bpage) /* in: buffer page */
342
299
enum buf_flush flush_type = (enum buf_flush) bpage->flush_type;
354
311
#endif /* UNIV_DEBUG */
355
312
return(flush_type);
357
/*********************************************************************//**
314
/*************************************************************************
358
315
Set the flush type of a page. */
361
318
buf_page_set_flush_type(
362
319
/*====================*/
363
buf_page_t* bpage, /*!< in: buffer page */
364
enum buf_flush flush_type) /*!< in: flush type */
320
buf_page_t* bpage, /* in: buffer page */
321
enum buf_flush flush_type) /* in: flush type */
366
323
bpage->flush_type = flush_type;
367
324
ut_ad(buf_page_get_flush_type(bpage) == flush_type);
370
/*********************************************************************//**
327
/*************************************************************************
371
328
Map a block to a file page. */
374
331
buf_block_set_file_page(
375
332
/*====================*/
376
buf_block_t* block, /*!< in/out: pointer to control block */
377
ulint space, /*!< in: tablespace id */
378
ulint page_no)/*!< in: page number */
333
buf_block_t* block, /* in/out: pointer to control block */
334
ulint space, /* in: tablespace id */
335
ulint page_no)/* in: page number */
380
337
buf_block_set_state(block, BUF_BLOCK_FILE_PAGE);
381
338
block->page.space = space;
382
339
block->page.offset = page_no;
385
/*********************************************************************//**
386
Gets the io_fix state of a block.
387
@return io_fix state */
342
/*************************************************************************
343
Gets the io_fix state of a block. */
390
346
buf_page_get_io_fix(
391
347
/*================*/
392
const buf_page_t* bpage) /*!< in: pointer to the control block */
348
/* out: io_fix state */
349
const buf_page_t* bpage) /* in: pointer to the control block */
394
351
enum buf_io_fix io_fix = (enum buf_io_fix) bpage->io_fix;
395
352
#ifdef UNIV_DEBUG
407
/*********************************************************************//**
408
Gets the io_fix state of a block.
409
@return io_fix state */
364
/*************************************************************************
365
Gets the io_fix state of a block. */
412
368
buf_block_get_io_fix(
413
/*=================*/
414
const buf_block_t* block) /*!< in: pointer to the control block */
370
/* out: io_fix state */
371
const buf_block_t* block) /* in: pointer to the control block */
416
373
return(buf_page_get_io_fix(&block->page));
419
/*********************************************************************//**
376
/*************************************************************************
420
377
Sets the io_fix state of a block. */
423
380
buf_page_set_io_fix(
424
381
/*================*/
425
buf_page_t* bpage, /*!< in/out: control block */
426
enum buf_io_fix io_fix) /*!< in: io_fix state */
382
buf_page_t* bpage, /* in/out: control block */
383
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));
385
ut_ad(buf_pool_mutex_own());
432
386
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
434
388
bpage->io_fix = io_fix;
435
389
ut_ad(buf_page_get_io_fix(bpage) == io_fix);
438
/*********************************************************************//**
392
/*************************************************************************
439
393
Sets the io_fix state of a block. */
442
396
buf_block_set_io_fix(
443
397
/*=================*/
444
buf_block_t* block, /*!< in/out: control block */
445
enum buf_io_fix io_fix) /*!< in: io_fix state */
398
buf_block_t* block, /* in/out: control block */
399
enum buf_io_fix io_fix) /* in: io_fix state */
447
401
buf_page_set_io_fix(&block->page, io_fix);
450
/********************************************************************//**
404
/************************************************************************
451
405
Determine if a buffer block can be relocated in memory. The block
452
406
can be dirty, but it must not be I/O-fixed or bufferfixed. */
455
409
buf_page_can_relocate(
456
410
/*==================*/
457
const buf_page_t* bpage) /*!< control block being relocated */
411
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));
413
ut_ad(buf_pool_mutex_own());
463
414
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
464
415
ut_ad(buf_page_in_file(bpage));
465
416
ut_ad(bpage->in_LRU_list);
468
419
&& bpage->buf_fix_count == 0);
471
/*********************************************************************//**
472
Determine if a block has been flagged old.
473
@return TRUE if old */
422
/*************************************************************************
423
Determine if a block has been flagged old. */
478
const buf_page_t* bpage) /*!< in: control block */
428
/* out: TRUE if old */
429
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
431
ut_ad(buf_page_in_file(bpage));
486
433
return(bpage->old);
489
/*********************************************************************//**
436
/*************************************************************************
490
437
Flag a block old. */
493
440
buf_page_set_old(
494
441
/*=============*/
495
buf_page_t* bpage, /*!< in/out: control block */
496
ibool old) /*!< in: old */
442
buf_page_t* bpage, /* in/out: control block */
443
ibool old) /* in: old */
499
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
500
#endif /* UNIV_DEBUG */
501
445
ut_a(buf_page_in_file(bpage));
502
ut_ad(buf_pool_mutex_own(buf_pool));
446
ut_ad(buf_pool_mutex_own());
503
447
ut_ad(bpage->in_LRU_list);
505
449
#ifdef UNIV_LRU_DEBUG
506
ut_a((buf_pool->LRU_old_len == 0) == (buf_pool->LRU_old == NULL));
507
/* If a block is flagged "old", the LRU_old list must exist. */
508
ut_a(!old || buf_pool->LRU_old);
510
if (UT_LIST_GET_PREV(LRU, bpage) && UT_LIST_GET_NEXT(LRU, bpage)) {
511
const buf_page_t* prev = UT_LIST_GET_PREV(LRU, bpage);
512
const buf_page_t* next = UT_LIST_GET_NEXT(LRU, bpage);
513
if (prev->old == next->old) {
514
ut_a(prev->old == old);
517
ut_a(buf_pool->LRU_old == (old ? bpage : next));
450
if (UT_LIST_GET_PREV(LRU, bpage) && UT_LIST_GET_NEXT(LRU, bpage)
451
&& UT_LIST_GET_PREV(LRU, bpage)->old
452
== UT_LIST_GET_NEXT(LRU, bpage)->old) {
453
ut_a(UT_LIST_GET_PREV(LRU, bpage)->old == old);
520
455
#endif /* UNIV_LRU_DEBUG */
522
457
bpage->old = old;
525
/*********************************************************************//**
526
Determine the time of first access of a block in the buffer pool.
527
@return ut_time_ms() at the time of first access, 0 if not accessed */
460
/*************************************************************************
461
Determine if a block has been accessed in the buffer pool. */
530
464
buf_page_is_accessed(
531
465
/*=================*/
532
const buf_page_t* bpage) /*!< in: control block */
466
/* out: TRUE if accessed */
467
const buf_page_t* bpage) /* in: control block */
534
469
ut_ad(buf_page_in_file(bpage));
536
return(bpage->access_time);
471
return(bpage->accessed);
539
/*********************************************************************//**
474
/*************************************************************************
540
475
Flag a block accessed. */
543
478
buf_page_set_accessed(
544
479
/*==================*/
545
buf_page_t* bpage, /*!< in/out: control block */
546
ulint time_ms) /*!< in: ut_time_ms() */
480
buf_page_t* bpage, /* in/out: control block */
481
ibool accessed) /* in: accessed */
549
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
550
ut_ad(buf_pool_mutex_own(buf_pool));
552
483
ut_a(buf_page_in_file(bpage));
484
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
554
if (!bpage->access_time) {
555
/* Make this the time of the first access. */
556
bpage->access_time = time_ms;
486
bpage->accessed = accessed;
560
/*********************************************************************//**
489
/*************************************************************************
561
490
Gets the buf_block_t handle of a buffered file block if an uncompressed
562
page frame exists, or NULL.
563
@return control block, or NULL */
491
page frame exists, or NULL. */
566
494
buf_page_get_block(
567
495
/*===============*/
568
buf_page_t* bpage) /*!< in: control block, or NULL */
496
/* out: control block, or NULL */
497
buf_page_t* bpage) /* in: control block, or NULL */
570
499
if (UNIV_LIKELY(bpage != NULL)) {
571
500
ut_ad(buf_page_in_file(bpage));
674
600
return(block->page.offset);
677
/*********************************************************************//**
678
Gets the compressed page size of a block.
679
@return compressed page size, or 0 */
603
/*************************************************************************
604
Gets the compressed page size of a block. */
682
607
buf_page_get_zip_size(
683
608
/*==================*/
684
const buf_page_t* bpage) /*!< in: pointer to the control block */
609
/* out: compressed page size, or 0 */
610
const buf_page_t* bpage) /* in: pointer to the control block */
686
612
return(bpage->zip.ssize ? 512 << bpage->zip.ssize : 0);
689
/*********************************************************************//**
690
Gets the compressed page size of a block.
691
@return compressed page size, or 0 */
615
/*************************************************************************
616
Gets the compressed page size of a block. */
694
619
buf_block_get_zip_size(
695
620
/*===================*/
696
const buf_block_t* block) /*!< in: pointer to the control block */
621
/* out: compressed page size, or 0 */
622
const buf_block_t* block) /* in: pointer to the control block */
698
624
return(block->page.zip.ssize ? 512 << block->page.zip.ssize : 0);
701
#ifndef UNIV_HOTBACKUP
702
627
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
703
/*********************************************************************//**
628
/***********************************************************************
629
Gets the block to whose frame the pointer is pointing to. */
634
/* out: pointer to block */
635
const byte* ptr) /* in: pointer to a frame */
637
const buf_block_t* block;
638
ulint space_id, page_no;
640
ptr = (const byte*) ut_align_down(ptr, UNIV_PAGE_SIZE);
641
page_no = mach_read_from_4(ptr + FIL_PAGE_OFFSET);
642
space_id = mach_read_from_4(ptr + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
644
block = (const buf_block_t*) buf_page_hash_get(space_id, page_no);
646
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
647
ut_ad(block->frame == ptr);
651
/*************************************************************************
704
652
Gets the compressed page descriptor corresponding to an uncompressed page
706
@return compressed page descriptor, or NULL */
708
655
const page_zip_des_t*
709
656
buf_frame_get_page_zip(
710
657
/*===================*/
711
const byte* ptr) /*!< in: pointer to the page */
658
/* out: compressed page descriptor, or NULL */
659
const byte* ptr) /* in: pointer to the page */
713
return(buf_block_get_page_zip(buf_block_align(ptr)));
661
const page_zip_des_t* page_zip;
662
buf_pool_mutex_enter();
663
page_zip = buf_block_get_page_zip(buf_block_align(ptr));
664
buf_pool_mutex_exit();
715
667
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
716
#endif /* !UNIV_HOTBACKUP */
718
/**********************************************************************//**
669
/**************************************************************************
719
670
Gets the space id, page offset, and byte offset within page of a
720
671
pointer pointing to a buffer frame containing a file page. */
723
674
buf_ptr_get_fsp_addr(
724
675
/*=================*/
725
const void* ptr, /*!< in: pointer to a buffer frame */
726
ulint* space, /*!< out: space id */
727
fil_addr_t* addr) /*!< out: page offset and byte offset */
676
const void* ptr, /* in: pointer to a buffer frame */
677
ulint* space, /* out: space id */
678
fil_addr_t* addr) /* out: page offset and byte offset */
729
680
const page_t* page = (const page_t*) ut_align_down(ptr,
734
685
addr->boffset = ut_align_offset(ptr, UNIV_PAGE_SIZE);
737
#ifndef UNIV_HOTBACKUP
738
/**********************************************************************//**
688
/**************************************************************************
739
689
Gets the hash value of the page the pointer is pointing to. This can be used
740
in searches in the lock hash table.
741
@return lock hash value */
690
in searches in the lock hash table. */
744
693
buf_block_get_lock_hash_val(
745
694
/*========================*/
746
const buf_block_t* block) /*!< in: block */
695
/* out: lock hash value */
696
const buf_block_t* block) /* in: block */
749
ut_ad(buf_page_in_file(&block->page));
750
#ifdef UNIV_SYNC_DEBUG
751
ut_ad(rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_EXCLUSIVE)
752
|| rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_SHARED));
753
#endif /* UNIV_SYNC_DEBUG */
754
698
return(block->lock_hash_val);
757
/********************************************************************//**
701
/************************************************************************
702
Allocates a buffer block. */
707
/* out, own: the allocated block,
708
in state BUF_BLOCK_MEMORY */
709
ulint zip_size) /* in: compressed page size in bytes,
710
or 0 if uncompressed tablespace */
714
block = buf_LRU_get_free_block(zip_size);
716
buf_block_set_state(block, BUF_BLOCK_MEMORY);
721
/************************************************************************
758
722
Frees a buffer block which does not contain a file page. */
763
buf_block_t* block) /*!< in, own: block to be freed */
727
buf_block_t* block) /* in, own: block to be freed */
765
buf_pool_t* buf_pool = buf_pool_from_bpage((buf_page_t*)block);
767
buf_pool_mutex_enter(buf_pool);
729
buf_pool_mutex_enter();
769
731
mutex_enter(&block->mutex);
798
#ifndef UNIV_HOTBACKUP
799
/********************************************************************//**
759
/************************************************************************
800
760
Calculates a folded value of a file page address to use in the page hash
802
@return the folded value */
805
764
buf_page_address_fold(
806
765
/*==================*/
807
ulint space, /*!< in: space id */
808
ulint offset) /*!< in: offset of the page within space */
766
/* out: the folded value */
767
ulint space, /* in: space id */
768
ulint offset) /* in: offset of the page within space */
810
770
return((space << 20) + space + offset);
813
/********************************************************************//**
773
/************************************************************************
774
This function is used to get info if there is an io operation
775
going on on a buffer page. */
780
/* out: TRUE if io going on */
781
buf_page_t* bpage) /* in: buf_pool block, must be bufferfixed */
785
buf_pool_mutex_enter();
787
ut_ad(buf_page_in_file(bpage));
788
ut_ad(bpage->buf_fix_count > 0);
790
io_fixed = buf_page_get_io_fix(bpage) != BUF_IO_NONE;
791
buf_pool_mutex_exit();
796
/************************************************************************
814
797
Gets the youngest modification log sequence number for a frame.
815
Returns zero if not file page or no modification occurred yet.
816
@return newest modification to page */
798
Returns zero if not file page or no modification occurred yet. */
819
801
buf_page_get_newest_modification(
820
802
/*=============================*/
821
const buf_page_t* bpage) /*!< in: block containing the
803
/* out: newest modification to page */
804
const buf_page_t* bpage) /* in: block containing the
825
mutex_t* block_mutex = buf_page_get_mutex(bpage);
827
mutex_enter(block_mutex);
809
buf_pool_mutex_enter();
829
811
if (buf_page_in_file(bpage)) {
830
812
lsn = bpage->newest_modification;
931
/******************************************************************//**
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
Returns the control block of a file page, NULL if not found.
968
@return block, NULL if not found */
903
/**********************************************************************
904
Returns the control block of a file page, 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(
909
/* out: block, NULL if not found */
910
ulint space, /* in: space id */
911
ulint offset) /* in: offset of the page within space */
980
913
buf_page_t* bpage;
983
ut_ad(buf_pool_mutex_own(buf_pool));
984
ut_ad(fold == buf_page_address_fold(space, offset));
917
ut_ad(buf_pool_mutex_own());
986
919
/* Look for the page in the hash table */
921
fold = buf_page_address_fold(space, offset);
988
923
HASH_SEARCH(hash, buf_pool->page_hash, fold, buf_page_t*, bpage,
989
ut_ad(bpage->in_page_hash && !bpage->in_zip_hash
990
&& buf_page_in_file(bpage)),
991
924
bpage->space == space && bpage->offset == offset);
993
926
ut_a(buf_page_in_file(bpage));
994
927
ut_ad(bpage->in_page_hash);
995
928
ut_ad(!bpage->in_zip_hash);
996
#if UNIV_WORD_SIZE == 4
997
/* On 32-bit systems, there is no padding in
998
buf_page_t. On other systems, Valgrind could complain
999
about uninitialized pad bytes. */
1000
929
UNIV_MEM_ASSERT_RW(bpage, sizeof *bpage);
1007
/******************************************************************//**
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
/******************************************************************//**
935
/**********************************************************************
1032
936
Returns the control block of a file page, NULL if not found
1033
or an uncompressed page frame does not exist.
1034
@return block, NULL if not found */
937
or an uncompressed page frame does not exist. */
1037
940
buf_block_hash_get(
1038
941
/*===============*/
1039
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1040
ulint space, /*!< in: space id */
1041
ulint offset) /*!< in: offset of the page
942
/* out: block, NULL if not found */
943
ulint space, /* in: space id */
944
ulint offset) /* in: offset of the page within space */
1046
block = buf_page_get_block(buf_page_hash_get(buf_pool, space, offset));
946
return(buf_page_get_block(buf_page_hash_get(space, offset)));
1051
/********************************************************************//**
1052
Returns TRUE if the page can be found in the buffer pool hash table.
1054
NOTE that it is possible that the page is not yet read from disk,
1057
@return TRUE if found in the page hash table */
949
/************************************************************************
950
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
951
that it is possible that the page is not yet read from disk, though. */
1062
ulint space, /*!< in: space id */
1063
ulint offset) /*!< in: page number */
956
/* out: TRUE if found from page hash table,
957
NOTE that the page is not necessarily yet read
959
ulint space, /* in: space id */
960
ulint offset) /* in: page number */
1065
962
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);
964
buf_pool_mutex_enter();
966
bpage = buf_page_hash_get(space, offset);
968
buf_pool_mutex_exit();
1074
970
return(bpage != NULL);
1077
/********************************************************************//**
973
/************************************************************************
1078
974
Releases a compressed-only page acquired with buf_page_get_zip(). */
1081
977
buf_page_release_zip(
1082
978
/*=================*/
1083
buf_page_t* bpage) /*!< in: buffer block */
979
buf_page_t* bpage) /* in: buffer block */
1085
981
buf_block_t* block;
1086
buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
1089
984
ut_a(bpage->buf_fix_count > 0);