end user facing functions init, free, get * @brief initialize the cache * * @param ccache_params some common cache parameters * @param cache_specific_params cache specific parameters, see parse_params * function or use -e "print" with the cachesim binary */
| 78 | * function or use -e "print" with the cachesim binary |
| 79 | */ |
| 80 | cache_t *LIRS_init(const common_cache_params_t ccache_params, |
| 81 | const char *cache_specific_params) { |
| 82 | cache_t *cache = |
| 83 | cache_struct_init("LIRS", ccache_params, cache_specific_params); |
| 84 | cache->cache_init = LIRS_init; |
| 85 | cache->cache_free = LIRS_free; |
| 86 | cache->get = LIRS_get; |
| 87 | cache->find = LIRS_find; |
| 88 | cache->can_insert = LIRS_can_insert; |
| 89 | cache->insert = LIRS_insert; |
| 90 | cache->evict = LIRS_evict; |
| 91 | cache->remove = LIRS_remove; |
| 92 | cache->to_evict = LIRS_to_evict; |
| 93 | |
| 94 | if (ccache_params.consider_obj_metadata) { |
| 95 | cache->obj_md_size = 8 * 2; |
| 96 | } else { |
| 97 | cache->obj_md_size = 0; |
| 98 | } |
| 99 | |
| 100 | cache->eviction_params = (LIRS_params_t *)malloc(sizeof(LIRS_params_t)); |
| 101 | LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params); |
| 102 | |
| 103 | params->hirs_ratio = 0.01; |
| 104 | params->hirs_limit = |
| 105 | MAX(1, (uint64_t)(params->hirs_ratio * cache->cache_size)); |
| 106 | params->lirs_limit = cache->cache_size - params->hirs_limit; |
| 107 | params->hirs_count = 0; |
| 108 | params->lirs_count = 0; |
| 109 | params->nonresident = 0; |
| 110 | |
| 111 | // initialize LRU for stack S and stack Q |
| 112 | common_cache_params_t ccache_params_s = ccache_params; |
| 113 | ccache_params_s.cache_size = params->lirs_limit; |
| 114 | common_cache_params_t ccache_params_q = ccache_params; |
| 115 | ccache_params_q.cache_size = params->hirs_limit; |
| 116 | common_cache_params_t ccache_params_nh = ccache_params; |
| 117 | |
| 118 | params->LRU_s = LRU_init(ccache_params_s, NULL); |
| 119 | params->LRU_q = LRU_init(ccache_params_q, NULL); |
| 120 | params->LRU_nh = LRU_init(ccache_params_nh, NULL); |
| 121 | |
| 122 | return cache; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * free resources used by this cache |
no test coverage detected