| 72 | // *********************************************************************** |
| 73 | |
| 74 | cache_t *S3FIFOd_init(const common_cache_params_t ccache_params, |
| 75 | const char *cache_specific_params) { |
| 76 | cache_t *cache = cache_struct_init("S3FIFOd", ccache_params, cache_specific_params); |
| 77 | cache->cache_init = S3FIFOd_init; |
| 78 | cache->cache_free = S3FIFOd_free; |
| 79 | cache->get = S3FIFOd_get; |
| 80 | cache->find = S3FIFOd_find; |
| 81 | cache->insert = S3FIFOd_insert; |
| 82 | cache->evict = S3FIFOd_evict; |
| 83 | cache->remove = S3FIFOd_remove; |
| 84 | cache->to_evict = S3FIFOd_to_evict; |
| 85 | cache->get_n_obj = S3FIFOd_get_n_obj; |
| 86 | cache->get_occupied_byte = S3FIFOd_get_occupied_byte; |
| 87 | cache->can_insert = S3FIFOd_can_insert; |
| 88 | |
| 89 | cache->obj_md_size = 0; |
| 90 | |
| 91 | cache->eviction_params = malloc(sizeof(S3FIFOd_params_t)); |
| 92 | memset(cache->eviction_params, 0, sizeof(S3FIFOd_params_t)); |
| 93 | S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params; |
| 94 | params->req_local = new_request(); |
| 95 | params->hit_on_ghost = false; |
| 96 | |
| 97 | S3FIFOd_parse_params(cache, DEFAULT_CACHE_PARAMS); |
| 98 | if (cache_specific_params != NULL) { |
| 99 | S3FIFOd_parse_params(cache, cache_specific_params); |
| 100 | } |
| 101 | |
| 102 | int64_t fifo_cache_size = |
| 103 | (int64_t)ccache_params.cache_size * params->fifo_size_ratio; |
| 104 | int64_t main_cache_size = ccache_params.cache_size - fifo_cache_size; |
| 105 | int64_t fifo_ghost_cache_size = main_cache_size; |
| 106 | |
| 107 | common_cache_params_t ccache_params_local = ccache_params; |
| 108 | ccache_params_local.cache_size = fifo_cache_size; |
| 109 | params->fifo = FIFO_init(ccache_params_local, NULL); |
| 110 | |
| 111 | ccache_params_local.cache_size = fifo_ghost_cache_size; |
| 112 | params->fifo_ghost = FIFO_init(ccache_params_local, NULL); |
| 113 | snprintf(params->fifo_ghost->cache_name, CACHE_NAME_ARRAY_LEN, "FIFO-ghost"); |
| 114 | |
| 115 | ccache_params_local.cache_size = main_cache_size; |
| 116 | if (strcasecmp(params->main_cache_type, "FIFO") == 0) { |
| 117 | params->main_cache = FIFO_init(ccache_params_local, NULL); |
| 118 | } else if (strcasecmp(params->main_cache_type, "clock") == 0) { |
| 119 | params->main_cache = Clock_init(ccache_params_local, NULL); |
| 120 | } else if (strcasecmp(params->main_cache_type, "clock2") == 0) { |
| 121 | params->main_cache = Clock_init(ccache_params_local, "n-bit-counter=2"); |
| 122 | } else if (strcasecmp(params->main_cache_type, "clock3") == 0) { |
| 123 | params->main_cache = Clock_init(ccache_params_local, "n-bit-counter=3"); |
| 124 | } else if (strcasecmp(params->main_cache_type, "sieve") == 0) { |
| 125 | params->main_cache = Sieve_init(ccache_params_local, NULL); |
| 126 | } else if (strcasecmp(params->main_cache_type, "LRU") == 0) { |
| 127 | params->main_cache = LRU_init(ccache_params_local, NULL); |
| 128 | } else if (strcasecmp(params->main_cache_type, "ARC") == 0) { |
| 129 | params->main_cache = ARC_init(ccache_params_local, NULL); |
| 130 | } else if (strcasecmp(params->main_cache_type, "LHD") == 0) { |
| 131 | params->main_cache = LHD_init(ccache_params_local, NULL); |
no test coverage detected