diff --git a/libCacheSim/cache/eviction/SLRU.c b/libCacheSim/cache/eviction/SLRU.c index 82c48111..8455aa60 100644 --- a/libCacheSim/cache/eviction/SLRU.c +++ b/libCacheSim/cache/eviction/SLRU.c @@ -313,9 +313,8 @@ static cache_obj_t *SLRU_insert(cache_t *cache, const request_t *req) { if (nth_seg == -1) { // No space for insertion - int64_t sz = req->obj_size + cache->obj_md_size; - while (params->lru_n_bytes[0] + sz > params->lru_max_n_bytes[0] || - cache->occupied_byte + sz > cache->cache_size) { + while (cache->occupied_byte + req->obj_size + cache->obj_md_size > + cache->cache_size) { cache->evict(cache, req); } nth_seg = 0; @@ -382,6 +381,9 @@ static void SLRU_evict(cache_t *cache, const request_t *req) { SLRU_params_t *params = (SLRU_params_t *)(cache->eviction_params); cache_obj_t *obj = SLRU_to_evict(cache, req); + if (obj == NULL) { + ERROR("SLRU: no object to evict\n"); + } params->lru_n_bytes[obj->SLRU.lru_id] -= obj->obj_size + cache->obj_md_size; params->lru_n_objs[obj->SLRU.lru_id]--; @@ -412,6 +414,8 @@ static bool SLRU_remove(cache_t *cache, obj_id_t obj_id) { return false; } + params->lru_n_bytes[obj->SLRU.lru_id] -= obj->obj_size + cache->obj_md_size; + params->lru_n_objs[obj->SLRU.lru_id]--; remove_obj_from_list(&(params->lru_heads[obj->SLRU.lru_id]), &(params->lru_tails[obj->SLRU.lru_id]), obj); cache_remove_obj_base(cache, obj, true); diff --git a/libCacheSim/cache/eviction/WTinyLFU.c b/libCacheSim/cache/eviction/WTinyLFU.c index e5e55a5a..4af74046 100644 --- a/libCacheSim/cache/eviction/WTinyLFU.c +++ b/libCacheSim/cache/eviction/WTinyLFU.c @@ -394,8 +394,14 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { * caller asking the composite what it reserves is not told less than it * really does; using it here would bill a FIFO or Clock main cache for * the window's 16 bytes and call it full early. */ - if (!params->main_full && - WTinyLFU_main_fits(main_cache, params->req_local)) { + if (params->req_local->obj_size + main_cache->obj_md_size > + main_cache->cache_size) { + // the hill climber can shrink the main cache below this object + window->evict(window, req); + evicted = true; + } else if ((!params->main_full || + main_cache->get_n_obj(main_cache) == 0) && + WTinyLFU_main_fits(main_cache, params->req_local)) { main_cache->insert(main_cache, params->req_local); #if defined(TRACK_DEMOTION) @@ -462,6 +468,7 @@ static bool WTinyLFU_remove(cache_t *cache, obj_id_t obj_id) { return true; } if (params->main_cache->remove(params->main_cache, obj_id)) { + params->main_full = false; return true; } return false; diff --git a/test/test_cli.sh b/test/test_cli.sh index 22f622e8..e92a67ff 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -341,6 +341,9 @@ expect_output "WTinyLFU reports hill-climb=1" "hill-climb=1" \ expect_clean_error "WTinyLFU hill-climb rejects a FIFO main cache" \ "${BIN_DIR}/cachesim" "${TRACE}" vscsi wtinyLFU 1mb \ --num-req=10 --hashpower=8 -e "main-cache=FIFO,hill-climb=1" +expect_ok "WTinyLFU hill-climb runs with a small LRU main cache" \ + "${BIN_DIR}/cachesim" "${TRACE}" vscsi wtinyLFU 256kb \ + --hashpower=8 -e "main-cache=LRU,hill-climb=1" echo "running admission and prefetch missing-value tests" diff --git a/test/test_evictionAlgo.c b/test/test_evictionAlgo.c index dbe3bc76..48d38506 100644 --- a/test/test_evictionAlgo.c +++ b/test/test_evictionAlgo.c @@ -202,9 +202,9 @@ static const cache_test_data_t test_data_truth[] = { .hashpower = 20, .req_cnt_true = 113872, .req_byte_true = 4368040448, - .miss_cnt_true = {89862, 86685, 83365, 80309, 75447, 66000, 59092, 56111}, - .miss_byte_true = {4125897728, 3909879808, 3697543168, 3489533952, - 3159642624, 2695841792, 2506203648, 2440419840}}, + .miss_cnt_true = {89624, 86725, 82781, 80203, 75388, 65645, 59035, 56063}, + .miss_byte_true = {4123085312, 3915534848, 3690704896, 3493027840, + 3174708736, 2661464064, 2507604992, 2439981056}}, {.cache_name = "SR_LRU", .hashpower = 20, .req_cnt_true = 113872,