837
837
block = chunk->blocks;
839
839
for (i = chunk->size; i--; block++) {
842
switch (buf_block_get_state(block)) {
843
case BUF_BLOCK_ZIP_FREE:
844
case BUF_BLOCK_ZIP_PAGE:
845
case BUF_BLOCK_ZIP_DIRTY:
846
/* The uncompressed buffer pool should never
847
contain compressed block descriptors. */
850
case BUF_BLOCK_NOT_USED:
851
case BUF_BLOCK_READY_FOR_USE:
852
case BUF_BLOCK_MEMORY:
853
case BUF_BLOCK_REMOVE_HASH:
854
/* Skip blocks that are not being used for
857
case BUF_BLOCK_FILE_PAGE:
858
mutex_enter(&block->mutex);
859
ready = buf_flush_ready_for_replace(&block->page);
840
mutex_enter(&block->mutex);
842
if (buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE
843
&& !buf_flush_ready_for_replace(&block->page)) {
860
845
mutex_exit(&block->mutex);
849
mutex_exit(&block->mutex);
1167
1146
#ifdef UNIV_LRU_DEBUG
1168
1147
/* buf_pool->LRU_old must be the first item in the LRU list
1169
1148
whose "old" flag is set. */
1170
ut_a(buf_pool->LRU_old->old);
1171
1149
ut_a(!UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)
1172
1150
|| !UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)->old);
1173
1151
ut_a(!UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)
1174
1152
|| UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)->old);
1176
/* Check that the "old" flag is consistent in
1177
the block and its neighbours. */
1178
buf_page_set_old(dpage, buf_page_is_old(dpage));
1179
1153
#endif /* UNIV_LRU_DEBUG */
1499
1473
/********************************************************************//**
1474
Moves the block to the start of the LRU list if there is a danger
1475
that the block would drift out of the buffer pool. */
1478
buf_block_make_young(
1479
/*=================*/
1480
buf_page_t* bpage) /*!< in: block to make younger */
1482
ut_ad(!buf_pool_mutex_own());
1484
/* Note that we read freed_page_clock's without holding any mutex:
1485
this is allowed since the result is used only in heuristics */
1487
if (buf_page_peek_if_too_old(bpage)) {
1489
buf_pool_mutex_enter();
1490
/* There has been freeing activity in the LRU list:
1491
best to move to the head of the LRU list */
1493
buf_LRU_make_block_young(bpage);
1494
buf_pool_mutex_exit();
1498
/********************************************************************//**
1500
1499
Moves a page to the start of the buffer pool LRU list. This high-level
1501
function can be used to prevent an important page from slipping out of
1500
function can be used to prevent an important page from from slipping out of
1502
1501
the buffer pool. */
1518
1517
/********************************************************************//**
1519
Sets the time of the first access of a page and moves a page to the
1520
start of the buffer pool LRU list if it is too old. This high-level
1521
function can be used to prevent an important page from slipping
1522
out of the buffer pool. */
1525
buf_page_set_accessed_make_young(
1526
/*=============================*/
1527
buf_page_t* bpage, /*!< in/out: buffer block of a
1529
unsigned access_time) /*!< in: bpage->access_time
1530
read under mutex protection,
1533
ut_ad(!buf_pool_mutex_own());
1534
ut_a(buf_page_in_file(bpage));
1536
if (buf_page_peek_if_too_old(bpage)) {
1537
buf_pool_mutex_enter();
1538
buf_LRU_make_block_young(bpage);
1539
buf_pool_mutex_exit();
1540
} else if (!access_time) {
1541
ulint time_ms = ut_time_ms();
1542
buf_pool_mutex_enter();
1543
buf_page_set_accessed(bpage, time_ms);
1544
buf_pool_mutex_exit();
1548
/********************************************************************//**
1549
1518
Resets the check_index_page_at_flush field of a page if found in the buffer
2274
2243
UNIV_MEM_ASSERT_RW(&block->page, sizeof block->page);
2276
2245
buf_block_buf_fix_inc(block, file, line);
2246
buf_pool_mutex_exit();
2248
/* Check if this is the first access to the page */
2250
accessed = buf_page_is_accessed(&block->page);
2252
buf_page_set_accessed(&block->page, TRUE);
2278
2254
mutex_exit(&block->mutex);
2280
/* Check if this is the first access to the page */
2282
access_time = buf_page_is_accessed(&block->page);
2284
buf_pool_mutex_exit();
2286
buf_page_set_accessed_make_young(&block->page, access_time);
2256
buf_block_make_young(&block->page);
2288
2258
#ifdef UNIV_DEBUG_FILE_ACCESSES
2289
2259
ut_a(!block->page.file_page_was_freed);
2385
2355
buf_block_buf_fix_inc(block, file, line);
2356
accessed = buf_page_is_accessed(&block->page);
2357
buf_page_set_accessed(&block->page, TRUE);
2387
2359
mutex_exit(&block->mutex);
2389
/* Check if this is the first access to the page.
2390
We do a dirty read on purpose, to avoid mutex contention.
2391
This field is only used for heuristic purposes; it does not
2392
affect correctness. */
2361
buf_block_make_young(&block->page);
2394
access_time = buf_page_is_accessed(&block->page);
2395
buf_page_set_accessed_make_young(&block->page, access_time);
2363
/* Check if this is the first access to the page */
2397
2365
ut_ad(!ibuf_inside()
2398
2366
|| ibuf_page(buf_block_get_space(block),
2506
2474
mutex_exit(&block->mutex);
2508
if (mode == BUF_MAKE_YOUNG && buf_page_peek_if_too_old(&block->page)) {
2509
buf_pool_mutex_enter();
2510
buf_LRU_make_block_young(&block->page);
2511
buf_pool_mutex_exit();
2512
} else if (!buf_page_is_accessed(&block->page)) {
2513
/* Above, we do a dirty read on purpose, to avoid
2514
mutex contention. The field buf_page_t::access_time
2515
is only used for heuristic purposes. Writes to the
2516
field must be protected by mutex, however. */
2517
ulint time_ms = ut_time_ms();
2519
buf_pool_mutex_enter();
2520
buf_page_set_accessed(&block->page, time_ms);
2521
buf_pool_mutex_exit();
2476
if (mode == BUF_MAKE_YOUNG) {
2477
buf_block_make_young(&block->page);
2524
2480
ut_ad(!ibuf_inside() || (mode == BUF_KEEP_OLD));
3296
3251
buf_pool_invalidate(void)
3297
3252
/*=====================*/
3302
buf_pool_mutex_enter();
3304
for (i = BUF_FLUSH_LRU; i < BUF_FLUSH_N_TYPES; i++) {
3306
/* As this function is called during startup and
3307
during redo application phase during recovery, InnoDB
3308
is single threaded (apart from IO helper threads) at
3309
this stage. No new write batch can be in intialization
3310
stage at this point. */
3311
ut_ad(buf_pool->init_flush[i] == FALSE);
3313
/* However, it is possible that a write batch that has
3314
been posted earlier is still not complete. For buffer
3315
pool invalidation to proceed we must ensure there is NO
3316
write activity happening. */
3317
if (buf_pool->n_flush[i] > 0) {
3318
buf_pool_mutex_exit();
3319
buf_flush_wait_batch_end(i);
3320
buf_pool_mutex_enter();
3324
buf_pool_mutex_exit();
3326
3256
ut_ad(buf_all_freed());
3617
3538
(ulong) buf_pool->n_flush[BUF_FLUSH_LRU],
3618
3539
(ulong) buf_pool->n_flush[BUF_FLUSH_LIST],
3619
3540
(ulong) buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE],
3620
(ulong) buf_pool->stat.n_pages_made_young,
3621
(ulong) buf_pool->stat.n_pages_not_made_young,
3622
(ulong) buf_pool->stat.n_pages_read,
3623
(ulong) buf_pool->stat.n_pages_created,
3624
(ulong) buf_pool->stat.n_pages_written);
3541
(ulong) buf_pool->n_pages_read, buf_pool->n_pages_created,
3542
(ulong) buf_pool->n_pages_written);
3626
3544
/* Count the number of blocks belonging to each index in the buffer */
3836
3755
"Buffer pool size %lu\n"
3837
3756
"Free buffers %lu\n"
3838
3757
"Database pages %lu\n"
3839
"Old database pages %lu\n"
3840
3758
"Modified db pages %lu\n"
3841
3759
"Pending reads %lu\n"
3842
3760
"Pending writes: LRU %lu, flush list %lu, single page %lu\n",
3843
(ulong) buf_pool->curr_size,
3844
3762
(ulong) UT_LIST_GET_LEN(buf_pool->free),
3845
3763
(ulong) UT_LIST_GET_LEN(buf_pool->LRU),
3846
(ulong) buf_pool->LRU_old_len,
3847
3764
(ulong) UT_LIST_GET_LEN(buf_pool->flush_list),
3848
3765
(ulong) buf_pool->n_pend_reads,
3849
3766
(ulong) buf_pool->n_flush[BUF_FLUSH_LRU]
3855
3772
current_time = time(NULL);
3856
3773
time_elapsed = 0.001 + difftime(current_time,
3857
3774
buf_pool->last_printout_time);
3775
buf_pool->last_printout_time = current_time;
3860
"Pages made young %lu, not young %lu\n"
3861
"%.2f youngs/s, %.2f non-youngs/s\n"
3862
3778
"Pages read %lu, created %lu, written %lu\n"
3863
3779
"%.2f reads/s, %.2f creates/s, %.2f writes/s\n",
3864
(ulong) buf_pool->stat.n_pages_made_young,
3865
(ulong) buf_pool->stat.n_pages_not_made_young,
3866
(buf_pool->stat.n_pages_made_young
3867
- buf_pool->old_stat.n_pages_made_young)
3869
(buf_pool->stat.n_pages_not_made_young
3870
- buf_pool->old_stat.n_pages_not_made_young)
3872
(ulong) buf_pool->stat.n_pages_read,
3873
(ulong) buf_pool->stat.n_pages_created,
3874
(ulong) buf_pool->stat.n_pages_written,
3875
(buf_pool->stat.n_pages_read
3876
- buf_pool->old_stat.n_pages_read)
3878
(buf_pool->stat.n_pages_created
3879
- buf_pool->old_stat.n_pages_created)
3881
(buf_pool->stat.n_pages_written
3882
- buf_pool->old_stat.n_pages_written)
3780
(ulong) buf_pool->n_pages_read,
3781
(ulong) buf_pool->n_pages_created,
3782
(ulong) buf_pool->n_pages_written,
3783
(buf_pool->n_pages_read - buf_pool->n_pages_read_old)
3785
(buf_pool->n_pages_created - buf_pool->n_pages_created_old)
3787
(buf_pool->n_pages_written - buf_pool->n_pages_written_old)
3883
3788
/ time_elapsed);
3885
n_gets_diff = buf_pool->stat.n_page_gets - buf_pool->old_stat.n_page_gets;
3889
"Buffer pool hit rate %lu / 1000,"
3890
" young-making rate %lu / 1000 not %lu / 1000\n",
3892
(1000 - ((1000 * (buf_pool->stat.n_pages_read
3893
- buf_pool->old_stat.n_pages_read))
3894
/ (buf_pool->stat.n_page_gets
3895
- buf_pool->old_stat.n_page_gets))),
3897
(1000 * (buf_pool->stat.n_pages_made_young
3898
- buf_pool->old_stat.n_pages_made_young)
3901
(1000 * (buf_pool->stat.n_pages_not_made_young
3902
- buf_pool->old_stat.n_pages_not_made_young)
3790
if (buf_pool->n_page_gets > buf_pool->n_page_gets_old) {
3791
fprintf(file, "Buffer pool hit rate %lu / 1000\n",
3793
(1000 - ((1000 * (buf_pool->n_pages_read
3794
- buf_pool->n_pages_read_old))
3795
/ (buf_pool->n_page_gets
3796
- buf_pool->n_page_gets_old))));
3905
3798
fputs("No buffer pool page gets since the last printout\n",
3909
/* Statistics about read ahead algorithm */
3910
fprintf(file, "Pages read ahead %.2f/s,"
3911
" evicted without access %.2f/s\n",
3912
(buf_pool->stat.n_ra_pages_read
3913
- buf_pool->old_stat.n_ra_pages_read)
3915
(buf_pool->stat.n_ra_pages_evicted
3916
- buf_pool->old_stat.n_ra_pages_evicted)
3802
buf_pool->n_page_gets_old = buf_pool->n_page_gets;
3803
buf_pool->n_pages_read_old = buf_pool->n_pages_read;
3804
buf_pool->n_pages_created_old = buf_pool->n_pages_created;
3805
buf_pool->n_pages_written_old = buf_pool->n_pages_written;
3919
3807
/* Print some values to help us with visualizing what is
3920
3808
happening with LRU eviction. */