* @brief insert an object into the cache, * update the hash table and cache metadata * this function assumes the cache has enough space * eviction should be * performed before calling this function * * @param cache * @param req * @return the inserted object */
| 240 | * @return the inserted object |
| 241 | */ |
| 242 | static cache_obj_t *S3FIFO_insert(cache_t *cache, const request_t *req) { |
| 243 | S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; |
| 244 | cache_obj_t *obj = NULL; |
| 245 | |
| 246 | cache_t *small = params->small_fifo; |
| 247 | cache_t *main = params->main_fifo; |
| 248 | |
| 249 | if (params->hit_on_ghost) { |
| 250 | /* insert into main FIFO */ |
| 251 | params->hit_on_ghost = false; |
| 252 | obj = main->insert(main, req); |
| 253 | } else { |
| 254 | /* insert into small fifo */ |
| 255 | if (req->obj_size >= small->cache_size) { |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | if (!params->has_evicted && small->get_occupied_byte(small) >= small->cache_size) { |
| 260 | obj = main->insert(main, req); |
| 261 | } else { |
| 262 | obj = small->insert(small, req); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | obj->S3FIFO.freq = 0; |
| 267 | |
| 268 | return obj; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @brief find the object to be evicted |