extend ctrl process memory cache reads with freshness info - it is a bit too coarse grained at page granularity, that should've been easy to predict... in any case, to start addressing that, start keeping >1 hash key hash history in hash store layer, such that history may be preserved for a bit longer & diff'd with new key hashes

This commit is contained in:
Ryan Fleury
2024-01-25 09:06:03 -08:00
parent 76b2facbf4
commit d0c3d9dc21
8 changed files with 93 additions and 39 deletions
+13 -9
View File
@@ -122,7 +122,7 @@ hs_submit_data(U128 key, Arena **data_arena, String8 data)
}
//- rjf: commit this hash to key cache
U128 key_old_hash = {0};
U128 key_expired_hash = {0};
OS_MutexScopeW(key_stripe->rw_mutex)
{
HS_KeyNode *key_node = 0;
@@ -142,15 +142,19 @@ hs_submit_data(U128 key, Arena **data_arena, String8 data)
}
if(key_node)
{
key_old_hash = key_node->hash;
key_node->hash = hash;
if(key_node->hash_history_gen+1 >= ArrayCount(key_node->hash_history))
{
key_expired_hash = key_node->hash_history[(key_node->hash_history_gen-1)%ArrayCount(key_node->hash_history)];
}
key_node->hash_history[key_node->hash_history_gen%ArrayCount(key_node->hash_history)] = hash;
key_node->hash_history_gen += 1;
}
}
//- rjf: if this key was correllated with an old hash, dec key ref count of old hash
if(!u128_match(key_old_hash, u128_zero()))
//- rjf: if this key's history cache was full, dec key ref count of oldest hash
if(!u128_match(key_expired_hash, u128_zero()))
{
U64 old_hash_slot_idx = key_old_hash.u64[1]%hs_shared->slots_count;
U64 old_hash_slot_idx = key_expired_hash.u64[1]%hs_shared->slots_count;
U64 old_hash_stripe_idx = old_hash_slot_idx%hs_shared->stripes_count;
HS_Slot *old_hash_slot = &hs_shared->slots[old_hash_slot_idx];
HS_Stripe *old_hash_stripe = &hs_shared->stripes[old_hash_stripe_idx];
@@ -158,7 +162,7 @@ hs_submit_data(U128 key, Arena **data_arena, String8 data)
{
for(HS_Node *n = old_hash_slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, key_old_hash))
if(u128_match(n->hash, key_expired_hash))
{
ins_atomic_u64_dec_eval(&n->key_ref_count);
break;
@@ -250,9 +254,9 @@ hs_hash_from_key(U128 key)
{
for(HS_KeyNode *n = key_slot->first; n != 0; n = n->next)
{
if(u128_match(n->key, key))
if(u128_match(n->key, key) && n->hash_history_gen > 0)
{
result = n->hash;
result = n->hash_history[(n->hash_history_gen-1)%ArrayCount(n->hash_history)];
break;
}
}
+2 -1
View File
@@ -12,7 +12,8 @@ struct HS_KeyNode
{
HS_KeyNode *next;
U128 key;
U128 hash;
U128 hash_history[2];
U64 hash_history_gen;
};
typedef struct HS_KeySlot HS_KeySlot;