Skip to content

Commit ba250ed

Browse files
committed
Modified the LRU function
1 parent af29632 commit ba250ed

File tree

2 files changed

+108
-3
lines changed

2 files changed

+108
-3
lines changed

storage/innobase/buf/buf0buf.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,21 +5943,21 @@ buf_page_io_complete(
59435943

59445944
buf_pool->stat.n_pages_written++;
59455945

5946-
/* mijin: TODO: NEED TO BE FIXED!!!*/
5946+
/* mijin */
59475947
if (bpage->copy_target) {
59485948
twb_meta_dir_t* entry = NULL;
59495949
ulint fold;
59505950

59515951
fold = bpage->id.fold();
59525952

59535953
rw_lock_s_lock(buf_pool->twb_hash_lock);
5954-
HASH_SEARCH(hash, buf_pool->copy_pool_cache, fold, copy_pool_meta_dir_t*, entry, ut_ad(1),
5954+
HASH_SEARCH(hash, buf_pool->copy_pool_cache, fold, twb_meta_dir_t*, entry, ut_ad(1),
59555955
entry->space == bpage->space && entry->offset == bpage->offset);
59565956
rw_lock_s_unlock(buf_pool->twb_hash_lock);
59575957

59585958
if (entry) {
59595959
rw_lock_x_lock(buf_pool->twb_hash_lock);
5960-
HASH_DELETE(copy_pool_meta_dir_t, hash, buf_pool->copy_pool_cache, fold, entry);
5960+
HASH_DELETE(twb_meta_dir_t, hash, buf_pool->copy_pool_cache, fold, entry);
59615961
rw_lock_x_unlock(buf_pool->twb_hash_lock);
59625962

59635963
free(entry);

storage/innobase/buf/buf0lru.cc

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,95 @@ buf_LRU_get_free_block(
14091409
os_thread_sleep(10000);
14101410
}
14111411

1412+
/* mijin */
1413+
buf_pool_mutex_enter(buf_pool);
1414+
1415+
if (buf_pool->batch_running
1416+
/* || (buf_pool->first_free == buf_pool->total_entry)*/) {
1417+
buf_pool_mutex_exit(buf_pool);
1418+
goto loop;
1419+
}
1420+
1421+
if (buf_pool->flush_running) {
1422+
/* Another thread is running the flush right now. Wait
1423+
for it to finish. */
1424+
ib_int64_t sig_count = os_event_reset(buf_pool->f_event);
1425+
buf_pool_mutex_exit(buf_pool);
1426+
1427+
os_event_wait_low(buf_pool->f_event, sig_count);
1428+
goto loop;
1429+
}
1430+
1431+
ulint scanned = 0;
1432+
ulint total_copied = 0;
1433+
ulint failed = 0;
1434+
ulint first_free;
1435+
bool evict_zip;
1436+
1437+
buf_pool->need_to_flush_twb = true;
1438+
buf_pool->batch_running = true;
1439+
1440+
for (buf_page_t* bpage = buf_pool->lru_scan_itr.start();
1441+
bpage != NULL && scanned < srv_LRU_scan_depth /*&& buf_pool->first_free < buf_pool->total_entry*/;
1442+
++scanned, bpage = buf_pool->lru_scan_itr.get()) {
1443+
1444+
buf_page_t* prev = UT_LIST_GET_PREV(LRU, bpage);
1445+
buf_pool->lru_scan_itr.set(prev);
1446+
1447+
/* If the target page is io-fixed or already freed, skip the
1448+
copy process. */
1449+
if (!buf_page_can_relocate(bpage) || (bpage->state != BUF_BLOCK_FILE_PAGE)) {
1450+
continue;
1451+
} else if (bpage->oldest_modification == 0) {
1452+
/* Target page is a clean page! */
1453+
evict_zip = !buf_LRU_evict_from_unzip_LRU(buf_pool);;
1454+
buf_LRU_free_page(bpage, evict_zip);
1455+
1456+
continue;
1457+
}
1458+
1459+
ib_uint32_t space = bpage->id.space();
1460+
ib_uint32_t offset = bpage->id.page_no();
1461+
ulint fold = bpage->id.fold();
1462+
1463+
first_free = buf_pool->first_free;
1464+
buf_pool->first_free++;
1465+
1466+
/* Copy the buffer frame into the copy pool. */
1467+
memcpy(buf_pool->write_buf
1468+
+ UNIV_PAGE_SIZE * first_free,
1469+
((buf_block_t*) bpage)->frame, UNIV_PAGE_SIZE);
1470+
1471+
bpage->copy_target = true;
1472+
evict_zip = !buf_LRU_evict_from_unzip_LRU(buf_pool);;
1473+
1474+
/* Free the target page from the buffer pool. */
1475+
if (buf_LRU_free_page(bpage, evict_zip)) {
1476+
twb_meta_dir_t* new_entry = (twb_meta_dir_t*) malloc(sizeof(twb_meta_dir_t));
1477+
1478+
new_entry->space = space;
1479+
new_entry->offset = offset;
1480+
1481+
rw_lock_x_lock(buf_pool->twb_hash_lock);
1482+
HASH_INSERT(twb_meta_dir_t, hash, buf_pool->twb_hash, fold, new_entry);
1483+
rw_lock_x_unlock(buf_pool->twb_hash_lock);
1484+
1485+
total_copied++;
1486+
} else {
1487+
failed++;
1488+
}
1489+
}
1490+
1491+
buf_pool->batch_running = false;
1492+
os_event_set(buf_pool->b_event);
1493+
1494+
buf_pool_mutex_exit(buf_pool);
1495+
1496+
if (total_copied) {
1497+
goto loop;
1498+
}
1499+
/* end */
1500+
14121501
/* No free block was found: try to flush the LRU list.
14131502
This call will flush one page from the LRU and put it on the
14141503
free list. That means that the free block is up for grabs for
@@ -1616,6 +1705,22 @@ buf_LRU_remove_block(
16161705
UT_LIST_REMOVE(buf_pool->LRU, bpage);
16171706
ut_d(bpage->in_LRU_list = FALSE);
16181707

1708+
/* mijin: TODO: need to fix this part! */
1709+
if (bpage->copy_target) {
1710+
buf_flush_list_mutex_enter(buf_pool);
1711+
buf_pool->flush_hp.adjust(bpage);
1712+
1713+
UT_LIST_REMOVE(buf_pool->flush_list, bpage);
1714+
1715+
if ((buf_pool->flush_list_hp == bpage)) {
1716+
buf_pool->flush_list_hp = bpage;
1717+
MONITOR_INC(MONITOR_FLUSH_HP_RESCAN);
1718+
}
1719+
1720+
buf_flush_list_mutex_exit(buf_pool);
1721+
}
1722+
/* end */
1723+
16191724
buf_pool->stat.LRU_bytes -= bpage->size.physical();
16201725

16211726
buf_unzip_LRU_remove_block_if_needed(bpage);

0 commit comments

Comments
 (0)