Skip to content

Commit e3f19f9

Browse files
committed
fix: address code review findings in Clock2QPlus
- comment corr_window_size_upper/lower_bound fields - fix time_since_insertion type: int -> int64_t - save obj_id before remove() to avoid potential UAF
1 parent 97464bf commit e3f19f9

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

libCacheSim/cache/eviction/Clock2QPlus.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ typedef struct {
3131
double fifo_size_ratio;
3232
double ghost_size_ratio;
3333
double corr_window_ratio;
34+
// bounds for dynamic corr_window_size adjustment (0.5x and 0.1x of fifo size)
3435
int64_t corr_window_size_upper_bound;
3536
int64_t corr_window_size_lower_bound;
36-
double corr_window_size;
37+
double corr_window_size; // current correlation window (in # of FIFO inserts)
3738
// used to indicate whether the cache is full
3839
bool has_evicted;
3940
char main_cache_type[32];
@@ -229,7 +230,7 @@ static cache_obj_t *Clock2QPlus_find(cache_t *cache, const request_t *req,
229230
cache_obj_t *obj = params->fifo->find(params->fifo, req, true);
230231

231232
if (obj != NULL) {
232-
int time_since_insertion =
233+
int64_t time_since_insertion =
233234
params->n_obj_admit_to_fifo - obj->Clock2QPlus.insertion_time;
234235
if (time_since_insertion >= params->corr_window_size) {
235236
obj->Clock2QPlus.freq += 1;
@@ -376,9 +377,10 @@ static void Clock2QPlus_evict_main(cache_t *cache, const request_t *req) {
376377
new_obj->Clock2QPlus.freq = 0;
377378
new_obj->freq = freq;
378379
} else {
379-
bool removed = main->remove(main, obj_to_evict->obj_id);
380+
obj_id_t obj_id = obj_to_evict->obj_id;
381+
bool removed = main->remove(main, obj_id);
380382
if (!removed) {
381-
ERROR("cannot remove obj %" PRIu64 "\n", obj_to_evict->obj_id);
383+
ERROR("cannot remove obj %" PRIu64 "\n", obj_id);
382384
}
383385

384386
has_evicted = true;

0 commit comments

Comments
 (0)