Skip to content

Commit cfe4979

Browse files
committed
Change parameters after certain requests
1 parent 601122e commit cfe4979

2 files changed

Lines changed: 553 additions & 3 deletions

File tree

libCacheSim/cache/eviction/S4FIFO.c

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// performance-sensitive. It will not gather other statistics information like
66
// hit position or others.
77
//
8+
// This version (S4FIFO.c) is for cache miss ratio comparison only.
9+
//
810
// S4FIFO.c
911
// libCacheSim
1012
//
@@ -23,8 +25,8 @@ typedef struct {
2325
cache_t *main_fifo;
2426
bool hit_on_ghost;
2527

26-
bool collect_features; // whether to collect features for learning-based cache
27-
// replacement, False by default
28+
// bool collect_features; // whether to collect features for learning-based cache
29+
// // replacement, False by default
2830

2931
int hit_on_ghost_freq; // frequency of the object in ghost fifo
3032
int move_to_main_threshold;
@@ -33,15 +35,26 @@ typedef struct {
3335
double small_skip_ratio;
3436
int ghost_to_main_threshold;
3537

38+
int64_t after_n_reqs;
39+
// new parameters for dynamic adjustment
40+
double ns; // double small_size_ratio;
41+
double ng; // ghost_size_ratio;
42+
double nk; // small_skip_ratio;
43+
int ngt; // ghost_to_main_threshold;
44+
int nst; // move_to_main_threshold; aka small_to_main_threshold
45+
int64_t request_count; // count the number of requests, used for dynamic adjustment
46+
3647
bool has_evicted;
48+
bool has_adjusted;
3749
request_t *req_local;
3850

3951
int64_t s_counter; // is used for small skip logic
4052
} S4FIFO_params_t;
4153

4254
static const char *DEFAULT_CACHE_PARAMS =
4355
"small-size-ratio=0.10,ghost-size-ratio=0.90,move-to-main-threshold=2,"
44-
"small-skip-ratio=0,ghost-to-main-threshold=0";
56+
"small-skip-ratio=0,ghost-to-main-threshold=0,after-n-reqs=1000,"
57+
"ns=0.10,ng=0.90,nst=2,ngt=0,nk=0.10";
4558

4659
// ***********************************************************************
4760
// **** ****
@@ -111,6 +124,7 @@ cache_t *S4FIFO_init(const common_cache_params_t ccache_params,
111124
ccache_params_local.cache_size = small_fifo_size;
112125
params->small_fifo = FIFO_init(ccache_params_local, NULL);
113126
params->has_evicted = false;
127+
params->has_adjusted = false;
114128

115129
if (ghost_fifo_size > 0) {
116130
ccache_params_local.cache_size = ghost_fifo_size;
@@ -129,6 +143,7 @@ cache_t *S4FIFO_init(const common_cache_params_t ccache_params,
129143

130144
/* S4FIFO: initialize the s_counter, since no obj enter small queue -> 0 */
131145
params->s_counter = 0;
146+
params->request_count = 0;
132147

133148
return cache;
134149
}
@@ -175,6 +190,28 @@ static bool S4FIFO_get(cache_t *cache, const request_t *req) {
175190
params->main_fifo->get_occupied_byte(params->main_fifo) <=
176191
cache->cache_size);
177192

193+
// Here we update the request count and check if we need to adjust the parameters
194+
if (params->has_evicted) params->request_count++;
195+
if (params->request_count >= params->after_n_reqs && !params->has_adjusted) {
196+
// threshould we adjust the parameters
197+
params->move_to_main_threshold = params->nst;
198+
params->small_skip_ratio = params->nk;
199+
params->ghost_to_main_threshold = params->ngt;
200+
// queue size adjustment
201+
int64_t small_fifo_size =
202+
(int64_t)cache->cache_size * params->small_size_ratio;
203+
int64_t main_fifo_size = cache->cache_size - small_fifo_size;
204+
int64_t ghost_fifo_size =
205+
(int64_t)(cache->cache_size * params->ghost_size_ratio);
206+
207+
params->small_fifo->resize(params->small_fifo, small_fifo_size);
208+
if (params->ghost_fifo != NULL) {
209+
params->ghost_fifo->resize(params->ghost_fifo, ghost_fifo_size);
210+
}
211+
params->main_fifo->resize(params->main_fifo, main_fifo_size);
212+
params->has_adjusted = true;
213+
}
214+
178215
bool cache_hit = cache_get_base(cache, req);
179216

180217
return cache_hit;
@@ -485,6 +522,18 @@ static void S4FIFO_parse_params(cache_t *cache,
485522
params->small_skip_ratio = strtod(value, NULL);
486523
} else if (strcasecmp(key, "ghost-to-main-threshold") == 0) {
487524
params->ghost_to_main_threshold = atoi(value);
525+
} else if (strcasecmp(key, "after-n-reqs") == 0) {
526+
params->after_n_reqs = atoi(value);
527+
} else if (strcasecmp(key, "ns") == 0) {
528+
params->ns = strtod(value, NULL);
529+
} else if (strcasecmp(key, "ng") == 0) {
530+
params->ng = strtod(value, NULL);
531+
} else if (strcasecmp(key, "nk") == 0) {
532+
params->nk = strtod(value, NULL);
533+
} else if (strcasecmp(key, "nst") == 0) {
534+
params->nst = atoi(value);
535+
} else if (strcasecmp(key, "ngt") == 0) {
536+
params->ngt = atoi(value);
488537
} else if (strcasecmp(key, "print") == 0) {
489538
printf("parameters: %s\n", S4FIFO_current_params(params));
490539
exit(0);

0 commit comments

Comments
 (0)