@@ -49,6 +49,10 @@ typedef struct {
4949 request_t * req_local ;
5050
5151 int64_t s_counter ; // is used for small skip logic
52+
53+ // custom hit ratio recording
54+ int64_t miss_count_after_adjustment ;
55+ int64_t req_count_after_adjustment ;
5256} S4FIFO_params_t ;
5357
5458static const char * DEFAULT_CACHE_PARAMS =
@@ -155,6 +159,13 @@ cache_t *S4FIFO_init(const common_cache_params_t ccache_params,
155159 */
156160static void S4FIFO_free (cache_t * cache ) {
157161 S4FIFO_params_t * params = (S4FIFO_params_t * )cache -> eviction_params ;
162+ // before free, dump the custom hit ratio after adjustment
163+ if (params -> has_adjusted ) {
164+ double hit_ratio_after_adjustment =
165+ 1.0 - (double )params -> miss_count_after_adjustment /
166+ params -> req_count_after_adjustment ;
167+ printf ("S4FIFO: hit ratio after adjustment: %.4lf\n" , hit_ratio_after_adjustment );
168+ }
158169 free_request (params -> req_local );
159170 params -> small_fifo -> cache_free (params -> small_fifo );
160171 if (params -> ghost_fifo != NULL ) {
@@ -190,6 +201,17 @@ static bool S4FIFO_get(cache_t *cache, const request_t *req) {
190201 params -> main_fifo -> get_occupied_byte (params -> main_fifo ) <=
191202 cache -> cache_size );
192203
204+
205+ bool cache_hit = cache_get_base (cache , req );
206+
207+ // custom hit ratio recording
208+ if (params -> has_adjusted ) {
209+ params -> req_count_after_adjustment ++ ;
210+ if (!cache_hit ) {
211+ params -> miss_count_after_adjustment ++ ;
212+ }
213+ }
214+
193215 // Here we update the request count and check if we need to adjust the parameters
194216 if (params -> has_evicted ) params -> request_count ++ ;
195217 if (params -> request_count >= params -> after_n_reqs && !params -> has_adjusted ) {
@@ -204,16 +226,14 @@ static bool S4FIFO_get(cache_t *cache, const request_t *req) {
204226 int64_t ghost_fifo_size =
205227 (int64_t )(cache -> cache_size * params -> ghost_size_ratio );
206228
207- params -> small_fifo -> resize ( params -> small_fifo , small_fifo_size ) ;
229+ params -> small_fifo -> cache_size = small_fifo_size ;
208230 if (params -> ghost_fifo != NULL ) {
209- params -> ghost_fifo -> resize ( params -> ghost_fifo , ghost_fifo_size ) ;
231+ params -> ghost_fifo -> cache_size = ghost_fifo_size ;
210232 }
211- params -> main_fifo -> resize ( params -> main_fifo , main_fifo_size ) ;
233+ params -> main_fifo -> cache_size = main_fifo_size ;
212234 params -> has_adjusted = true;
213235 }
214236
215- bool cache_hit = cache_get_base (cache , req );
216-
217237 return cache_hit ;
218238}
219239
0 commit comments