@@ -27,6 +27,13 @@ typedef struct LIRS_params {
2727 uint64_t nonresident ;
2828} LIRS_params_t ;
2929
30+ /**
31+ * @brief local request for thread local storage
32+ */
33+ static __thread request_t * req_local_hit_RD_HIRinQ = NULL ;
34+ static __thread request_t * req_local_evictLIR = NULL ;
35+ static __thread request_t * req_local_evictHIR = NULL ;
36+
3037// ***********************************************************************
3138// **** ****
3239// **** function declarations ****
@@ -125,6 +132,20 @@ static void LIRS_free(cache_t *cache) {
125132 params -> LRU_s -> cache_free (params -> LRU_s );
126133 params -> LRU_q -> cache_free (params -> LRU_q );
127134 params -> LRU_nh -> cache_free (params -> LRU_nh );
135+
136+ if (req_local_hit_RD_HIRinQ != NULL ) {
137+ free_request (req_local_hit_RD_HIRinQ );
138+ req_local_hit_RD_HIRinQ = NULL ;
139+ }
140+ if (req_local_evictLIR != NULL ) {
141+ free_request (req_local_evictLIR );
142+ req_local_evictLIR = NULL ;
143+ }
144+ if (req_local_evictHIR != NULL ) {
145+ free_request (req_local_evictHIR );
146+ req_local_evictHIR = NULL ;
147+ }
148+
128149 my_free (sizeof (LIRS_params_t ), params );
129150 cache_struct_free (cache );
130151}
@@ -553,9 +574,10 @@ static cache_obj_t *hit_RD_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s,
553574 LIRS_params_t * params = (LIRS_params_t * )(cache -> eviction_params );
554575
555576 if (cache_obj_q != NULL ) {
556- params -> hirs_count -= cache_obj_q -> obj_size ;
577+ int64_t obj_size = cache_obj_q -> obj_size ;
578+ params -> hirs_count -= obj_size ;
557579 params -> LRU_q -> remove (params -> LRU_q , cache_obj_q -> obj_id );
558- cache -> occupied_byte -= cache_obj_q -> obj_size ;
580+ cache -> occupied_byte -= obj_size ;
559581 cache -> n_obj -- ;
560582 }
561583
@@ -583,19 +605,17 @@ static cache_obj_t *hit_NR_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s) {
583605
584606static cache_obj_t * hit_RD_HIRinQ (cache_t * cache , cache_obj_t * cache_obj_q ) {
585607 LIRS_params_t * params = (LIRS_params_t * )(cache -> eviction_params );
586-
587- static __thread request_t * req_local = NULL ;
588- if (req_local == NULL ) {
589- req_local = new_request ();
608+ if (req_local_hit_RD_HIRinQ == NULL ) {
609+ req_local_hit_RD_HIRinQ = new_request ();
590610 }
591- copy_cache_obj_to_request (req_local , cache_obj_q );
611+ copy_cache_obj_to_request (req_local_hit_RD_HIRinQ , cache_obj_q );
592612
593613 while (params -> lirs_count + cache_obj_q -> obj_size > params -> lirs_limit ) {
594614 evictLIR (cache );
595615 }
596- params -> LRU_s -> insert (params -> LRU_s , req_local );
616+ params -> LRU_s -> insert (params -> LRU_s , req_local_hit_RD_HIRinQ );
597617 cache_obj_t * obj_to_update =
598- params -> LRU_s -> find (params -> LRU_s , req_local , false);
618+ params -> LRU_s -> find (params -> LRU_s , req_local_hit_RD_HIRinQ , false);
599619 obj_to_update -> LIRS .is_LIR = false;
600620 obj_to_update -> LIRS .in_cache = true;
601621
@@ -606,30 +626,30 @@ static void evictLIR(cache_t *cache) {
606626 LIRS_params_t * params = (LIRS_params_t * )(cache -> eviction_params );
607627 cache_obj_t * obj_to_evict = params -> LRU_s -> to_evict (params -> LRU_s , NULL );
608628
609- static __thread request_t * req_local = NULL ;
610- if (req_local == NULL ) {
611- req_local = new_request ();
629+ if (req_local_evictLIR == NULL ) {
630+ req_local_evictLIR = new_request ();
612631 }
613- copy_cache_obj_to_request (req_local , obj_to_evict );
632+ copy_cache_obj_to_request (req_local_evictLIR , obj_to_evict );
614633 params -> lirs_count -= obj_to_evict -> obj_size ;
615634 params -> LRU_s -> evict (params -> LRU_s , NULL );
616635
617- cache -> occupied_byte -= (req_local -> obj_size + cache -> obj_md_size );
636+ cache -> occupied_byte -= (req_local_evictLIR -> obj_size + cache -> obj_md_size );
618637 cache -> n_obj -= 1 ;
619638
620- if ((uint64_t )req_local -> obj_size <= params -> hirs_limit ) {
621- while ((uint64_t )params -> hirs_count + req_local -> obj_size > params -> hirs_limit ) {
639+ if ((uint64_t )req_local_evictLIR -> obj_size <= params -> hirs_limit ) {
640+ while ((uint64_t )params -> hirs_count + req_local_evictLIR -> obj_size >
641+ params -> hirs_limit ) {
622642 evictHIR (cache );
623643 }
624- params -> LRU_q -> insert (params -> LRU_q , req_local );
644+ params -> LRU_q -> insert (params -> LRU_q , req_local_evictLIR );
625645
626646 cache_obj_t * obj_to_update =
627- params -> LRU_q -> find (params -> LRU_q , req_local , false);
647+ params -> LRU_q -> find (params -> LRU_q , req_local_evictLIR , false);
628648 obj_to_update -> LIRS .is_LIR = false;
629649 obj_to_update -> LIRS .in_cache = true;
630650
631- params -> hirs_count += req_local -> obj_size ;
632- cache -> occupied_byte += (req_local -> obj_size + cache -> obj_md_size );
651+ params -> hirs_count += req_local_evictLIR -> obj_size ;
652+ cache -> occupied_byte += (req_local_evictLIR -> obj_size + cache -> obj_md_size );
633653 cache -> n_obj += 1 ;
634654 }
635655
@@ -642,24 +662,23 @@ static bool evictHIR(cache_t *cache) {
642662 cache_obj_t * obj_to_evict = params -> LRU_q -> to_evict (params -> LRU_q , NULL );
643663
644664 // update the corresponding block in S to be non-resident
645- static __thread request_t * req_local = NULL ;
646- if (req_local == NULL ) {
647- req_local = new_request ();
665+ if (req_local_evictHIR == NULL ) {
666+ req_local_evictHIR = new_request ();
648667 }
649- copy_cache_obj_to_request (req_local , obj_to_evict );
668+ copy_cache_obj_to_request (req_local_evictHIR , obj_to_evict );
650669
651670 params -> hirs_count -= obj_to_evict -> obj_size ;
652671 params -> LRU_q -> evict (params -> LRU_q , NULL );
653672
654673 cache_obj_t * obj_to_update =
655- params -> LRU_s -> find (params -> LRU_s , req_local , false);
674+ params -> LRU_s -> find (params -> LRU_s , req_local_evictHIR , false);
656675 if (obj_to_update != NULL ) {
657676 obj_to_update -> LIRS .in_cache = false;
658- params -> LRU_nh -> insert (params -> LRU_nh , req_local );
677+ params -> LRU_nh -> insert (params -> LRU_nh , req_local_evictHIR );
659678 params -> nonresident += obj_to_update -> obj_size ;
660679 }
661680
662- cache -> occupied_byte -= (req_local -> obj_size + cache -> obj_md_size );
681+ cache -> occupied_byte -= (req_local_evictHIR -> obj_size + cache -> obj_md_size );
663682 cache -> n_obj -= 1 ;
664683
665684 return true;
0 commit comments