Skip to content

Commit

Permalink
algorithm update
Browse files Browse the repository at this point in the history
1. update Cloud2QPlus to add new entries into the main queue when the small queue is full but cache not full
2. add S3FIFOv2 which adds new entries to the main queue when the small fifo is full but cache is not full

This change significantly reduces miss ratio at large cache sizes because newly inserted objects (after cache is full) are evicted faster from the small queue
  • Loading branch information
1a1a11a committed May 29, 2024
1 parent 6a9a909 commit 963d0dc
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 39 deletions.
2 changes: 2 additions & 0 deletions libCacheSim/bin/cachesim/cache_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ static inline cache_t *create_cache(const char *trace_path,
cache = S3LRU_init(cc_params, eviction_params);
} else if (strcasecmp(eviction_algo, "s3fifo") == 0) {
cache = S3FIFO_init(cc_params, eviction_params);
} else if (strcasecmp(eviction_algo, "s3fifov2") == 0) {
cache = S3FIFOv2_init(cc_params, eviction_params);
} else if (strcasecmp(eviction_algo, "s3fifod") == 0) {
cache = S3FIFOd_init(cc_params, eviction_params);
} else if (strcasecmp(eviction_algo, "qdlp") == 0) {
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(sourceC
FIFO_Reinsertion.c

S3FIFO.c
S3FIFOv2.c
S3FIFOd.c

other/flashProb.c
Expand Down
36 changes: 29 additions & 7 deletions libCacheSim/cache/eviction/Cloud2QPlus.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ typedef struct {
double fifo_size_ratio;
double ghost_size_ratio;
double corr_window_ratio;
// used to indicate whether the cache is full
bool has_evicted;
char main_cache_type[32];

request_t *req_local;
} Cloud2QPlus_params_t;

static const char *DEFAULT_CACHE_PARAMS =
"fifo-size-ratio=0.10,ghost-size-ratio=0.90,move-to-main-threshold=2,"
"corr-window-ratio=0.2";
"corr-window-ratio=0.0";

// ***********************************************************************
// **** ****
Expand Down Expand Up @@ -108,6 +110,7 @@ cache_t *Cloud2QPlus_init(const common_cache_params_t ccache_params,
params->req_local = new_request();
params->hit_on_ghost = false;
params->corr_window_ratio = 0.2;
params->has_evicted = false;

Cloud2QPlus_parse_params(cache, DEFAULT_CACHE_PARAMS);
if (cache_specific_params != NULL) {
Expand Down Expand Up @@ -194,6 +197,7 @@ static bool Cloud2QPlus_get(cache_t *cache, const request_t *req) {
cache->cache_size);

bool cache_hit = cache_get_base(cache, req);
// printf("---------- get %ld %d\n", req->obj_id, cache_hit);

return cache_hit;
}
Expand Down Expand Up @@ -233,13 +237,14 @@ static cache_obj_t *Cloud2QPlus_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);

if (obj != NULL) {
int time_since_insertion =
params->n_obj_admit_to_fifo - obj->Cloud2QPlus.insertion_time;
if (time_since_insertion >
params->fifo->cache_size * params->corr_window_ratio) {
// if (time_since_insertion <= params->fifo->cache_size)
obj->Cloud2QPlus.freq += 1;
obj->Cloud2QPlus.freq += 1;
}
return obj;
}
Expand Down Expand Up @@ -274,20 +279,31 @@ static cache_obj_t *Cloud2QPlus_insert(cache_t *cache, const request_t *req) {
cache_obj_t *obj = NULL;

if (params->hit_on_ghost) {
/* insert into the ARC */
// printf("---- insert main %ld\n", req->obj_id);
/* insert into the main */
params->hit_on_ghost = false;
params->n_obj_admit_to_main += 1;
params->n_byte_admit_to_main += req->obj_size;
obj = params->main_cache->insert(params->main_cache, req);
} else {
// printf("---- insert fifo %ld\n", req->obj_id);
/* insert into the fifo */
if (req->obj_size >= params->fifo->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);
obj->Cloud2QPlus.insertion_time = params->n_obj_admit_to_fifo;
/* if the cache is not full, but small fifo is full
* insert to the main fifo, this happens during warmup */
if (!params->has_evicted && params->fifo->get_occupied_byte(params->fifo) >=
params->fifo->cache_size) {
params->n_obj_admit_to_main += 1;
params->n_byte_admit_to_main += req->obj_size;
obj = params->main_cache->insert(params->main_cache, req);
} else {
params->n_obj_admit_to_fifo += 1;
params->n_byte_admit_to_fifo += req->obj_size;
obj = params->fifo->insert(params->fifo, req);
obj->Cloud2QPlus.insertion_time = params->n_obj_admit_to_fifo;
}
}

#if defined(TRACK_EVICTION_V_AGE)
Expand Down Expand Up @@ -338,11 +354,14 @@ static void Cloud2QPlus_evict_fifo(cache_t *cache, const request_t *req) {
params->n_byte_move_to_main += obj_to_evict->obj_size;

cache_obj_t *new_obj = main->insert(main, params->req_local);
// printf("---- reinsert fifo %ld\n", new_obj->obj_id);

new_obj->misc.freq = obj_to_evict->misc.freq;
} else {
// insert to ghost
if (ghost != NULL) {
ghost->get(ghost, params->req_local);
// printf("---- evict fifo %ld\n", params->req_local->obj_id);
}
has_evicted = true;
}
Expand Down Expand Up @@ -376,8 +395,10 @@ static void Cloud2QPlus_evict_main(cache_t *cache, const request_t *req) {
// clock with 2-bit counter
new_obj->Cloud2QPlus.freq = MIN(freq, 3) - 1;
new_obj->misc.freq = freq;
// printf("---- reinsert main %ld\n", params->req_local->obj_id);
} else {
// main->evict(main, req);
// printf("---- evict main %ld\n", obj_to_evict->obj_id);
bool removed = main->remove(main, obj_to_evict->obj_id);
if (!removed) {
ERROR("cannot remove obj %ld\n", obj_to_evict->obj_id);
Expand All @@ -404,6 +425,7 @@ static void Cloud2QPlus_evict(cache_t *cache, const request_t *req) {
cache_t *ghost = params->fifo_ghost;
cache_t *main = params->main_cache;

params->has_evicted = true;
if (main->get_occupied_byte(main) > main->cache_size ||
fifo->get_occupied_byte(fifo) == 0) {
return Cloud2QPlus_evict_main(cache, req);
Expand Down
16 changes: 7 additions & 9 deletions libCacheSim/cache/eviction/S3FIFO.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,7 @@ static bool S3FIFO_get(cache_t *cache, const request_t *req) {

bool cache_hit = cache_get_base(cache, req);

// if (cache->n_req % 1000000 == 0) {
// double s = params->n_obj_admit_to_fifo + params->n_obj_admit_to_main +
// params->n_obj_move_to_main;
// printf("%ld %ld: %.4lf/%.4lf/%.4lf, %ld %ld\n", cache->n_req,
// cache->cache_size, (double)params->n_obj_admit_to_fifo / s,
// (double)params->n_obj_admit_to_main / s,
// (double)params->n_obj_move_to_main / s, params->fifo->cache_size,
// params->main_cache->cache_size);
// }
// printf("---------- get %ld %d\n", req->obj_id, cache_hit);

return cache_hit;
}
Expand Down Expand Up @@ -274,12 +266,14 @@ static cache_obj_t *S3FIFO_insert(cache_t *cache, const request_t *req) {
cache_obj_t *obj = NULL;

if (params->hit_on_ghost) {
// printf("---- insert main %ld\n", req->obj_id);
/* insert into the ARC */
params->hit_on_ghost = false;
params->n_obj_admit_to_main += 1;
params->n_byte_admit_to_main += req->obj_size;
obj = params->main_cache->insert(params->main_cache, req);
} else {
// printf("---- insert fifo %ld\n", req->obj_id);
/* insert into the fifo */
if (req->obj_size >= params->fifo->cache_size) {
return NULL;
Expand Down Expand Up @@ -341,6 +335,7 @@ static void S3FIFO_evict_fifo(cache_t *cache, const request_t *req) {
params->n_byte_move_to_main += obj_to_evict->obj_size;

cache_obj_t *new_obj = main->insert(main, params->req_local);
// printf("---- reinsert fifo %ld\n", new_obj->obj_id);
new_obj->misc.freq = obj_to_evict->misc.freq;
#if defined(TRACK_EVICTION_V_AGE)
new_obj->create_time = obj_to_evict->create_time;
Expand All @@ -358,6 +353,7 @@ static void S3FIFO_evict_fifo(cache_t *cache, const request_t *req) {

// insert to ghost
if (ghost != NULL) {
// printf("---- evict fifo %ld\n", params->req_local->obj_id);
ghost->get(ghost, params->req_local);
}
has_evicted = true;
Expand Down Expand Up @@ -391,6 +387,7 @@ static void S3FIFO_evict_main(cache_t *cache, const request_t *req) {
main->remove(main, obj_to_evict->obj_id);
obj_to_evict = NULL;

// printf("---- reinsert main %ld\n", params->req_local->obj_id);
cache_obj_t *new_obj = main->insert(main, params->req_local);
// clock with 2-bit counter
new_obj->S3FIFO.freq = MIN(freq, 3) - 1;
Expand All @@ -405,6 +402,7 @@ static void S3FIFO_evict_main(cache_t *cache, const request_t *req) {
CURR_TIME(cache, req) - obj_to_evict->create_time);
#endif

// printf("---- evict main %ld\n", obj_to_evict->obj_id);
// main->evict(main, req);
bool removed = main->remove(main, obj_to_evict->obj_id);
if (!removed) {
Expand Down
Loading

0 comments on commit 963d0dc

Please sign in to comment.