@@ -28,10 +28,12 @@ typedef struct {
2828// **** ****
2929// ***********************************************************************
3030
31- static void BeladySize_parse_params (cache_t * cache , const char * cache_specific_params );
31+ static void BeladySize_parse_params (cache_t * cache ,
32+ const char * cache_specific_params );
3233static void BeladySize_free (cache_t * cache );
3334static bool BeladySize_get (cache_t * cache , const request_t * req );
34- static cache_obj_t * BeladySize_find (cache_t * cache , const request_t * req , const bool update_cache );
35+ static cache_obj_t * BeladySize_find (cache_t * cache , const request_t * req ,
36+ const bool update_cache );
3537static cache_obj_t * BeladySize_insert (cache_t * cache , const request_t * req );
3638static cache_obj_t * BeladySize_to_evict (cache_t * cache , const request_t * req );
3739static void BeladySize_evict (cache_t * cache , const request_t * req );
@@ -46,13 +48,16 @@ static void BeladySize_remove_obj(cache_t *cache, cache_obj_t *obj);
4648// ***********************************************************************
4749
4850/**
49- * @brief initialize a Belady cache
51+ * @brief initialize a BeladySize cache
5052 *
5153 * @param ccache_params some common cache parameters
52- * @param cache_specific_params Belady specific parameters, should be NULL
54+ * @param cache_specific_params BeladySize specific parameters, see parse_params
55+ * function or use -e "print" with the cachesim binary
5356 */
54- cache_t * BeladySize_init (const common_cache_params_t ccache_params , const char * cache_specific_params ) {
55- cache_t * cache = cache_struct_init ("BeladySize" , ccache_params , cache_specific_params );
57+ cache_t * BeladySize_init (const common_cache_params_t ccache_params ,
58+ const char * cache_specific_params ) {
59+ cache_t * cache =
60+ cache_struct_init ("BeladySize" , ccache_params , cache_specific_params );
5661
5762 cache -> cache_init = BeladySize_init ;
5863 cache -> cache_free = BeladySize_free ;
@@ -63,7 +68,8 @@ cache_t *BeladySize_init(const common_cache_params_t ccache_params, const char *
6368 cache -> remove = BeladySize_remove ;
6469 cache -> to_evict = BeladySize_to_evict ;
6570
66- BeladySize_params_t * params = (BeladySize_params_t * )malloc (sizeof (BeladySize_params_t ));
71+ BeladySize_params_t * params =
72+ (BeladySize_params_t * )malloc (sizeof (BeladySize_params_t ));
6773 cache -> eviction_params = params ;
6874
6975 BeladySize_parse_params (cache , DEFAULT_PARAMS );
@@ -103,7 +109,9 @@ static void BeladySize_free(cache_t *cache) {
103109 * @param req
104110 * @return true if cache hit, false if cache miss
105111 */
106- static bool BeladySize_get (cache_t * cache , const request_t * req ) { return cache_get_base (cache , req ); }
112+ static bool BeladySize_get (cache_t * cache , const request_t * req ) {
113+ return cache_get_base (cache , req );
114+ }
107115
108116// ***********************************************************************
109117// **** ****
@@ -121,7 +129,8 @@ static bool BeladySize_get(cache_t *cache, const request_t *req) { return cache_
121129 * and if the object is expired, it is removed from the cache
122130 * @return the object or NULL if not found
123131 */
124- static cache_obj_t * BeladySize_find (cache_t * cache , const request_t * req , const bool update_cache ) {
132+ static cache_obj_t * BeladySize_find (cache_t * cache , const request_t * req ,
133+ const bool update_cache ) {
125134 cache_obj_t * obj = cache_find_base (cache , req , update_cache );
126135
127136 if (!update_cache ) {
@@ -167,15 +176,18 @@ struct hash_iter_user_data {
167176 uint64_t max_score ;
168177};
169178
170- static inline void hashtable_iter_Belady_size (cache_obj_t * cache_obj , void * userdata ) {
171- struct hash_iter_user_data * iter_userdata = (struct hash_iter_user_data * )userdata ;
179+ static inline void hashtable_iter_Belady_size (cache_obj_t * cache_obj ,
180+ void * userdata ) {
181+ struct hash_iter_user_data * iter_userdata =
182+ (struct hash_iter_user_data * )userdata ;
172183 if (iter_userdata -> max_score == UINT64_MAX ) return ;
173184
174185 uint64_t obj_score ;
175186 if (cache_obj -> Belady .next_access_vtime == -1 )
176187 obj_score = UINT64_MAX ;
177188 else
178- obj_score = cache_obj -> obj_size * (cache_obj -> Belady .next_access_vtime - iter_userdata -> curr_vtime );
189+ obj_score = cache_obj -> obj_size * (cache_obj -> Belady .next_access_vtime -
190+ iter_userdata -> curr_vtime );
179191
180192 if (obj_score > iter_userdata -> max_score ) {
181193 iter_userdata -> to_evict_obj = cache_obj ;
@@ -199,7 +211,8 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) {
199211 iter_userdata .max_score = 0 ;
200212 iter_userdata .to_evict_obj = NULL ;
201213
202- hashtable_foreach (cache -> hashtable , hashtable_iter_Belady_size , & iter_userdata );
214+ hashtable_foreach (cache -> hashtable , hashtable_iter_Belady_size ,
215+ & iter_userdata );
203216
204217 return iter_userdata .to_evict_obj ;
205218}
@@ -212,7 +225,8 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) {
212225 for (int i = 0 ; i < params -> n_sample ; i ++ ) {
213226 sampled_obj = hashtable_rand_obj (cache -> hashtable );
214227 sampled_obj_score =
215- log ((double )sampled_obj -> obj_size ) + log ((double )(sampled_obj -> Belady .next_access_vtime - cache -> n_req ));
228+ log ((double )sampled_obj -> obj_size ) +
229+ log ((double )(sampled_obj -> Belady .next_access_vtime - cache -> n_req ));
216230 if (obj_to_evict_score < sampled_obj_score ) {
217231 obj_to_evict = sampled_obj ;
218232 obj_to_evict_score = sampled_obj_score ;
@@ -222,10 +236,12 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) {
222236 WARN (
223237 "BeladySize_to_evict: obj_to_evict is NULL, "
224238 "maybe cache size is too small or hash power too large, "
225- "current hash table size %lu, n_obj %lu, cache size %lu, request size %lu, and %d samples "
239+ "current hash table size %lu, n_obj %lu, cache size %lu, request size "
240+ "%lu, and %d samples "
226241 "obj_to_evict_score %.4lf sampled_obj_score %.4lf\n" ,
227- hashsize (cache -> hashtable -> hashpower ), cache -> hashtable -> n_obj , cache -> cache_size , req -> obj_size ,
228- params -> n_sample , obj_to_evict_score , sampled_obj_score );
242+ hashsize (cache -> hashtable -> hashpower ), cache -> hashtable -> n_obj ,
243+ cache -> cache_size , req -> obj_size , params -> n_sample , obj_to_evict_score ,
244+ sampled_obj_score );
229245 return BeladySize_to_evict (cache , req );
230246 }
231247
@@ -277,7 +293,8 @@ static const char *BeladySize_current_params(BeladySize_params_t *params) {
277293 * to see the default parameters, use current_params()
278294 * or use -e "print" with cachesim
279295 */
280- static void BeladySize_parse_params (cache_t * cache , const char * cache_specific_params ) {
296+ static void BeladySize_parse_params (cache_t * cache ,
297+ const char * cache_specific_params ) {
281298 BeladySize_params_t * params = (BeladySize_params_t * )cache -> eviction_params ;
282299 char * params_str = strdup (cache_specific_params );
283300 char * old_params_str = params_str ;
@@ -303,7 +320,8 @@ static void BeladySize_parse_params(cache_t *cache, const char *cache_specific_p
303320 printf ("current parameters: %s\n" , BeladySize_current_params (params ));
304321 exit (0 );
305322 } else {
306- ERROR ("%s does not have parameter %s, support %s\n" , cache -> cache_name , key , BeladySize_current_params (params ));
323+ ERROR ("%s does not have parameter %s, support %s\n" , cache -> cache_name ,
324+ key , BeladySize_current_params (params ));
307325 exit (1 );
308326 }
309327 }
0 commit comments