diff --git a/CMakeLists.txt b/CMakeLists.txt index a2623b470..395a31d9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,16 +88,16 @@ endif() # Define shared compiler flags for all targets -set(LIBCACHESIM_C_FLAGS - -Wall -Wextra -Werror - -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable - -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings +set(LIBCACHESIM_C_FLAGS + -Wall -Wextra -Werror + -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable + -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs ) -set(LIBCACHESIM_CXX_FLAGS - -Wall -Wextra -Werror - -Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable +set(LIBCACHESIM_CXX_FLAGS + -Wall -Wextra -Werror + -Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs ) @@ -119,10 +119,18 @@ list(APPEND dependency_libs ${CMAKE_THREAD_LIBS_INIT}) # Link standard math and dl libraries universally list(APPEND dependency_libs m dl) -find_package(GLib REQUIRED) +# Find GLib using pkg-config +find_package(PkgConfig REQUIRED) + +# Find glib-2.0 using pkg-config +pkg_check_modules(GLib REQUIRED glib-2.0) + +# Add GLib library directories to the linker search path +link_directories(${GLib_LIBRARY_DIRS}) + # Don't add GLib includes globally - add them to specific targets # include_directories(${GLib_INCLUDE_DIRS}) -list(APPEND dependency_libs ${GLib_LIBRARY}) +list(APPEND dependency_libs ${GLib_LIBRARIES}) find_package(argp REQUIRED) # Don't add argp includes globally @@ -336,4 +344,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Find${PROJECT_NAME}.cmake install(EXPORT ${PROJECT_NAME}Targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) \ No newline at end of file +) diff --git a/libCacheSim/cache/eviction/QDLP.c b/libCacheSim/cache/eviction/QDLP.c index 5df9f373d..16db6cac9 100644 --- a/libCacheSim/cache/eviction/QDLP.c +++ b/libCacheSim/cache/eviction/QDLP.c @@ -20,20 +20,20 @@ extern "C" { #endif typedef struct { - cache_t *fifo; - cache_t *fifo_ghost; + cache_t *small_cache; + cache_t *ghost_cache; cache_t *main_cache; bool hit_on_ghost; - int64_t n_obj_admit_to_fifo; + int64_t n_obj_admit_to_small; int64_t n_obj_admit_to_main; int64_t n_obj_move_to_main; - int64_t n_byte_admit_to_fifo; + int64_t n_byte_admit_to_small; int64_t n_byte_admit_to_main; int64_t n_byte_move_to_main; int move_to_main_threshold; - double fifo_size_ratio; + double small_size_ratio; double ghost_size_ratio; char main_cache_type[32]; @@ -100,22 +100,22 @@ cache_t *QDLP_init(const common_cache_params_t ccache_params, } int64_t fifo_cache_size = - (int64_t)ccache_params.cache_size * params->fifo_size_ratio; + (int64_t)ccache_params.cache_size * params->small_size_ratio; int64_t main_cache_size = ccache_params.cache_size - fifo_cache_size; - int64_t fifo_ghost_cache_size = + int64_t ghost_cache_size = (int64_t)(ccache_params.cache_size * params->ghost_size_ratio); common_cache_params_t ccache_params_local = ccache_params; ccache_params_local.cache_size = fifo_cache_size; - params->fifo = FIFO_init(ccache_params_local, NULL); + params->small_cache = FIFO_init(ccache_params_local, NULL); - if (fifo_ghost_cache_size > 0) { - ccache_params_local.cache_size = fifo_ghost_cache_size; - params->fifo_ghost = FIFO_init(ccache_params_local, NULL); - snprintf(params->fifo_ghost->cache_name, CACHE_NAME_ARRAY_LEN, + if (ghost_cache_size > 0) { + ccache_params_local.cache_size = ghost_cache_size; + params->ghost_cache = FIFO_init(ccache_params_local, NULL); + snprintf(params->ghost_cache->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-ghost"); } else { - params->fifo_ghost = NULL; + params->ghost_cache = NULL; } ccache_params_local.cache_size = main_cache_size; @@ -152,15 +152,15 @@ cache_t *QDLP_init(const common_cache_params_t ccache_params, } #if defined(TRACK_EVICTION_V_AGE) - if (params->fifo_ghost != NULL) { - params->fifo_ghost->track_eviction_age = false; + if (params->ghost_cache != NULL) { + params->ghost->track_eviction_age = false; } - params->fifo->track_eviction_age = false; + params->small_cache->track_eviction_age = false; params->main_cache->track_eviction_age = false; #endif snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "QDLP-%.4lf-%.4lf-%s-%d", - params->fifo_size_ratio, params->ghost_size_ratio, + params->small_size_ratio, params->ghost_size_ratio, params->main_cache_type, params->move_to_main_threshold); return cache; @@ -174,9 +174,9 @@ cache_t *QDLP_init(const common_cache_params_t ccache_params, static void QDLP_free(cache_t *cache) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; free_request(params->req_local); - params->fifo->cache_free(params->fifo); - if (params->fifo_ghost != NULL) { - params->fifo_ghost->cache_free(params->fifo_ghost); + params->small_cache->cache_free(params->small_cache); + if (params->ghost_cache != NULL) { + params->ghost_cache->cache_free(params->ghost_cache); } params->main_cache->cache_free(params->main_cache); free(cache->eviction_params); @@ -204,7 +204,7 @@ static void QDLP_free(cache_t *cache) { */ static bool QDLP_get(cache_t *cache, const request_t *req) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; - DEBUG_ASSERT(params->fifo->get_occupied_byte(params->fifo) + + DEBUG_ASSERT(params->small_cache->get_occupied_byte(params->small_cache) + params->main_cache->get_occupied_byte(params->main_cache) <= cache->cache_size); @@ -234,7 +234,8 @@ static cache_obj_t *QDLP_find(cache_t *cache, const request_t *req, // if update cache is false, we only check the fifo and main caches if (!update_cache) { - cache_obj_t *obj = params->fifo->find(params->fifo, req, false); + cache_obj_t *obj = + params->small_cache->find(params->small_cache, req, false); if (obj != NULL) { return obj; } @@ -247,14 +248,14 @@ static cache_obj_t *QDLP_find(cache_t *cache, const request_t *req, /* update cache is true from now */ params->hit_on_ghost = false; - cache_obj_t *obj = params->fifo->find(params->fifo, req, true); + cache_obj_t *obj = params->small_cache->find(params->small_cache, req, true); if (obj != NULL) { return obj; } - if (params->fifo_ghost != NULL && - params->fifo_ghost->remove(params->fifo_ghost, req->obj_id)) { - // if object in fifo_ghost, remove will return true + if (params->ghost_cache != NULL && + params->ghost_cache->remove(params->ghost_cache, req->obj_id)) { + // if object in ghost, remove will return true params->hit_on_ghost = true; } @@ -287,12 +288,12 @@ static cache_obj_t *QDLP_insert(cache_t *cache, const request_t *req) { obj = params->main_cache->find(params->main_cache, req, false); } else { /* insert into the fifo */ - if (req->obj_size >= params->fifo->cache_size) { + if (req->obj_size >= params->small_cache->cache_size) { return NULL; } - params->n_obj_admit_to_fifo += 1; - params->n_byte_admit_to_fifo += req->obj_size; - obj = params->fifo->insert(params->fifo, req); + params->n_obj_admit_to_small += 1; + params->n_byte_admit_to_small += req->obj_size; + obj = params->small_cache->insert(params->small_cache, req); } #if defined(TRACK_EVICTION_V_AGE) @@ -331,25 +332,25 @@ static cache_obj_t *QDLP_to_evict(cache_t *cache, const request_t *req) { static void QDLP_evict(cache_t *cache, const request_t *req) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; - cache_t *fifo = params->fifo; - cache_t *ghost = params->fifo_ghost; - cache_t *main = params->main_cache; + cache_t *small_cache = params->small_cache; + cache_t *ghost_cache = params->ghost_cache; + cache_t *main_cache = params->main_cache; - if (fifo->get_occupied_byte(fifo) == 0) { + if (small_cache->get_occupied_byte(small_cache) == 0) { #if defined(TRACK_EVICTION_V_AGE) - cache_obj_t *obj = main->to_evict(main, req); + cache_obj_t *obj = main_cache->to_evict(main_cache, req); record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time); #endif - assert(main->get_occupied_byte(main) <= cache->cache_size); + assert(main_cache->get_occupied_byte(main_cache) <= cache->cache_size); // evict from main cache - main->evict(main, req); + main_cache->evict(main_cache, req); return; } // evict from FIFO - cache_obj_t *obj = fifo->to_evict(fifo, req); + cache_obj_t *obj = small_cache->to_evict(small_cache, req); assert(obj != NULL); // need to copy the object before it is evicted copy_cache_obj_to_request(params->req_local, obj); @@ -361,21 +362,22 @@ static void QDLP_evict(cache_t *cache, const request_t *req) { params->main_cache->get(params->main_cache, params->req_local); #if defined(TRACK_EVICTION_V_AGE) - main->find(main, params->req_local, false)->create_time = obj->create_time; + main_cache->find(main_cache, params->req_local, false)->create_time = + obj->create_time; } else { record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time); #else } else { #endif // insert to ghost - if (ghost != NULL) { - ghost->get(ghost, params->req_local); + if (ghost_cache != NULL) { + ghost_cache->get(ghost_cache, params->req_local); } } // remove from fifo, but do not update stat // bool removed = fifo->remove(fifo, params->req_local->obj_id); - fifo->evict(fifo, req); + small_cache->evict(small_cache, req); } /** @@ -394,9 +396,10 @@ static void QDLP_evict(cache_t *cache, const request_t *req) { static bool QDLP_remove(cache_t *cache, const obj_id_t obj_id) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; bool removed = false; - removed = removed || params->fifo->remove(params->fifo, obj_id); - removed = removed || (params->fifo_ghost && - params->fifo_ghost->remove(params->fifo_ghost, obj_id)); + removed = removed || params->small_cache->remove(params->small_cache, obj_id); + removed = + removed || (params->ghost_cache && + params->ghost_cache->remove(params->ghost_cache, obj_id)); removed = removed || params->main_cache->remove(params->main_cache, obj_id); return removed; @@ -404,20 +407,20 @@ static bool QDLP_remove(cache_t *cache, const obj_id_t obj_id) { static inline int64_t QDLP_get_occupied_byte(const cache_t *cache) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; - return params->fifo->get_occupied_byte(params->fifo) + + return params->small_cache->get_occupied_byte(params->small_cache) + params->main_cache->get_occupied_byte(params->main_cache); } static inline int64_t QDLP_get_n_obj(const cache_t *cache) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; - return params->fifo->get_n_obj(params->fifo) + + return params->small_cache->get_n_obj(params->small_cache) + params->main_cache->get_n_obj(params->main_cache); } static inline bool QDLP_can_insert(cache_t *cache, const request_t *req) { QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params; - return req->obj_size <= params->fifo->cache_size && + return req->obj_size <= params->small_cache->cache_size && cache_can_insert_default(cache, req); } @@ -429,7 +432,7 @@ static inline bool QDLP_can_insert(cache_t *cache, const request_t *req) { static const char *QDLP_current_params(QDLP_params_t *params) { static __thread char params_str[128]; snprintf(params_str, 128, "fifo-size-ratio=%.4lf,main-cache=%s\n", - params->fifo_size_ratio, params->main_cache->cache_name); + params->small_size_ratio, params->main_cache->cache_name); return params_str; } @@ -452,7 +455,7 @@ static void QDLP_parse_params(cache_t *cache, } if (strcasecmp(key, "fifo-size-ratio") == 0) { - params->fifo_size_ratio = strtod(value, NULL); + params->small_size_ratio = strtod(value, NULL); } else if (strcasecmp(key, "ghost-size-ratio") == 0) { params->ghost_size_ratio = strtod(value, NULL); } else if (strcasecmp(key, "move-to-main-threshold") == 0) { diff --git a/libCacheSim/cache/eviction/S3FIFO.c b/libCacheSim/cache/eviction/S3FIFO.c index adc039ea1..cb5658311 100644 --- a/libCacheSim/cache/eviction/S3FIFO.c +++ b/libCacheSim/cache/eviction/S3FIFO.c @@ -256,24 +256,24 @@ static cache_obj_t *S3FIFO_insert(cache_t *cache, const request_t *req) { S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; cache_obj_t *obj = NULL; - cache_t *small = params->small_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *main_fifo = params->main_fifo; if (params->hit_on_ghost) { /* insert into main FIFO */ params->hit_on_ghost = false; - obj = main->insert(main, req); + obj = main_fifo->insert(main_fifo, req); } else { /* insert into small fifo */ - if (req->obj_size >= small->cache_size) { + if (req->obj_size >= small_fifo->cache_size) { return NULL; } if (!params->has_evicted && - small->get_occupied_byte(small) >= small->cache_size) { - obj = main->insert(main, req); + small_fifo->get_occupied_byte(small_fifo) >= small_fifo->cache_size) { + obj = main_fifo->insert(main_fifo, req); } else { - obj = small->insert(small, req); + obj = small_fifo->insert(small_fifo, req); } } @@ -299,54 +299,54 @@ static cache_obj_t *S3FIFO_to_evict(cache_t *cache, const request_t *req) { static void S3FIFO_evict_small(cache_t *cache, const request_t *req) { S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; - cache_t *small = params->small_fifo; - cache_t *ghost = params->ghost_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *ghost_fifo = params->ghost_fifo; + cache_t *main_fifo = params->main_fifo; bool has_evicted = false; - while (!has_evicted && small->get_occupied_byte(small) > 0) { - cache_obj_t *obj_to_evict = small->to_evict(small, req); + while (!has_evicted && small_fifo->get_occupied_byte(small_fifo) > 0) { + cache_obj_t *obj_to_evict = small_fifo->to_evict(small_fifo, req); DEBUG_ASSERT(obj_to_evict != NULL); // need to copy the object before it is evicted copy_cache_obj_to_request(params->req_local, obj_to_evict); if (obj_to_evict->S3FIFO.freq >= params->move_to_main_threshold) { - main->insert(main, params->req_local); + main_fifo->insert(main_fifo, params->req_local); } else { // insert to ghost - if (ghost != NULL) { - ghost->get(ghost, params->req_local); + if (ghost_fifo != NULL) { + ghost_fifo->get(ghost_fifo, params->req_local); } has_evicted = true; } // remove from small fifo, but do not update stat - bool removed = small->remove(small, params->req_local->obj_id); + bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id); DEBUG_ASSERT(removed); } } static void S3FIFO_evict_main(cache_t *cache, const request_t *req) { S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; - cache_t *main = params->main_fifo; + cache_t *main_fifo = params->main_fifo; bool has_evicted = false; - while (!has_evicted && main->get_occupied_byte(main) > 0) { - cache_obj_t *obj_to_evict = main->to_evict(main, req); + while (!has_evicted && main_fifo->get_occupied_byte(main_fifo) > 0) { + cache_obj_t *obj_to_evict = main_fifo->to_evict(main_fifo, req); DEBUG_ASSERT(obj_to_evict != NULL); int freq = obj_to_evict->S3FIFO.freq; copy_cache_obj_to_request(params->req_local, obj_to_evict); if (freq >= 1) { // we need to evict first because the object to insert has the same obj_id - main->remove(main, obj_to_evict->obj_id); + main_fifo->remove(main_fifo, obj_to_evict->obj_id); obj_to_evict = NULL; - cache_obj_t *new_obj = main->insert(main, params->req_local); + cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local); // clock with 2-bit counter new_obj->S3FIFO.freq = MIN(freq, 3) - 1; } else { - bool removed = main->remove(main, obj_to_evict->obj_id); + bool removed = main_fifo->remove(main_fifo, obj_to_evict->obj_id); DEBUG_ASSERT(removed); has_evicted = true; @@ -367,11 +367,11 @@ static void S3FIFO_evict(cache_t *cache, const request_t *req) { S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; params->has_evicted = true; - cache_t *small = params->small_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *main_fifo = params->main_fifo; - if (main->get_occupied_byte(main) > main->cache_size || - small->get_occupied_byte(small) == 0) { + if (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size || + small_fifo->get_occupied_byte(small_fifo) == 0) { S3FIFO_evict_main(cache, req); } else { S3FIFO_evict_small(cache, req); diff --git a/libCacheSim/cache/eviction/S3FIFOd.c b/libCacheSim/cache/eviction/S3FIFOd.c index a8fc27b92..5c7596b48 100644 --- a/libCacheSim/cache/eviction/S3FIFOd.c +++ b/libCacheSim/cache/eviction/S3FIFOd.c @@ -25,18 +25,18 @@ extern "C" { #endif typedef struct { - cache_t *fifo; - cache_t *fifo_ghost; - cache_t *main_cache; + cache_t *small_fifo; + cache_t *ghost_fifo; + cache_t *main_fifo; bool hit_on_ghost; int move_to_main_threshold; - double fifo_size_ratio; - char main_cache_type[32]; + double small_fifo_size_ratio; + char main_fifo_type[32]; - cache_t *fifo_eviction; - cache_t *main_cache_eviction; - int32_t fifo_eviction_hit; + cache_t *small_eviction; + cache_t *main_eviction; + int32_t small_eviction_hit; int32_t main_eviction_hit; request_t *req_local; @@ -101,68 +101,68 @@ cache_t *S3FIFOd_init(const common_cache_params_t ccache_params, } int64_t fifo_cache_size = - (int64_t)ccache_params.cache_size * params->fifo_size_ratio; - int64_t main_cache_size = ccache_params.cache_size - fifo_cache_size; - int64_t fifo_ghost_cache_size = main_cache_size; + (int64_t)ccache_params.cache_size * params->small_fifo_size_ratio; + int64_t main_fifo_size = ccache_params.cache_size - fifo_cache_size; + int64_t ghost_fifo = main_fifo_size; common_cache_params_t ccache_params_local = ccache_params; ccache_params_local.cache_size = fifo_cache_size; - params->fifo = FIFO_init(ccache_params_local, NULL); - - ccache_params_local.cache_size = fifo_ghost_cache_size; - params->fifo_ghost = FIFO_init(ccache_params_local, NULL); - snprintf(params->fifo_ghost->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-ghost"); - - ccache_params_local.cache_size = main_cache_size; - if (strcasecmp(params->main_cache_type, "FIFO") == 0) { - params->main_cache = FIFO_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "clock") == 0) { - params->main_cache = Clock_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "clock2") == 0) { - params->main_cache = Clock_init(ccache_params_local, "n-bit-counter=2"); - } else if (strcasecmp(params->main_cache_type, "clock3") == 0) { - params->main_cache = Clock_init(ccache_params_local, "n-bit-counter=3"); - } else if (strcasecmp(params->main_cache_type, "sieve") == 0) { - params->main_cache = Sieve_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "LRU") == 0) { - params->main_cache = LRU_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "ARC") == 0) { - params->main_cache = ARC_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "LHD") == 0) { - params->main_cache = LHD_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "LeCaR") == 0) { - params->main_cache = LeCaR_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "Cacheus") == 0) { - params->main_cache = Cacheus_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "twoQ") == 0) { - params->main_cache = TwoQ_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "LIRS") == 0) { - params->main_cache = LIRS_init(ccache_params_local, NULL); - } else if (strcasecmp(params->main_cache_type, "Hyperbolic") == 0) { - params->main_cache = Hyperbolic_init(ccache_params_local, NULL); + params->small_fifo = FIFO_init(ccache_params_local, NULL); + + ccache_params_local.cache_size = ghost_fifo; + params->ghost_fifo = FIFO_init(ccache_params_local, NULL); + snprintf(params->ghost_fifo->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-ghost"); + + ccache_params_local.cache_size = main_fifo_size; + if (strcasecmp(params->main_fifo_type, "FIFO") == 0) { + params->main_fifo = FIFO_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "clock") == 0) { + params->main_fifo = Clock_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "clock2") == 0) { + params->main_fifo = Clock_init(ccache_params_local, "n-bit-counter=2"); + } else if (strcasecmp(params->main_fifo_type, "clock3") == 0) { + params->main_fifo = Clock_init(ccache_params_local, "n-bit-counter=3"); + } else if (strcasecmp(params->main_fifo_type, "sieve") == 0) { + params->main_fifo = Sieve_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "LRU") == 0) { + params->main_fifo = LRU_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "ARC") == 0) { + params->main_fifo = ARC_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "LHD") == 0) { + params->main_fifo = LHD_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "LeCaR") == 0) { + params->main_fifo = LeCaR_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "Cacheus") == 0) { + params->main_fifo = Cacheus_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "twoQ") == 0) { + params->main_fifo = TwoQ_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "LIRS") == 0) { + params->main_fifo = LIRS_init(ccache_params_local, NULL); + } else if (strcasecmp(params->main_fifo_type, "Hyperbolic") == 0) { + params->main_fifo = Hyperbolic_init(ccache_params_local, NULL); } else { - ERROR("S3FIFOd does not support %s \n", params->main_cache_type); + ERROR("S3FIFOd does not support %s \n", params->main_fifo_type); } ccache_params_local.cache_size = ccache_params.cache_size / 10; ccache_params_local.hashpower -= 4; - params->fifo_eviction = FIFO_init(ccache_params_local, NULL); - params->main_cache_eviction = FIFO_init(ccache_params_local, NULL); - snprintf(params->fifo_eviction->cache_name, CACHE_NAME_ARRAY_LEN, + params->small_eviction = FIFO_init(ccache_params_local, NULL); + params->main_eviction = FIFO_init(ccache_params_local, NULL); + snprintf(params->small_eviction->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-evicted"); - snprintf(params->main_cache_eviction->cache_name, CACHE_NAME_ARRAY_LEN, "%s", + snprintf(params->main_eviction->cache_name, CACHE_NAME_ARRAY_LEN, "%s", "main-evicted"); #if defined(TRACK_EVICTION_V_AGE) - params->fifo->track_eviction_age = false; - params->main_cache->track_eviction_age = false; - params->fifo_ghost->track_eviction_age = false; - params->fifo_eviction->track_eviction_age = false; - params->main_cache_eviction->track_eviction_age = false; + params->small_fifo->track_eviction_age = false; + params->main_fifo->track_eviction_age = false; + params->ghost_fifo->track_eviction_age = false; + params->small_eviction->track_eviction_age = false; + params->main_eviction->track_eviction_age = false; #endif snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "S3FIFOd-%s-%d", - params->main_cache_type, params->move_to_main_threshold); + params->main_fifo_type, params->move_to_main_threshold); return cache; } @@ -175,9 +175,9 @@ cache_t *S3FIFOd_init(const common_cache_params_t ccache_params, static void S3FIFOd_free(cache_t *cache) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; free_request(params->req_local); - params->fifo->cache_free(params->fifo); - params->fifo_ghost->cache_free(params->fifo_ghost); - params->main_cache->cache_free(params->main_cache); + params->small_fifo->cache_free(params->small_fifo); + params->ghost_fifo->cache_free(params->ghost_fifo); + params->main_fifo->cache_free(params->main_fifo); free(cache->eviction_params); cache_struct_free(cache); } @@ -187,32 +187,33 @@ static void S3FIFOd_update_fifo_size(cache_t *cache, const request_t *req) { int step = 20; step = MAX( - 1, MIN(params->fifo->cache_size, params->main_cache->cache_size) / 1000); - bool cond1 = params->fifo_eviction_hit + params->main_eviction_hit > 100; - bool cond2 = params->main_cache_eviction->get_occupied_byte( - params->main_cache_eviction) > 0; + 1, MIN(params->small_fifo->cache_size, params->main_fifo->cache_size) / + 1000); + bool cond1 = params->small_eviction_hit + params->main_eviction_hit > 100; + bool cond2 = + params->main_eviction->get_occupied_byte(params->main_eviction) > 0; if (!cond2) { - params->fifo_eviction_hit = 0; + params->small_eviction_hit = 0; params->main_eviction_hit = 0; } if (cond1 && cond2) { - if (params->fifo_eviction_hit > params->main_eviction_hit * 2) { - // if (params->main_cache->cache_size > step) { - if (params->main_cache->cache_size > cache->cache_size / 100) { - params->fifo->cache_size += step; - params->fifo_ghost->cache_size += step; - params->main_cache->cache_size -= step; + if (params->small_eviction_hit > params->main_eviction_hit * 2) { + // if (params->main_fifo->cache_size > step) { + if (params->main_fifo->cache_size > cache->cache_size / 100) { + params->small_fifo->cache_size += step; + params->ghost_fifo->cache_size += step; + params->main_fifo->cache_size -= step; } - } else if (params->main_eviction_hit > params->fifo_eviction_hit * 2) { - // if (params->fifo->cache_size > step) { - if (params->fifo->cache_size > cache->cache_size / 100) { - params->fifo->cache_size -= step; - params->fifo_ghost->cache_size -= step; - params->main_cache->cache_size += step; + } else if (params->main_eviction_hit > params->small_eviction_hit * 2) { + // if (params->small_fifo->cache_size > step) { + if (params->small_fifo->cache_size > cache->cache_size / 100) { + params->small_fifo->cache_size -= step; + params->ghost_fifo->cache_size -= step; + params->main_fifo->cache_size += step; } } - params->fifo_eviction_hit = params->fifo_eviction_hit * 0.8; + params->small_eviction_hit = params->small_eviction_hit * 0.8; params->main_eviction_hit = params->main_eviction_hit * 0.8; } } @@ -220,15 +221,16 @@ static void S3FIFOd_update_fifo_size(cache_t *cache, const request_t *req) { static void S3FIFOd_update_fifo_size2(cache_t *cache, const request_t *req) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - assert(params->fifo_eviction_hit + params->main_eviction_hit <= 1); - if (params->fifo_eviction_hit == 1 && params->main_cache->cache_size > 1) { - params->fifo->cache_size += 1; - params->main_cache->cache_size -= 1; - } else if (params->main_eviction_hit == 1 && params->fifo->cache_size > 1) { - params->main_cache->cache_size += 1; - params->fifo->cache_size -= 1; + assert(params->small_eviction_hit + params->main_eviction_hit <= 1); + if (params->small_eviction_hit == 1 && params->main_fifo->cache_size > 1) { + params->small_fifo->cache_size += 1; + params->main_fifo->cache_size -= 1; + } else if (params->main_eviction_hit == 1 && + params->small_fifo->cache_size > 1) { + params->main_fifo->cache_size += 1; + params->small_fifo->cache_size -= 1; } - params->fifo_eviction_hit = 0; + params->small_eviction_hit = 0; params->main_eviction_hit = 0; } @@ -253,8 +255,8 @@ static void S3FIFOd_update_fifo_size2(cache_t *cache, const request_t *req) { */ static bool S3FIFOd_get(cache_t *cache, const request_t *req) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - DEBUG_ASSERT(params->fifo->get_occupied_byte(params->fifo) + - params->main_cache->get_occupied_byte(params->main_cache) <= + DEBUG_ASSERT(params->small_fifo->get_occupied_byte(params->small_fifo) + + params->main_fifo->get_occupied_byte(params->main_fifo) <= cache->cache_size); // static __thread int64_t last_print_rtime = 0; @@ -262,13 +264,13 @@ static bool S3FIFOd_get(cache_t *cache, const request_t *req) { // printf( // "%ld %ld day: evictHit %d %d, fifo size %ld/%ld main size %ld/%ld, // ghost " "size %ld/%ld\n", cache->n_req, req->clock_time / 86400, - // params->fifo_eviction_hit, params->main_eviction_hit, - // params->fifo->get_occupied_byte(params->fifo), - // params->fifo->cache_size, - // params->main_cache->get_occupied_byte(params->main_cache), - // params->main_cache->cache_size, - // params->fifo_ghost->get_occupied_byte(params->fifo_ghost), - // params->fifo_ghost->cache_size); + // params->small_eviction_hit, params->main_eviction_hit, + // params->small_fifo->get_occupied_byte(params->small_fifo), + // params->small_fifo->cache_size, + // params->main_fifo->get_occupied_byte(params->main_fifo), + // params->main_fifo->cache_size, + // params->ghost_fifo->get_occupied_byte(params->ghost_fifo), + // params->ghost_fifo->cache_size); // last_print_rtime = req->clock_time; // } @@ -299,11 +301,11 @@ static cache_obj_t *S3FIFOd_find(cache_t *cache, const request_t *req, // if update cache is false, we only check the fifo and main caches if (!update_cache) { - cache_obj_t *obj = params->fifo->find(params->fifo, req, false); + cache_obj_t *obj = params->small_fifo->find(params->small_fifo, req, false); if (obj != NULL) { return obj; } - obj = params->main_cache->find(params->main_cache, req, false); + obj = params->main_fifo->find(params->main_fifo, req, false); if (obj != NULL) { return obj; } @@ -312,26 +314,25 @@ static cache_obj_t *S3FIFOd_find(cache_t *cache, const request_t *req, /* update cache is true from now */ params->hit_on_ghost = false; - cache_obj_t *obj = params->fifo->find(params->fifo, req, true); + cache_obj_t *obj = params->small_fifo->find(params->small_fifo, req, true); if (obj != NULL) { return obj; } - if (params->fifo_ghost->remove(params->fifo_ghost, req->obj_id)) { + if (params->ghost_fifo->remove(params->ghost_fifo, req->obj_id)) { params->hit_on_ghost = true; } - obj = params->main_cache->find(params->main_cache, req, update_cache); + obj = params->main_fifo->find(params->main_fifo, req, update_cache); - if (params->fifo_eviction->find(params->fifo_eviction, req, false) != NULL) { - params->fifo_eviction->remove(params->fifo_eviction, req->obj_id); - params->fifo_eviction_hit++; + if (params->small_eviction->find(params->small_eviction, req, false) != + NULL) { + params->small_eviction->remove(params->small_eviction, req->obj_id); + params->small_eviction_hit++; } - if (params->main_cache_eviction->find(params->main_cache_eviction, req, - true) != NULL) { - params->main_cache_eviction->remove(params->main_cache_eviction, - req->obj_id); + if (params->main_eviction->find(params->main_eviction, req, true) != NULL) { + params->main_eviction->remove(params->main_eviction, req->obj_id); params->main_eviction_hit++; } @@ -356,11 +357,11 @@ static cache_obj_t *S3FIFOd_insert(cache_t *cache, const request_t *req) { if (params->hit_on_ghost) { /* insert into the ARC */ params->hit_on_ghost = false; - params->main_cache->get(params->main_cache, req); - obj = params->main_cache->find(params->main_cache, req, false); + params->main_fifo->get(params->main_fifo, req); + obj = params->main_fifo->find(params->main_fifo, req, false); } else { /* insert into the fifo */ - obj = params->fifo->insert(params->fifo, req); + obj = params->small_fifo->insert(params->small_fifo, req); } assert(obj->misc.freq == 0); @@ -399,26 +400,25 @@ static cache_obj_t *S3FIFOd_to_evict(cache_t *cache, const request_t *req) { static void S3FIFOd_evict(cache_t *cache, const request_t *req) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - cache_t *fifo = params->fifo; - cache_t *ghost = params->fifo_ghost; - cache_t *main = params->main_cache; + cache_t *small_fifo = params->small_fifo; + cache_t *ghost = params->ghost_fifo; + cache_t *main_fifo = params->main_fifo; - if (fifo->get_occupied_byte(fifo) == 0) { - assert(main->get_occupied_byte(main) <= cache->cache_size); + if (small_fifo->get_occupied_byte(small_fifo) == 0) { + assert(main_fifo->get_occupied_byte(main_fifo) <= cache->cache_size); // evict from main cache - cache_obj_t *obj = main->to_evict(main, req); + cache_obj_t *obj = main_fifo->to_evict(main_fifo, req); #if defined(TRACK_EVICTION_V_AGE) record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time); #endif copy_cache_obj_to_request(params->req_local, obj); - params->main_cache_eviction->get(params->main_cache_eviction, - params->req_local); - main->evict(main, req); + params->main_eviction->get(params->main_eviction, params->req_local); + main_fifo->evict(main_fifo, req); return; } // evict from FIFO - cache_obj_t *obj = fifo->to_evict(fifo, req); + cache_obj_t *obj = small_fifo->to_evict(small_fifo, req); assert(obj != NULL); // need to copy the object before it is evicted copy_cache_obj_to_request(params->req_local, obj); @@ -426,52 +426,50 @@ static void S3FIFOd_evict(cache_t *cache, const request_t *req) { #if defined(TRACK_EVICTION_V_AGE) if (obj->misc.freq >= params->move_to_main_threshold) { // promote to main cache - cache_obj_t *new_obj = main->insert(main, params->req_local); + cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local); new_obj->create_time = obj->create_time; // evict from fifo, must be after copy eviction age - bool removed = fifo->remove(fifo, params->req_local->obj_id); + bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id); assert(removed); - while (main->get_occupied_byte(main) > main->cache_size) { + while (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size) { // evict from main cache - obj = main->to_evict(main, req); + obj = main_fifo->to_evict(main_fifo, req); copy_cache_obj_to_request(params->req_local, obj); - params->main_cache_eviction->get(params->main_cache_eviction, - params->req_local); - main->evict(main, req); + params->main_eviction->get(params->main_eviction, params->req_local); + main_fifo->evict(main_fifo, req); } } else { // evict from fifo, must be after copy eviction age - bool removed = fifo->remove(fifo, params->req_local->obj_id); + bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id); assert(removed); record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time); // insert to ghost ghost->get(ghost, params->req_local); - params->fifo_eviction->get(params->fifo_eviction, params->req_local); + params->small_eviction->get(params->small_eviction, params->req_local); } #else // evict from fifo - bool removed = fifo->remove(fifo, params->req_local->obj_id); + bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id); assert(removed); if (obj->misc.freq >= params->move_to_main_threshold) { // promote to main cache - main->insert(main, params->req_local); + main_fifo->insert(main_fifo, params->req_local); - while (main->get_occupied_byte(main) > main->cache_size) { + while (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size) { // evict from main cache - obj = main->to_evict(main, req); + obj = main_fifo->to_evict(main_fifo, req); copy_cache_obj_to_request(params->req_local, obj); - params->main_cache_eviction->get(params->main_cache_eviction, - params->req_local); - main->evict(main, req); + params->main_eviction->get(params->main_eviction, params->req_local); + main_fifo->evict(main_fifo, req); } } else { // insert to ghost ghost->get(ghost, params->req_local); - params->fifo_eviction->get(params->fifo_eviction, params->req_local); + params->small_eviction->get(params->small_eviction, params->req_local); } #endif } @@ -492,29 +490,29 @@ static void S3FIFOd_evict(cache_t *cache, const request_t *req) { static bool S3FIFOd_remove(cache_t *cache, const obj_id_t obj_id) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; bool removed = false; - removed = removed || params->fifo->remove(params->fifo, obj_id); - removed = removed || params->fifo_ghost->remove(params->fifo_ghost, obj_id); - removed = removed || params->main_cache->remove(params->main_cache, obj_id); + removed = removed || params->small_fifo->remove(params->small_fifo, obj_id); + removed = removed || params->ghost_fifo->remove(params->ghost_fifo, obj_id); + removed = removed || params->main_fifo->remove(params->main_fifo, obj_id); return removed; } static inline int64_t S3FIFOd_get_occupied_byte(const cache_t *cache) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - return params->fifo->get_occupied_byte(params->fifo) + - params->main_cache->get_occupied_byte(params->main_cache); + return params->small_fifo->get_occupied_byte(params->small_fifo) + + params->main_fifo->get_occupied_byte(params->main_fifo); } static inline int64_t S3FIFOd_get_n_obj(const cache_t *cache) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - return params->fifo->get_n_obj(params->fifo) + - params->main_cache->get_n_obj(params->main_cache); + return params->small_fifo->get_n_obj(params->small_fifo) + + params->main_fifo->get_n_obj(params->main_fifo); } static inline bool S3FIFOd_can_insert(cache_t *cache, const request_t *req) { S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; - return req->obj_size <= params->fifo->cache_size && + return req->obj_size <= params->small_fifo->cache_size && cache_can_insert_default(cache, req); } @@ -526,7 +524,7 @@ static inline bool S3FIFOd_can_insert(cache_t *cache, const request_t *req) { static const char *S3FIFOd_current_params(S3FIFOd_params_t *params) { static __thread char params_str[128]; snprintf(params_str, 128, "fifo-size-ratio=%.4lf,main-cache=%s\n", - params->fifo_size_ratio, params->main_cache->cache_name); + params->small_fifo_size_ratio, params->main_fifo->cache_name); return params_str; } @@ -549,10 +547,11 @@ static void S3FIFOd_parse_params(cache_t *cache, params_str++; } - if (strcasecmp(key, "fifo-size-ratio") == 0) { - params->fifo_size_ratio = strtod(value, NULL); + if (strcasecmp(key, "fifo-size-ratio") == 0 || + strcasecmp(key, "small-size-ratio") == 0) { + params->small_fifo_size_ratio = strtod(value, NULL); } else if (strcasecmp(key, "main-cache") == 0) { - strncpy(params->main_cache_type, value, 30); + strncpy(params->main_fifo_type, value, 30); } else if (strcasecmp(key, "move-to-main-threshold") == 0) { params->move_to_main_threshold = atoi(value); } else if (strcasecmp(key, "print") == 0) { diff --git a/libCacheSim/cache/eviction/S3FIFOv0.c b/libCacheSim/cache/eviction/S3FIFOv0.c index a1a3d0556..0797f3016 100644 --- a/libCacheSim/cache/eviction/S3FIFOv0.c +++ b/libCacheSim/cache/eviction/S3FIFOv0.c @@ -211,16 +211,16 @@ static cache_obj_t *S3FIFOv0_find(cache_t *cache, const request_t *req, const bool update_cache) { S3FIFOv0_params_t *params = (S3FIFOv0_params_t *)cache->eviction_params; - cache_t *small = params->small_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *main_fifo = params->main_fifo; // if update cache is false, we only check the fifo and main caches if (!update_cache) { - cache_obj_t *obj = small->find(small, req, false); + cache_obj_t *obj = small_fifo->find(small_fifo, req, false); if (obj != NULL) { return obj; } - obj = main->find(main, req, false); + obj = main_fifo->find(main_fifo, req, false); if (obj != NULL) { return obj; } @@ -229,7 +229,7 @@ static cache_obj_t *S3FIFOv0_find(cache_t *cache, const request_t *req, /* update cache is true from now */ params->hit_on_ghost = false; - cache_obj_t *obj = small->find(small, req, true); + cache_obj_t *obj = small_fifo->find(small_fifo, req, true); if (obj != NULL) { obj->S3FIFO.freq += 1; return obj; @@ -241,7 +241,7 @@ static cache_obj_t *S3FIFOv0_find(cache_t *cache, const request_t *req, params->hit_on_ghost = true; } - obj = main->find(main, req, true); + obj = main_fifo->find(main_fifo, req, true); if (obj != NULL) { obj->S3FIFO.freq += 1; } @@ -310,14 +310,14 @@ static cache_obj_t *S3FIFOv0_to_evict(cache_t *cache, const request_t *req) { static void S3FIFOv0_evict_small(cache_t *cache, const request_t *req) { S3FIFOv0_params_t *params = (S3FIFOv0_params_t *)cache->eviction_params; - cache_t *small = params->small_fifo; - cache_t *ghost = params->ghost_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *ghost_fifo = params->ghost_fifo; + cache_t *main_fifo = params->main_fifo; bool has_evicted = false; - while (!has_evicted && small->get_occupied_byte(small) > 0) { + while (!has_evicted && small_fifo->get_occupied_byte(small_fifo) > 0) { // evict from small fifo - cache_obj_t *obj_to_evict = small->to_evict(small, req); + cache_obj_t *obj_to_evict = small_fifo->to_evict(small_fifo, req); DEBUG_ASSERT(obj_to_evict != NULL); // need to copy the object before it is evicted copy_cache_obj_to_request(params->req_local, obj_to_evict); @@ -330,7 +330,7 @@ static void S3FIFOv0_evict_small(cache_t *cache, const request_t *req) { params->n_obj_move_to_main += 1; params->n_byte_move_to_main += obj_to_evict->obj_size; - cache_obj_t *new_obj = main->insert(main, params->req_local); + cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local); #if defined(TRACK_EVICTION_V_AGE) new_obj->create_time = obj_to_evict->create_time; } else { @@ -346,26 +346,26 @@ static void S3FIFOv0_evict_small(cache_t *cache, const request_t *req) { #endif // insert to ghost - if (ghost != NULL) { - ghost->get(ghost, params->req_local); + if (ghost_fifo != NULL) { + ghost_fifo->get(ghost_fifo, params->req_local); } has_evicted = true; } // remove from fifo, but do not update stat - bool removed = small->remove(small, params->req_local->obj_id); + bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id); DEBUG_ASSERT(removed); } } static void S3FIFOv0_evict_main(cache_t *cache, const request_t *req) { S3FIFOv0_params_t *params = (S3FIFOv0_params_t *)cache->eviction_params; - cache_t *main = params->main_fifo; + cache_t *main_fifo = params->main_fifo; // evict from main cache bool has_evicted = false; - while (!has_evicted && main->get_occupied_byte(main) > 0) { - cache_obj_t *obj_to_evict = main->to_evict(main, req); + while (!has_evicted && main_fifo->get_occupied_byte(main_fifo) > 0) { + cache_obj_t *obj_to_evict = main_fifo->to_evict(main_fifo, req); DEBUG_ASSERT(obj_to_evict != NULL); int freq = obj_to_evict->S3FIFO.freq; #if defined(TRACK_EVICTION_V_AGE) @@ -374,10 +374,10 @@ static void S3FIFOv0_evict_main(cache_t *cache, const request_t *req) { copy_cache_obj_to_request(params->req_local, obj_to_evict); if (freq >= 1) { // we need to evict first because the object to insert has the same obj_id - main->remove(main, obj_to_evict->obj_id); + main_fifo->remove(main_fifo, obj_to_evict->obj_id); obj_to_evict = NULL; - cache_obj_t *new_obj = main->insert(main, params->req_local); + cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local); // clock with 2-bit counter new_obj->S3FIFO.freq = MIN(freq, 3) - 1; @@ -390,7 +390,7 @@ static void S3FIFOv0_evict_main(cache_t *cache, const request_t *req) { CURR_TIME(cache, req) - obj_to_evict->create_time); #endif - bool removed = main->remove(main, obj_to_evict->obj_id); + bool removed = main_fifo->remove(main_fifo, obj_to_evict->obj_id); DEBUG_ASSERT(removed); has_evicted = true; @@ -410,11 +410,11 @@ static void S3FIFOv0_evict_main(cache_t *cache, const request_t *req) { static void S3FIFOv0_evict(cache_t *cache, const request_t *req) { S3FIFOv0_params_t *params = (S3FIFOv0_params_t *)cache->eviction_params; - cache_t *fifo = params->small_fifo; - cache_t *main = params->main_fifo; + cache_t *small_fifo = params->small_fifo; + cache_t *main_fifo = params->main_fifo; - if (main->get_occupied_byte(main) > main->cache_size || - fifo->get_occupied_byte(fifo) == 0) { + if (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size || + small_fifo->get_occupied_byte(small_fifo) == 0) { S3FIFOv0_evict_main(cache, req); } else { S3FIFOv0_evict_small(cache, req); diff --git a/libCacheSim/cache/eviction/WTinyLFU.c b/libCacheSim/cache/eviction/WTinyLFU.c index 4293b2c75..485a5799c 100644 --- a/libCacheSim/cache/eviction/WTinyLFU.c +++ b/libCacheSim/cache/eviction/WTinyLFU.c @@ -261,7 +261,7 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { WTinyLFU_params_t *params = (WTinyLFU_params_t *)(cache->eviction_params); cache_t *window = params->LRU; - cache_t *main = params->main_cache; + cache_t *main_cache = params->main_cache; bool evicted = false; while (!evicted) { @@ -275,10 +275,10 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { /** only when main_cache is full, evict an obj from the main_cache **/ // if main_cache has enough space, insert the obj into main_cache - if (main->get_occupied_byte(main) + params->req_local->obj_size + - cache->obj_md_size <= - main->cache_size) { - main->insert(main, params->req_local); + if (main_cache->get_occupied_byte(main_cache) + + params->req_local->obj_size + cache->obj_md_size <= + main_cache->cache_size) { + main_cache->insert(main_cache, params->req_local); #if defined(TRACK_DEMOTION) printf("%ld keep %ld %ld\n", cache->n_req, window_victim->create_time, @@ -290,7 +290,7 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { } else { // compare the frequency of window_victim and main_cache_victim - cache_obj_t *main_cache_victim = main->to_evict(main, req); + cache_obj_t *main_cache_victim = main_cache->to_evict(main_cache, req); DEBUG_ASSERT(main_cache_victim != NULL); // if window_victim is more frequent, insert it into main_cache if (minimalIncrementCBF_estimate(params->CBF, @@ -304,12 +304,13 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { window_victim->misc.next_access_vtime); #endif - main->evict(main, req); + main_cache->evict(main_cache, req); bool ret = window->remove(window, window_victim->obj_id); DEBUG_ASSERT(ret); - cache_obj_t *cache_obj = main->insert(main, params->req_local); + cache_obj_t *cache_obj = + main_cache->insert(main_cache, params->req_local); params->n_admit_bytes += params->req_local->obj_size; } else { @@ -328,7 +329,7 @@ static void WTinyLFU_evict(cache_t *cache, const request_t *req) { sizeof(obj_id_t)); } else { DEBUG_ASSERT(window->get_occupied_byte(window) == 0); - main->evict(main, req); + main_cache->evict(main_cache, req); return; } } diff --git a/libCacheSim/cache/eviction/other/S3LRU.c b/libCacheSim/cache/eviction/other/S3LRU.c index 6e356e4f9..b4be5a896 100644 --- a/libCacheSim/cache/eviction/other/S3LRU.c +++ b/libCacheSim/cache/eviction/other/S3LRU.c @@ -325,7 +325,7 @@ static void S3LRU_evict_LRU(cache_t *cache, const request_t *req) { S3LRU_params_t *params = (S3LRU_params_t *)cache->eviction_params; cache_t *LRU = params->LRU; cache_t *ghost = params->LRU_ghost; - cache_t *main = params->main_cache; + cache_t *main_cache = params->main_cache; bool has_evicted = false; @@ -341,7 +341,7 @@ static void S3LRU_evict_LRU(cache_t *cache, const request_t *req) { obj_to_evict->misc.next_access_vtime); #endif - main->insert(main, params->req_local); + main_cache->insert(main_cache, params->req_local); } else { #if defined(TRACK_DEMOTION) printf("%ld demote %ld %ld\n", cache->n_req, obj_to_evict->create_time, @@ -362,14 +362,14 @@ static void S3LRU_evict_main(cache_t *cache, const request_t *req) { S3LRU_params_t *params = (S3LRU_params_t *)cache->eviction_params; // cache_t *LRU = params->LRU; // cache_t *ghost = params->LRU_ghost; - cache_t *main = params->main_cache; + cache_t *main_cache = params->main_cache; // evict from main cache bool has_evicted = false; - while (!has_evicted && main->get_occupied_byte(main) > 0) { - cache_obj_t *obj_to_evict = main->to_evict(main, req); + while (!has_evicted && main_cache->get_occupied_byte(main_cache) > 0) { + cache_obj_t *obj_to_evict = main_cache->to_evict(main_cache, req); DEBUG_ASSERT(obj_to_evict != NULL); - bool removed = main->remove(main, obj_to_evict->obj_id); + bool removed = main_cache->remove(main_cache, obj_to_evict->obj_id); if (!removed) { ERROR("cannot remove obj %ld\n", (long)obj_to_evict->obj_id); } @@ -391,11 +391,11 @@ static void S3LRU_evict(cache_t *cache, const request_t *req) { S3LRU_params_t *params = (S3LRU_params_t *)cache->eviction_params; cache_t *LRU = params->LRU; - cache_t *main = params->main_cache; + cache_t *main_cache = params->main_cache; - if (main->get_occupied_byte(main) > main->cache_size || + if (main_cache->get_occupied_byte(main_cache) > main_cache->cache_size || LRU->get_occupied_byte(LRU) == 0) { - main->evict(main, req); + main_cache->evict(main_cache, req); return; } else { S3LRU_evict_LRU(cache, req);