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

Function Cacheus_evict

libCacheSim/cache/eviction/Cacheus.c:270–315  ·  view source on GitHub ↗

* @brief evict an object from the cache * it needs to call cache_evict_base before returning * which updates some metadata such as n_obj, occupied size, and hash table * * @param cache * @param req not used */

Source from the content-addressed store, hash-verified

268 * @param req not used
269 */
270static void Cacheus_evict(cache_t *cache, const request_t *req) {
271 Cacheus_params_t *params = (Cacheus_params_t *)(cache->eviction_params);
272 cache_t *lru = params->LRU;
273 cache_t *lfu = params->LFU;
274 cache_t *lru_g = params->LRU_g;
275 cache_t *lfu_g = params->LFU_g;
276
277 // If two voters decide the same:
278 cache_obj_t *lru_to_evict = lru->to_evict(lru, req);
279 cache_obj_t *lfu_to_evict = lfu->to_evict(lfu, req);
280 DEBUG_ASSERT(lru_to_evict != NULL);
281 DEBUG_ASSERT(lfu_to_evict != NULL);
282
283 cache_obj_t *obj_to_evict = NULL;
284 if (cache->to_evict_candidate_gen_vtime == cache->n_req) {
285 obj_to_evict = cache->to_evict_candidate;
286 } else {
287 obj_to_evict = Cacheus_to_evict(cache, req);
288 }
289
290 if (lru_to_evict->obj_id == lfu_to_evict->obj_id) {
291 lru->evict(lru, req);
292 lfu->evict(lfu, req);
293 } else if (obj_to_evict == lru_to_evict) {
294 copy_cache_obj_to_request(params->req_local, obj_to_evict);
295 lru->evict(lru, req);
296 bool removed = lfu->remove(lfu, params->req_local->obj_id);
297 DEBUG_ASSERT(removed);
298 // insert into ghost
299 bool ghost_hit = lru_g->get(lru_g, params->req_local);
300 DEBUG_ASSERT(!ghost_hit);
301 } else {
302 // Remove first because LFU needs to offload the freq to obj in LRU
303 // history
304 copy_cache_obj_to_request(params->req_local, obj_to_evict);
305 // LRU remove needs to before LFU evict
306 bool removed = lru->remove(lru, params->req_local->obj_id);
307 DEBUG_ASSERT(removed);
308 lfu->evict(lfu, req);
309 // insert into ghost
310 bool ghost_hit = lfu_g->get(lfu_g, params->req_local);
311 DEBUG_ASSERT(!ghost_hit);
312 }
313
314 cache->to_evict_candidate_gen_vtime = -1;
315}
316
317static bool Cacheus_remove(cache_t *cache, const obj_id_t obj_id) {
318 Cacheus_params_t *params = (Cacheus_params_t *)(cache->eviction_params);

Callers

nothing calls this directly

Calls 5

Cacheus_to_evictFunction · 0.85
evictMethod · 0.45
removeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected