1
/******************************************************
2
The database buffer replacement algorithm
6
Created 11/5/1995 Heikki Tuuri
7
*******************************************************/
13
#include "srv0srv.h" /* Needed to getsrv_print_innodb_monitor */
19
#include "sync0sync.h"
21
#include "hash0hash.h"
32
/* The number of blocks from the LRU_old pointer onward, including the block
33
pointed to, must be 3/8 of the whole LRU list length, except that the
34
tolerance defined below is allowed. Note that the tolerance must be small
35
enough such that for even the BUF_LRU_OLD_MIN_LEN long LRU list, the
36
LRU_old pointer is not allowed to point to either end of the LRU list. */
38
#define BUF_LRU_OLD_TOLERANCE 20
40
/* The whole LRU list length is divided by this number to determine an
41
initial segment in buf_LRU_get_recent_limit */
43
#define BUF_LRU_INITIAL_RATIO 8
45
/* If we switch on the InnoDB monitor because there are too few available
46
frames in the buffer pool, we set this to TRUE */
47
ibool buf_lru_switched_on_innodb_mon = FALSE;
49
/**********************************************************************
50
Takes a block out of the LRU list and page hash table and sets the block
51
state to BUF_BLOCK_REMOVE_HASH. */
54
buf_LRU_block_remove_hashed_page(
55
/*=============================*/
56
buf_block_t* block); /* in: block, must contain a file page and
57
be in a state where it can be freed; there
58
may or may not be a hash index to the page */
59
/**********************************************************************
60
Puts a file page whose has no hash index to the free list. */
63
buf_LRU_block_free_hashed_page(
64
/*===========================*/
65
buf_block_t* block); /* in: block, must contain a file page and
66
be in a state where it can be freed */
68
/**********************************************************************
69
Invalidates all pages belonging to a given tablespace when we are deleting
70
the data file(s) of that tablespace. */
73
buf_LRU_invalidate_tablespace(
74
/*==========================*/
75
ulint id) /* in: space id */
82
mutex_enter(&(buf_pool->mutex));
86
block = UT_LIST_GET_LAST(buf_pool->LRU);
88
while (block != NULL) {
89
buf_block_t* prev_block;
91
mutex_enter(&block->mutex);
92
prev_block = UT_LIST_GET_PREV(LRU, block);
94
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
96
if (block->space == id
97
&& (block->buf_fix_count > 0 || block->io_fix != 0)) {
99
/* We cannot remove this page during this scan yet;
100
maybe the system is currently reading it in, or
101
flushing the modifications to the file */
108
if (block->space == id) {
110
if (buf_debug_prints) {
112
"Dropping space %lu page %lu\n",
113
(ulong) block->space,
114
(ulong) block->offset);
117
if (block->is_hashed) {
118
page_no = block->offset;
120
mutex_exit(&block->mutex);
122
mutex_exit(&(buf_pool->mutex));
124
/* Note that the following call will acquire
125
an S-latch on the page */
127
btr_search_drop_page_hash_when_freed(id,
132
if (0 != ut_dulint_cmp(block->oldest_modification,
135
/* Remove from the flush list of modified
137
block->oldest_modification = ut_dulint_zero;
139
UT_LIST_REMOVE(flush_list,
140
buf_pool->flush_list, block);
143
/* Remove from the LRU list */
144
buf_LRU_block_remove_hashed_page(block);
145
buf_LRU_block_free_hashed_page(block);
148
mutex_exit(&block->mutex);
152
mutex_exit(&(buf_pool->mutex));
155
os_thread_sleep(20000);
161
/**********************************************************************
162
Gets the minimum LRU_position field for the blocks in an initial segment
163
(determined by BUF_LRU_INITIAL_RATIO) of the LRU list. The limit is not
164
guaranteed to be precise, because the ulint_clock may wrap around. */
167
buf_LRU_get_recent_limit(void)
168
/*==========================*/
169
/* out: the limit; zero if could not determine it */
175
mutex_enter(&(buf_pool->mutex));
177
len = UT_LIST_GET_LEN(buf_pool->LRU);
179
if (len < BUF_LRU_OLD_MIN_LEN) {
180
/* The LRU list is too short to do read-ahead */
182
mutex_exit(&(buf_pool->mutex));
187
block = UT_LIST_GET_FIRST(buf_pool->LRU);
189
limit = block->LRU_position - len / BUF_LRU_INITIAL_RATIO;
191
mutex_exit(&(buf_pool->mutex));
196
/**********************************************************************
197
Look for a replaceable block from the end of the LRU list and put it to
198
the free list if found. */
201
buf_LRU_search_and_free_block(
202
/*==========================*/
203
/* out: TRUE if freed */
204
ulint n_iterations) /* in: how many times this has been called
205
repeatedly without result: a high value means
206
that we should search farther; if value is
207
k < 10, then we only search k/10 * [number
208
of pages in the buffer pool] from the end
215
mutex_enter(&(buf_pool->mutex));
218
block = UT_LIST_GET_LAST(buf_pool->LRU);
220
while (block != NULL) {
221
ut_a(block->in_LRU_list);
223
mutex_enter(&block->mutex);
225
if (buf_flush_ready_for_replace(block)) {
228
if (buf_debug_prints) {
230
"Putting space %lu page %lu"
232
(ulong) block->space,
233
(ulong) block->offset);
235
#endif /* UNIV_DEBUG */
237
buf_LRU_block_remove_hashed_page(block);
239
mutex_exit(&(buf_pool->mutex));
240
mutex_exit(&block->mutex);
242
/* Remove possible adaptive hash index built on the
243
page; in the case of AWE the block may not have a
247
/* The page was declared uninitialized
248
by buf_LRU_block_remove_hashed_page().
249
We need to flag the contents of the
250
page valid (which it still is) in
251
order to avoid bogus Valgrind
253
UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE);
254
btr_search_drop_page_hash_index(block->frame);
255
UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE);
258
ut_a(block->buf_fix_count == 0);
260
mutex_enter(&(buf_pool->mutex));
261
mutex_enter(&block->mutex);
263
buf_LRU_block_free_hashed_page(block);
265
mutex_exit(&block->mutex);
270
mutex_exit(&block->mutex);
272
block = UT_LIST_GET_PREV(LRU, block);
275
if (!freed && n_iterations <= 10
276
&& distance > 100 + (n_iterations * buf_pool->curr_size)
278
buf_pool->LRU_flush_ended = 0;
280
mutex_exit(&(buf_pool->mutex));
285
if (buf_pool->LRU_flush_ended > 0) {
286
buf_pool->LRU_flush_ended--;
289
buf_pool->LRU_flush_ended = 0;
291
mutex_exit(&(buf_pool->mutex));
296
/**********************************************************************
297
Tries to remove LRU flushed blocks from the end of the LRU list and put them
298
to the free list. This is beneficial for the efficiency of the insert buffer
299
operation, as flushed pages from non-unique non-clustered indexes are here
300
taken out of the buffer pool, and their inserts redirected to the insert
301
buffer. Otherwise, the flushed blocks could get modified again before read
302
operations need new buffer blocks, and the i/o work done in flushing would be
306
buf_LRU_try_free_flushed_blocks(void)
307
/*=================================*/
309
mutex_enter(&(buf_pool->mutex));
311
while (buf_pool->LRU_flush_ended > 0) {
313
mutex_exit(&(buf_pool->mutex));
315
buf_LRU_search_and_free_block(1);
317
mutex_enter(&(buf_pool->mutex));
320
mutex_exit(&(buf_pool->mutex));
323
/**********************************************************************
324
Returns TRUE if less than 25 % of the buffer pool is available. This can be
325
used in heuristics to prevent huge transactions eating up the whole buffer
326
pool for their locks. */
329
buf_LRU_buf_pool_running_out(void)
330
/*==============================*/
331
/* out: TRUE if less than 25 % of buffer pool
336
mutex_enter(&(buf_pool->mutex));
338
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
339
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->max_size / 4) {
344
mutex_exit(&(buf_pool->mutex));
349
/**********************************************************************
350
Returns a free block from buf_pool. The block is taken off the free list.
351
If it is empty, blocks are moved from the end of the LRU list to the free
355
buf_LRU_get_free_block(void)
356
/*========================*/
357
/* out: the free control block; also if AWE is
358
used, it is guaranteed that the block has its
359
page mapped to a frame when we return */
361
buf_block_t* block = NULL;
363
ulint n_iterations = 1;
364
ibool mon_value_was = FALSE;
365
ibool started_monitor = FALSE;
367
mutex_enter(&(buf_pool->mutex));
369
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
370
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->max_size / 20) {
371
ut_print_timestamp(stderr);
374
" InnoDB: ERROR: over 95 percent of the buffer pool"
376
"InnoDB: lock heaps or the adaptive hash index!"
378
"InnoDB: transactions do not set too many row locks.\n"
379
"InnoDB: Your buffer pool size is %lu MB."
380
" Maybe you should make\n"
381
"InnoDB: the buffer pool bigger?\n"
382
"InnoDB: We intentionally generate a seg fault"
383
" to print a stack trace\n"
384
"InnoDB: on Linux!\n",
385
(ulong) (buf_pool->curr_size
386
/ (1024 * 1024 / UNIV_PAGE_SIZE)));
390
} else if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
391
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->max_size / 3) {
393
if (!buf_lru_switched_on_innodb_mon) {
395
/* Over 67 % of the buffer pool is occupied by lock
396
heaps or the adaptive hash index. This may be a memory
399
ut_print_timestamp(stderr);
401
" InnoDB: WARNING: over 67 percent of"
402
" the buffer pool is occupied by\n"
403
"InnoDB: lock heaps or the adaptive"
404
" hash index! Check that your\n"
405
"InnoDB: transactions do not set too many"
407
"InnoDB: Your buffer pool size is %lu MB."
408
" Maybe you should make\n"
409
"InnoDB: the buffer pool bigger?\n"
410
"InnoDB: Starting the InnoDB Monitor to print"
411
" diagnostics, including\n"
412
"InnoDB: lock heap and hash index sizes.\n",
413
(ulong) (buf_pool->curr_size
414
/ (1024 * 1024 / UNIV_PAGE_SIZE)));
416
buf_lru_switched_on_innodb_mon = TRUE;
417
srv_print_innodb_monitor = TRUE;
418
os_event_set(srv_lock_timeout_thread_event);
420
} else if (buf_lru_switched_on_innodb_mon) {
422
/* Switch off the InnoDB Monitor; this is a simple way
423
to stop the monitor if the situation becomes less urgent,
424
but may also surprise users if the user also switched on the
427
buf_lru_switched_on_innodb_mon = FALSE;
428
srv_print_innodb_monitor = FALSE;
431
/* If there is a block in the free list, take it */
432
if (UT_LIST_GET_LEN(buf_pool->free) > 0) {
434
block = UT_LIST_GET_FIRST(buf_pool->free);
435
ut_a(block->in_free_list);
436
UT_LIST_REMOVE(free, buf_pool->free, block);
437
block->in_free_list = FALSE;
438
ut_a(block->state != BUF_BLOCK_FILE_PAGE);
439
ut_a(!block->in_LRU_list);
443
/* Remove from the list of mapped pages */
445
UT_LIST_REMOVE(awe_LRU_free_mapped,
446
buf_pool->awe_LRU_free_mapped,
449
/* We map the page to a frame; second param
450
FALSE below because we do not want it to be
451
added to the awe_LRU_free_mapped list */
453
buf_awe_map_page_to_frame(block, FALSE);
457
mutex_enter(&block->mutex);
459
block->state = BUF_BLOCK_READY_FOR_USE;
460
UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE);
462
mutex_exit(&block->mutex);
464
mutex_exit(&(buf_pool->mutex));
466
if (started_monitor) {
467
srv_print_innodb_monitor = mon_value_was;
473
/* If no block was in the free list, search from the end of the LRU
474
list and try to free a block there */
476
mutex_exit(&(buf_pool->mutex));
478
freed = buf_LRU_search_and_free_block(n_iterations);
484
if (n_iterations > 30) {
485
ut_print_timestamp(stderr);
487
"InnoDB: Warning: difficult to find free blocks from\n"
488
"InnoDB: the buffer pool (%lu search iterations)!"
490
"InnoDB: increasing the buffer pool size.\n"
491
"InnoDB: It is also possible that"
492
" in your Unix version\n"
493
"InnoDB: fsync is very slow, or"
494
" completely frozen inside\n"
495
"InnoDB: the OS kernel. Then upgrading to"
497
"InnoDB: of your operating system may help."
499
"InnoDB: number of fsyncs in diagnostic info below.\n"
500
"InnoDB: Pending flushes (fsync) log: %lu;"
501
" buffer pool: %lu\n"
502
"InnoDB: %lu OS file reads, %lu OS file writes,"
504
"InnoDB: Starting InnoDB Monitor to print further\n"
505
"InnoDB: diagnostics to the standard output.\n",
506
(ulong) n_iterations,
507
(ulong) fil_n_pending_log_flushes,
508
(ulong) fil_n_pending_tablespace_flushes,
509
(ulong) os_n_file_reads, (ulong) os_n_file_writes,
510
(ulong) os_n_fsyncs);
512
mon_value_was = srv_print_innodb_monitor;
513
started_monitor = TRUE;
514
srv_print_innodb_monitor = TRUE;
515
os_event_set(srv_lock_timeout_thread_event);
518
/* No free block was found: try to flush the LRU list */
520
buf_flush_free_margin();
521
++srv_buf_pool_wait_free;
523
os_aio_simulated_wake_handler_threads();
525
mutex_enter(&(buf_pool->mutex));
527
if (buf_pool->LRU_flush_ended > 0) {
528
/* We have written pages in an LRU flush. To make the insert
529
buffer more efficient, we try to move these pages to the free
532
mutex_exit(&(buf_pool->mutex));
534
buf_LRU_try_free_flushed_blocks();
536
mutex_exit(&(buf_pool->mutex));
539
if (n_iterations > 10) {
541
os_thread_sleep(500000);
549
/***********************************************************************
550
Moves the LRU_old pointer so that the length of the old blocks list
551
is inside the allowed limits. */
554
buf_LRU_old_adjust_len(void)
555
/*========================*/
560
ut_a(buf_pool->LRU_old);
561
ut_ad(mutex_own(&(buf_pool->mutex)));
562
ut_ad(3 * (BUF_LRU_OLD_MIN_LEN / 8) > BUF_LRU_OLD_TOLERANCE + 5);
565
old_len = buf_pool->LRU_old_len;
566
new_len = 3 * (UT_LIST_GET_LEN(buf_pool->LRU) / 8);
568
ut_a(buf_pool->LRU_old->in_LRU_list);
570
/* Update the LRU_old pointer if necessary */
572
if (old_len < new_len - BUF_LRU_OLD_TOLERANCE) {
574
buf_pool->LRU_old = UT_LIST_GET_PREV(
575
LRU, buf_pool->LRU_old);
576
(buf_pool->LRU_old)->old = TRUE;
577
buf_pool->LRU_old_len++;
579
} else if (old_len > new_len + BUF_LRU_OLD_TOLERANCE) {
581
(buf_pool->LRU_old)->old = FALSE;
582
buf_pool->LRU_old = UT_LIST_GET_NEXT(
583
LRU, buf_pool->LRU_old);
584
buf_pool->LRU_old_len--;
586
ut_a(buf_pool->LRU_old); /* Check that we did not
587
fall out of the LRU list */
593
/***********************************************************************
594
Initializes the old blocks pointer in the LRU list. This function should be
595
called when the LRU list grows to BUF_LRU_OLD_MIN_LEN length. */
598
buf_LRU_old_init(void)
599
/*==================*/
603
ut_ad(mutex_own(&(buf_pool->mutex)));
604
ut_a(UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN);
606
/* We first initialize all blocks in the LRU list as old and then use
607
the adjust function to move the LRU_old pointer to the right
610
block = UT_LIST_GET_FIRST(buf_pool->LRU);
612
while (block != NULL) {
613
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
614
ut_a(block->in_LRU_list);
616
block = UT_LIST_GET_NEXT(LRU, block);
619
buf_pool->LRU_old = UT_LIST_GET_FIRST(buf_pool->LRU);
620
buf_pool->LRU_old_len = UT_LIST_GET_LEN(buf_pool->LRU);
622
buf_LRU_old_adjust_len();
625
/**********************************************************************
626
Removes a block from the LRU list. */
629
buf_LRU_remove_block(
630
/*=================*/
631
buf_block_t* block) /* in: control block */
635
ut_ad(mutex_own(&(buf_pool->mutex)));
637
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
638
ut_a(block->in_LRU_list);
640
/* If the LRU_old pointer is defined and points to just this block,
641
move it backward one step */
643
if (block == buf_pool->LRU_old) {
645
/* Below: the previous block is guaranteed to exist, because
646
the LRU_old pointer is only allowed to differ by the
647
tolerance value from strict 3/8 of the LRU list length. */
649
buf_pool->LRU_old = UT_LIST_GET_PREV(LRU, block);
650
(buf_pool->LRU_old)->old = TRUE;
652
buf_pool->LRU_old_len++;
653
ut_a(buf_pool->LRU_old);
656
/* Remove the block from the LRU list */
657
UT_LIST_REMOVE(LRU, buf_pool->LRU, block);
658
block->in_LRU_list = FALSE;
660
if (srv_use_awe && block->frame) {
661
/* Remove from the list of mapped pages */
663
UT_LIST_REMOVE(awe_LRU_free_mapped,
664
buf_pool->awe_LRU_free_mapped, block);
667
/* If the LRU list is so short that LRU_old not defined, return */
668
if (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN) {
670
buf_pool->LRU_old = NULL;
675
ut_ad(buf_pool->LRU_old);
677
/* Update the LRU_old_len field if necessary */
680
buf_pool->LRU_old_len--;
683
/* Adjust the length of the old block list if necessary */
684
buf_LRU_old_adjust_len();
687
/**********************************************************************
688
Adds a block to the LRU list end. */
691
buf_LRU_add_block_to_end_low(
692
/*=========================*/
693
buf_block_t* block) /* in: control block */
695
buf_block_t* last_block;
699
ut_ad(mutex_own(&(buf_pool->mutex)));
701
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
705
last_block = UT_LIST_GET_LAST(buf_pool->LRU);
708
block->LRU_position = last_block->LRU_position;
710
block->LRU_position = buf_pool_clock_tic();
713
ut_a(!block->in_LRU_list);
714
UT_LIST_ADD_LAST(LRU, buf_pool->LRU, block);
715
block->in_LRU_list = TRUE;
717
if (srv_use_awe && block->frame) {
718
/* Add to the list of mapped pages */
720
UT_LIST_ADD_LAST(awe_LRU_free_mapped,
721
buf_pool->awe_LRU_free_mapped, block);
724
if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) {
726
buf_pool->LRU_old_len++;
729
if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
731
ut_ad(buf_pool->LRU_old);
733
/* Adjust the length of the old block list if necessary */
735
buf_LRU_old_adjust_len();
737
} else if (UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN) {
739
/* The LRU list is now long enough for LRU_old to become
746
/**********************************************************************
747
Adds a block to the LRU list. */
750
buf_LRU_add_block_low(
751
/*==================*/
752
buf_block_t* block, /* in: control block */
753
ibool old) /* in: TRUE if should be put to the old blocks
754
in the LRU list, else put to the start; if the
755
LRU list is very short, the block is added to
756
the start, regardless of this parameter */
762
ut_ad(mutex_own(&(buf_pool->mutex)));
764
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
765
ut_a(!block->in_LRU_list);
768
cl = buf_pool_clock_tic();
770
if (srv_use_awe && block->frame) {
771
/* Add to the list of mapped pages; for simplicity we always
772
add to the start, even if the user would have set 'old'
775
UT_LIST_ADD_FIRST(awe_LRU_free_mapped,
776
buf_pool->awe_LRU_free_mapped, block);
779
if (!old || (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN)) {
781
UT_LIST_ADD_FIRST(LRU, buf_pool->LRU, block);
783
block->LRU_position = cl;
784
block->freed_page_clock = buf_pool->freed_page_clock;
786
UT_LIST_INSERT_AFTER(LRU, buf_pool->LRU, buf_pool->LRU_old,
788
buf_pool->LRU_old_len++;
790
/* We copy the LRU position field of the previous block
793
block->LRU_position = (buf_pool->LRU_old)->LRU_position;
796
block->in_LRU_list = TRUE;
798
if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
800
ut_ad(buf_pool->LRU_old);
802
/* Adjust the length of the old block list if necessary */
804
buf_LRU_old_adjust_len();
806
} else if (UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN) {
808
/* The LRU list is now long enough for LRU_old to become
815
/**********************************************************************
816
Adds a block to the LRU list. */
821
buf_block_t* block, /* in: control block */
822
ibool old) /* in: TRUE if should be put to the old
823
blocks in the LRU list, else put to the start;
824
if the LRU list is very short, the block is
825
added to the start, regardless of this
828
buf_LRU_add_block_low(block, old);
831
/**********************************************************************
832
Moves a block to the start of the LRU list. */
835
buf_LRU_make_block_young(
836
/*=====================*/
837
buf_block_t* block) /* in: control block */
839
buf_LRU_remove_block(block);
840
buf_LRU_add_block_low(block, FALSE);
843
/**********************************************************************
844
Moves a block to the end of the LRU list. */
847
buf_LRU_make_block_old(
848
/*===================*/
849
buf_block_t* block) /* in: control block */
851
buf_LRU_remove_block(block);
852
buf_LRU_add_block_to_end_low(block);
855
/**********************************************************************
856
Puts a block back to the free list. */
859
buf_LRU_block_free_non_file_page(
860
/*=============================*/
861
buf_block_t* block) /* in: block, must not contain a file page */
864
ut_ad(mutex_own(&(buf_pool->mutex)));
865
ut_ad(mutex_own(&block->mutex));
868
ut_a((block->state == BUF_BLOCK_MEMORY)
869
|| (block->state == BUF_BLOCK_READY_FOR_USE));
871
ut_a(block->n_pointers == 0);
872
ut_a(!block->in_free_list);
874
block->state = BUF_BLOCK_NOT_USED;
876
UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE);
878
/* Wipe contents of page to reveal possible stale pointers to it */
879
memset(block->frame, '\0', UNIV_PAGE_SIZE);
881
UT_LIST_ADD_FIRST(free, buf_pool->free, block);
882
block->in_free_list = TRUE;
884
UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
886
if (srv_use_awe && block->frame) {
887
/* Add to the list of mapped pages */
889
UT_LIST_ADD_FIRST(awe_LRU_free_mapped,
890
buf_pool->awe_LRU_free_mapped, block);
894
/**********************************************************************
895
Takes a block out of the LRU list and page hash table and sets the block
896
state to BUF_BLOCK_REMOVE_HASH. */
899
buf_LRU_block_remove_hashed_page(
900
/*=============================*/
901
buf_block_t* block) /* in: block, must contain a file page and
902
be in a state where it can be freed; there
903
may or may not be a hash index to the page */
905
ut_ad(mutex_own(&(buf_pool->mutex)));
906
ut_ad(mutex_own(&block->mutex));
909
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
910
ut_a(block->io_fix == 0);
911
ut_a(block->buf_fix_count == 0);
912
ut_a(ut_dulint_cmp(block->oldest_modification, ut_dulint_zero) == 0);
914
buf_LRU_remove_block(block);
916
buf_pool->freed_page_clock += 1;
918
/* Note that if AWE is enabled the block may not have a frame at all */
920
buf_block_modify_clock_inc(block);
922
if (block != buf_page_hash_get(block->space, block->offset)) {
924
"InnoDB: Error: page %lu %lu not found"
925
" in the hash table\n",
926
(ulong) block->space,
927
(ulong) block->offset);
928
if (buf_page_hash_get(block->space, block->offset)) {
930
"InnoDB: In hash table we find block"
931
" %p of %lu %lu which is not %p\n",
932
(void*) buf_page_hash_get
933
(block->space, block->offset),
934
(ulong) buf_page_hash_get
935
(block->space, block->offset)->space,
936
(ulong) buf_page_hash_get
937
(block->space, block->offset)->offset,
950
HASH_DELETE(buf_block_t, hash, buf_pool->page_hash,
951
buf_page_address_fold(block->space, block->offset),
954
UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE);
955
block->state = BUF_BLOCK_REMOVE_HASH;
958
/**********************************************************************
959
Puts a file page whose has no hash index to the free list. */
962
buf_LRU_block_free_hashed_page(
963
/*===========================*/
964
buf_block_t* block) /* in: block, must contain a file page and
965
be in a state where it can be freed */
967
ut_ad(mutex_own(&(buf_pool->mutex)));
968
ut_ad(mutex_own(&block->mutex));
970
ut_a(block->state == BUF_BLOCK_REMOVE_HASH);
972
block->state = BUF_BLOCK_MEMORY;
974
buf_LRU_block_free_non_file_page(block);
978
/**************************************************************************
979
Validates the LRU list. */
982
buf_LRU_validate(void)
983
/*==================*/
991
mutex_enter(&(buf_pool->mutex));
993
if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) {
995
ut_a(buf_pool->LRU_old);
996
old_len = buf_pool->LRU_old_len;
997
new_len = 3 * (UT_LIST_GET_LEN(buf_pool->LRU) / 8);
998
ut_a(old_len >= new_len - BUF_LRU_OLD_TOLERANCE);
999
ut_a(old_len <= new_len + BUF_LRU_OLD_TOLERANCE);
1002
UT_LIST_VALIDATE(LRU, buf_block_t, buf_pool->LRU);
1004
block = UT_LIST_GET_FIRST(buf_pool->LRU);
1008
while (block != NULL) {
1010
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
1016
if (buf_pool->LRU_old && (old_len == 1)) {
1017
ut_a(buf_pool->LRU_old == block);
1020
LRU_pos = block->LRU_position;
1022
block = UT_LIST_GET_NEXT(LRU, block);
1025
/* If the following assert fails, it may
1026
not be an error: just the buf_pool clock
1027
has wrapped around */
1028
ut_a(LRU_pos >= block->LRU_position);
1032
if (buf_pool->LRU_old) {
1033
ut_a(buf_pool->LRU_old_len == old_len);
1036
UT_LIST_VALIDATE(free, buf_block_t, buf_pool->free);
1038
block = UT_LIST_GET_FIRST(buf_pool->free);
1040
while (block != NULL) {
1041
ut_a(block->state == BUF_BLOCK_NOT_USED);
1043
block = UT_LIST_GET_NEXT(free, block);
1046
mutex_exit(&(buf_pool->mutex));
1050
/**************************************************************************
1051
Prints the LRU list. */
1062
mutex_enter(&(buf_pool->mutex));
1064
fprintf(stderr, "Pool ulint clock %lu\n",
1065
(ulong) buf_pool->ulint_clock);
1067
block = UT_LIST_GET_FIRST(buf_pool->LRU);
1071
while (block != NULL) {
1073
fprintf(stderr, "BLOCK %lu ", (ulong) block->offset);
1076
fputs("old ", stderr);
1079
if (block->buf_fix_count) {
1080
fprintf(stderr, "buffix count %lu ",
1081
(ulong) block->buf_fix_count);
1084
if (block->io_fix) {
1085
fprintf(stderr, "io_fix %lu ", (ulong) block->io_fix);
1088
if (ut_dulint_cmp(block->oldest_modification,
1089
ut_dulint_zero) > 0) {
1090
fputs("modif. ", stderr);
1093
frame = buf_block_get_frame(block);
1095
fprintf(stderr, "LRU pos %lu type %lu index id %lu ",
1096
(ulong) block->LRU_position,
1097
(ulong) fil_page_get_type(frame),
1098
(ulong) ut_dulint_get_low
1099
(btr_page_get_index_id(frame)));
1101
block = UT_LIST_GET_NEXT(LRU, block);
1108
mutex_exit(&(buf_pool->mutex));
1110
#endif /* UNIV_DEBUG */