@@ -120,21 +120,21 @@ get_fingerprint_rates(Storage *storage, u64 fingerprint)
120
120
121
121
/* Try to remove DB_RECS_TO_FREE_CNT records from DB if it's full */
122
122
while (!(rec = tdb_rec_get_alloc (storage -> tdb , key , & get_alloc_ctx ))) {
123
- struct list_head * pos , * tmp , tail_to_delete ;
123
+ struct list_head * pos , * tmp , head_to_delete ;
124
124
u32 cnt = DB_RECS_TO_FREE_CNT ;
125
125
126
- INIT_LIST_HEAD (& tail_to_delete );
126
+ INIT_LIST_HEAD (& head_to_delete );
127
127
128
128
/* Cut off DB_RECS_TO_FREE_CNT entries from the LRU list */
129
129
spin_lock (& storage -> lru_list_lock );
130
- list_for_each_prev_safe (pos , tmp , & storage -> lru_list ) {
131
- list_move (pos , & tail_to_delete );
130
+ list_for_each_safe (pos , tmp , & storage -> lru_list ) {
131
+ list_move (pos , & head_to_delete );
132
132
if (!-- cnt )
133
133
break ;
134
134
}
135
135
spin_unlock (& storage -> lru_list_lock );
136
136
137
- list_for_each_safe (pos , tmp , & tail_to_delete ) {
137
+ list_for_each_safe (pos , tmp , & head_to_delete ) {
138
138
u64 key = ((TdbRec * )pos - 1 )-> key ;
139
139
/* TODO: remove directly by record bypassing search by key */
140
140
tdb_entry_remove (storage -> tdb , key , NULL , NULL , true);
@@ -150,9 +150,13 @@ get_fingerprint_rates(Storage *storage, u64 fingerprint)
150
150
rates = (Rates * )rec -> data ;
151
151
152
152
spin_lock (& storage -> lru_list_lock );
153
- /* The record still was not added to the LRU list */
154
- if ( list_empty ( & rates -> list_node ))
153
+ if ( list_empty ( & rates -> list_node )) {
154
+ /* Entry is new or was somehow removed from list, add it to tail (MRU) */
155
155
list_add_tail (& rates -> list_node , & storage -> lru_list );
156
+ } else {
157
+ /* Entry already exists and is in the list, move it to tail (MRU) */
158
+ list_move_tail (& rates -> list_node , & storage -> lru_list );
159
+ }
156
160
spin_unlock (& storage -> lru_list_lock );
157
161
158
162
return rates ;
0 commit comments