MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / SLRU_init

Function SLRU_init

libCacheSim/cache/eviction/SLRU.c:103–191  ·  view source on GitHub ↗

end user facing functions * @brief initialize a LRU cache * * @param ccache_params some common cache parameters * @param cache_specific_params LRU specific parameters, should be NULL */

Source from the content-addressed store, hash-verified

101 * @param cache_specific_params LRU specific parameters, should be NULL
102 */
103cache_t *SLRU_init(const common_cache_params_t ccache_params,
104 const char *cache_specific_params) {
105 cache_t *cache =
106 cache_struct_init("SLRU", ccache_params, cache_specific_params);
107 cache->cache_init = SLRU_init;
108 cache->cache_free = SLRU_free;
109 cache->get = SLRU_get;
110 cache->find = SLRU_find;
111 cache->insert = SLRU_insert;
112 cache->evict = SLRU_evict;
113 cache->remove = SLRU_remove;
114 cache->to_evict = SLRU_to_evict;
115 cache->can_insert = SLRU_can_insert;
116
117 if (ccache_params.consider_obj_metadata) {
118 cache->obj_md_size = 8 * 2;
119 } else {
120 cache->obj_md_size = 0;
121 }
122
123 cache->eviction_params = (SLRU_params_t *)malloc(sizeof(SLRU_params_t));
124 SLRU_params_t *params = (SLRU_params_t *)(cache->eviction_params);
125 memset(params, 0, sizeof(SLRU_params_t));
126 params->n_seg = 4;
127
128 if (cache_specific_params != NULL) {
129 SLRU_parse_params(cache, cache_specific_params);
130 }
131
132 if (params->lru_max_n_bytes == NULL) {
133 // if the user does not specify segment size
134 params->lru_max_n_bytes = calloc(params->n_seg, sizeof(int64_t));
135 for (int i = 0; i < params->n_seg; i++) {
136 params->lru_max_n_bytes[i] =
137 (int64_t)ccache_params.cache_size / params->n_seg;
138 }
139 }
140
141 params->lru_heads =
142 (cache_obj_t **)malloc(sizeof(cache_obj_t *) * params->n_seg);
143 params->lru_tails =
144 (cache_obj_t **)malloc(sizeof(cache_obj_t *) * params->n_seg);
145 params->lru_n_objs = (int64_t *)malloc(sizeof(int64_t) * params->n_seg);
146 params->lru_n_bytes = (int64_t *)malloc(sizeof(int64_t) * params->n_seg);
147
148 for (int i = 0; i < params->n_seg; i++) {
149 params->lru_heads[i] = NULL;
150 params->lru_tails[i] = NULL;
151 params->lru_n_objs[i] = 0;
152 params->lru_n_bytes[i] = 0;
153 }
154
155 // update slru cache name
156 bool same_size = true;
157 for (int i = 1; i < params->n_seg; i++) {
158 if (params->lru_max_n_bytes[i] != params->lru_max_n_bytes[i - 1]) {
159 same_size = false;
160 break;

Callers 4

create_test_cacheFunction · 0.85
QDLP_initFunction · 0.85
WTinyLFU_initFunction · 0.85
create_cacheFunction · 0.85

Calls 2

cache_struct_initFunction · 0.85
SLRU_parse_paramsFunction · 0.85

Tested by

no test coverage detected