| 77 | // *********************************************************************** |
| 78 | |
| 79 | cache_t *S3FIFO_init(const common_cache_params_t ccache_params, const char *cache_specific_params) { |
| 80 | cache_t *cache = cache_struct_init("S3FIFO", ccache_params, cache_specific_params); |
| 81 | cache->cache_init = S3FIFO_init; |
| 82 | cache->cache_free = S3FIFO_free; |
| 83 | cache->get = S3FIFO_get; |
| 84 | cache->find = S3FIFO_find; |
| 85 | cache->insert = S3FIFO_insert; |
| 86 | cache->evict = S3FIFO_evict; |
| 87 | cache->remove = S3FIFO_remove; |
| 88 | cache->to_evict = S3FIFO_to_evict; |
| 89 | cache->get_n_obj = S3FIFO_get_n_obj; |
| 90 | cache->get_occupied_byte = S3FIFO_get_occupied_byte; |
| 91 | cache->can_insert = S3FIFO_can_insert; |
| 92 | |
| 93 | cache->obj_md_size = 0; |
| 94 | |
| 95 | cache->eviction_params = malloc(sizeof(S3FIFO_params_t)); |
| 96 | memset(cache->eviction_params, 0, sizeof(S3FIFO_params_t)); |
| 97 | S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params; |
| 98 | params->req_local = new_request(); |
| 99 | params->hit_on_ghost = false; |
| 100 | |
| 101 | S3FIFO_parse_params(cache, DEFAULT_CACHE_PARAMS); |
| 102 | if (cache_specific_params != NULL) { |
| 103 | S3FIFO_parse_params(cache, cache_specific_params); |
| 104 | } |
| 105 | |
| 106 | int64_t small_fifo_size = (int64_t)ccache_params.cache_size * params->small_size_ratio; |
| 107 | int64_t main_fifo_size = ccache_params.cache_size - small_fifo_size; |
| 108 | int64_t ghost_fifo_size = (int64_t)(ccache_params.cache_size * params->ghost_size_ratio); |
| 109 | |
| 110 | common_cache_params_t ccache_params_local = ccache_params; |
| 111 | ccache_params_local.cache_size = small_fifo_size; |
| 112 | params->small_fifo = FIFO_init(ccache_params_local, NULL); |
| 113 | params->has_evicted = false; |
| 114 | |
| 115 | if (ghost_fifo_size > 0) { |
| 116 | ccache_params_local.cache_size = ghost_fifo_size; |
| 117 | params->ghost_fifo = FIFO_init(ccache_params_local, NULL); |
| 118 | snprintf(params->ghost_fifo->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-ghost"); |
| 119 | } else { |
| 120 | params->ghost_fifo = NULL; |
| 121 | } |
| 122 | |
| 123 | ccache_params_local.cache_size = main_fifo_size; |
| 124 | params->main_fifo = FIFO_init(ccache_params_local, NULL); |
| 125 | |
| 126 | snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "S3FIFO-%.4lf-%d", params->small_size_ratio, |
| 127 | params->move_to_main_threshold); |
| 128 | |
| 129 | return cache; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * free resources used by this cache |
no test coverage detected