Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ jobs:
- uses: actions/checkout@v2
- name: Prepare
run: bash scripts/install_dependency.sh
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Configure CMake with LSan
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_C_FLAGS="-fsanitize=leak" \
-DCMAKE_CXX_FLAGS="-fsanitize=leak"
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
- name: Test with LSan
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
run: |
export ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:verbosity=1"
ctest -C ${{env.BUILD_TYPE}} --output-on-failure

selfhosted:
runs-on: self-hosted
Expand Down
10 changes: 7 additions & 3 deletions libCacheSim/cache/eviction/LFUDA.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static void free_list_node(void *list_node);
*/
cache_t *LFUDA_init(const common_cache_params_t ccache_params,
const char *cache_specific_params) {
cache_t *cache = cache_struct_init("LFUDA", ccache_params, cache_specific_params);
cache_t *cache =
cache_struct_init("LFUDA", ccache_params, cache_specific_params);
cache->cache_init = LFUDA_init;
cache->cache_free = LFUDA_free;
cache->get = LFUDA_get;
Expand Down Expand Up @@ -102,6 +103,7 @@ cache_t *LFUDA_init(const common_cache_params_t ccache_params,
static void LFUDA_free(cache_t *cache) {
LFUDA_params_t *params = (LFUDA_params_t *)(cache->eviction_params);
g_hash_table_destroy(params->freq_map);
free(params);
cache_struct_free(cache);
}

Expand Down Expand Up @@ -216,7 +218,9 @@ static cache_obj_t *LFUDA_insert(cache_t *cache, const request_t *req) {
memset(new_node, 0, sizeof(freq_node_t));
new_node->freq = cache_obj->lfu.freq;
g_hash_table_insert(params->freq_map, key, new_node);
params->max_freq = params->max_freq < cache_obj->lfu.freq ? cache_obj->lfu.freq : params->max_freq;
params->max_freq = params->max_freq < cache_obj->lfu.freq
? cache_obj->lfu.freq
: params->max_freq;
} else {
DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);
}
Expand Down Expand Up @@ -354,7 +358,7 @@ static void update_min_freq(LFUDA_params_t *params) {
break;
}
}
// If cache is empty, min_freq will be unchanged.
// If cache is empty, min_freq will be unchanged.
DEBUG_ASSERT(params->min_freq >= old_min_freq);
}

Expand Down
73 changes: 46 additions & 27 deletions libCacheSim/cache/eviction/LIRS.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ typedef struct LIRS_params {
uint64_t nonresident;
} LIRS_params_t;

/**
* @brief local request for thread local storage
*/
static __thread request_t *req_local_hit_RD_HIRinQ = NULL;
static __thread request_t *req_local_evictLIR = NULL;
static __thread request_t *req_local_evictHIR = NULL;

// ***********************************************************************
// **** ****
// **** function declarations ****
Expand Down Expand Up @@ -125,6 +132,20 @@ static void LIRS_free(cache_t *cache) {
params->LRU_s->cache_free(params->LRU_s);
params->LRU_q->cache_free(params->LRU_q);
params->LRU_nh->cache_free(params->LRU_nh);

if (req_local_hit_RD_HIRinQ != NULL) {
free_request(req_local_hit_RD_HIRinQ);
req_local_hit_RD_HIRinQ = NULL;
}
if (req_local_evictLIR != NULL) {
free_request(req_local_evictLIR);
req_local_evictLIR = NULL;
}
if (req_local_evictHIR != NULL) {
free_request(req_local_evictHIR);
req_local_evictHIR = NULL;
}

my_free(sizeof(LIRS_params_t), params);
cache_struct_free(cache);
}
Expand Down Expand Up @@ -553,9 +574,10 @@ static cache_obj_t *hit_RD_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s,
LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params);

if (cache_obj_q != NULL) {
params->hirs_count -= cache_obj_q->obj_size;
int64_t obj_size = cache_obj_q->obj_size;
params->hirs_count -= obj_size;
params->LRU_q->remove(params->LRU_q, cache_obj_q->obj_id);
cache->occupied_byte -= cache_obj_q->obj_size;
cache->occupied_byte -= obj_size;
cache->n_obj--;
}

Expand Down Expand Up @@ -583,19 +605,17 @@ static cache_obj_t *hit_NR_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s) {

static cache_obj_t *hit_RD_HIRinQ(cache_t *cache, cache_obj_t *cache_obj_q) {
LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params);

static __thread request_t *req_local = NULL;
if (req_local == NULL) {
req_local = new_request();
if (req_local_hit_RD_HIRinQ == NULL) {
req_local_hit_RD_HIRinQ = new_request();
}
copy_cache_obj_to_request(req_local, cache_obj_q);
copy_cache_obj_to_request(req_local_hit_RD_HIRinQ, cache_obj_q);

while (params->lirs_count + cache_obj_q->obj_size > params->lirs_limit) {
evictLIR(cache);
}
params->LRU_s->insert(params->LRU_s, req_local);
params->LRU_s->insert(params->LRU_s, req_local_hit_RD_HIRinQ);
cache_obj_t *obj_to_update =
params->LRU_s->find(params->LRU_s, req_local, false);
params->LRU_s->find(params->LRU_s, req_local_hit_RD_HIRinQ, false);
obj_to_update->LIRS.is_LIR = false;
obj_to_update->LIRS.in_cache = true;

Expand All @@ -606,30 +626,30 @@ static void evictLIR(cache_t *cache) {
LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params);
cache_obj_t *obj_to_evict = params->LRU_s->to_evict(params->LRU_s, NULL);

static __thread request_t *req_local = NULL;
if (req_local == NULL) {
req_local = new_request();
if (req_local_evictLIR == NULL) {
req_local_evictLIR = new_request();
}
copy_cache_obj_to_request(req_local, obj_to_evict);
copy_cache_obj_to_request(req_local_evictLIR, obj_to_evict);
params->lirs_count -= obj_to_evict->obj_size;
params->LRU_s->evict(params->LRU_s, NULL);

cache->occupied_byte -= (req_local->obj_size + cache->obj_md_size);
cache->occupied_byte -= (req_local_evictLIR->obj_size + cache->obj_md_size);
cache->n_obj -= 1;

if ((uint64_t)req_local->obj_size <= params->hirs_limit) {
while ((uint64_t)params->hirs_count + req_local->obj_size > params->hirs_limit) {
if ((uint64_t)req_local_evictLIR->obj_size <= params->hirs_limit) {
while ((uint64_t)params->hirs_count + req_local_evictLIR->obj_size >
params->hirs_limit) {
evictHIR(cache);
}
params->LRU_q->insert(params->LRU_q, req_local);
params->LRU_q->insert(params->LRU_q, req_local_evictLIR);

cache_obj_t *obj_to_update =
params->LRU_q->find(params->LRU_q, req_local, false);
params->LRU_q->find(params->LRU_q, req_local_evictLIR, false);
obj_to_update->LIRS.is_LIR = false;
obj_to_update->LIRS.in_cache = true;

params->hirs_count += req_local->obj_size;
cache->occupied_byte += (req_local->obj_size + cache->obj_md_size);
params->hirs_count += req_local_evictLIR->obj_size;
cache->occupied_byte += (req_local_evictLIR->obj_size + cache->obj_md_size);
cache->n_obj += 1;
}

Expand All @@ -642,24 +662,23 @@ static bool evictHIR(cache_t *cache) {
cache_obj_t *obj_to_evict = params->LRU_q->to_evict(params->LRU_q, NULL);

// update the corresponding block in S to be non-resident
static __thread request_t *req_local = NULL;
if (req_local == NULL) {
req_local = new_request();
if (req_local_evictHIR == NULL) {
req_local_evictHIR = new_request();
}
copy_cache_obj_to_request(req_local, obj_to_evict);
copy_cache_obj_to_request(req_local_evictHIR, obj_to_evict);

params->hirs_count -= obj_to_evict->obj_size;
params->LRU_q->evict(params->LRU_q, NULL);

cache_obj_t *obj_to_update =
params->LRU_s->find(params->LRU_s, req_local, false);
params->LRU_s->find(params->LRU_s, req_local_evictHIR, false);
if (obj_to_update != NULL) {
obj_to_update->LIRS.in_cache = false;
params->LRU_nh->insert(params->LRU_nh, req_local);
params->LRU_nh->insert(params->LRU_nh, req_local_evictHIR);
params->nonresident += obj_to_update->obj_size;
}

cache->occupied_byte -= (req_local->obj_size + cache->obj_md_size);
cache->occupied_byte -= (req_local_evictHIR->obj_size + cache->obj_md_size);
cache->n_obj -= 1;

return true;
Expand Down
6 changes: 5 additions & 1 deletion libCacheSim/cache/eviction/LRU.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ cache_t *LRU_init(const common_cache_params_t ccache_params,
*
* @param cache
*/
static void LRU_free(cache_t *cache) { cache_struct_free(cache); }
static void LRU_free(cache_t *cache) {
LRU_params_t *params = (LRU_params_t *)cache->eviction_params;
free(params);
cache_struct_free(cache);
}

/**
* @brief this function is the user facing API
Expand Down
6 changes: 4 additions & 2 deletions libCacheSim/cache/eviction/SLRU.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ static void SLRU_free(cache_t *cache) {
free(params->lru_tails);
free(params->lru_n_objs);
free(params->lru_n_bytes);
free(params);
cache_struct_free(cache);
}

Expand Down Expand Up @@ -450,8 +451,9 @@ static void SLRU_parse_params(cache_t *cache,
params->n_seg = n_seg;
params->lru_max_n_bytes = calloc(params->n_seg, sizeof(int64_t));
for (int i = 0; i < n_seg; i++) {
params->lru_max_n_bytes[i] = (int64_t)(
(double)seg_size_array[i] / seg_size_sum * cache->cache_size);
params->lru_max_n_bytes[i] =
(int64_t)((double)seg_size_array[i] / seg_size_sum *
cache->cache_size);
}
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", SLRU_current_params(cache, params));
Expand Down
3 changes: 3 additions & 0 deletions libCacheSim/mrcProfiler/mrcProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,7 @@ void mrcProfiler::MRCProfilerMINISIM::run() {
hit_size_vec[i] = sum_obj_size_req - result[i].n_miss_byte;
}
}
// clean up
my_free(sizeof(cache_stat_t) * mrc_size_vec.size(), result);
free_request(req);
}
Loading