* @brief insert an object into the cache, * update the hash table and cache metadata * this function assumes the cache has enough space * and eviction is not part of this function * * @param cache * @param req * @return the inserted object */
| 230 | * @return the inserted object |
| 231 | */ |
| 232 | static cache_obj_t *CAR_insert(cache_t *cache, const request_t *req){ |
| 233 | CAR_params_t *params = (CAR_params_t *)(cache->eviction_params); |
| 234 | cache_obj_t *obj = cache_insert_base(cache, req); |
| 235 | |
| 236 | if( |
| 237 | (params->curr_obj_in_L1_ghost || params->curr_obj_in_L2_ghost) |
| 238 | ) { |
| 239 | // Insert at the tail of T2 |
| 240 | obj->CAR.lru_id = 2; |
| 241 | obj->CAR.reference = false; // Set the page reference bit to 0 |
| 242 | append_obj_to_tail(¶ms->L2_data_head, ¶ms->L2_data_tail,obj); |
| 243 | params->L2_data_size += req->obj_size + cache->obj_md_size; |
| 244 | |
| 245 | params->curr_obj_in_L1_ghost = false; |
| 246 | params->curr_obj_in_L2_ghost = false; |
| 247 | } else { |
| 248 | // Insert at the tail of T1 |
| 249 | obj->CAR.lru_id = 1; |
| 250 | obj->CAR.reference = false; // Set the page reference bit to 0 |
| 251 | append_obj_to_tail(¶ms->L1_data_head, ¶ms->L1_data_tail,obj); |
| 252 | params->L1_data_size += req->obj_size + cache->obj_md_size; |
| 253 | |
| 254 | } |
| 255 | |
| 256 | return obj; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * @brief find the object to be evicted |
nothing calls this directly
no test coverage detected