eliminate incorrect cases of async_push_work, where pushes which could occur on worker threads may try to write to a cache that is currently being held, when the push occurs (when all threads are saturated) - async_push_work must never be called from within a cache locking mechanism

This commit is contained in:
Ryan Fleury
2024-11-14 09:55:03 -08:00
parent ff45952f07
commit 420f089fda
3 changed files with 24 additions and 12 deletions
+12 -9
View File
@@ -1445,20 +1445,23 @@ ctrl_stored_hash_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B3
//- rjf: not good, or is stale -> submit hash request
if((!is_good || is_stale) && os_now_microseconds() >= last_time_requested_us+100000)
{
if(ctrl_u2ms_enqueue_req(process, range, zero_terminated, endt_us)) OS_MutexScopeW(process_stripe->rw_mutex)
if(ctrl_u2ms_enqueue_req(process, range, zero_terminated, endt_us))
{
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
OS_MutexScopeW(process_stripe->rw_mutex)
{
if(ctrl_handle_match(n->handle, process))
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
{
U64 range_slot_idx = range_hash%n->range_hash_slots_count;
CTRL_ProcessMemoryRangeHashSlot *range_slot = &n->range_hash_slots[range_slot_idx];
for(CTRL_ProcessMemoryRangeHashNode *range_n = range_slot->first; range_n != 0; range_n = range_n->next)
if(ctrl_handle_match(n->handle, process))
{
if(MemoryMatchStruct(&range_n->vaddr_range, &range) && range_n->zero_terminated == zero_terminated)
U64 range_slot_idx = range_hash%n->range_hash_slots_count;
CTRL_ProcessMemoryRangeHashSlot *range_slot = &n->range_hash_slots[range_slot_idx];
for(CTRL_ProcessMemoryRangeHashNode *range_n = range_slot->first; range_n != 0; range_n = range_n->next)
{
range_n->last_time_requested_us = os_now_microseconds();
break;
if(MemoryMatchStruct(&range_n->vaddr_range, &range) && range_n->zero_terminated == zero_terminated)
{
range_n->last_time_requested_us = os_now_microseconds();
break;
}
}
}
}
+8 -2
View File
@@ -493,7 +493,10 @@ di_open(DI_Key *key)
di_u2p_enqueue_key(&key_normalized, max_U64);
ins_atomic_u64_eval_assign(&node->last_time_requested_us, os_now_microseconds());
ins_atomic_u64_inc_eval(&node->request_count);
async_push_work(di_parse_work, .completion_counter = &node->completion_count);
DeferLoop(os_rw_mutex_drop_w(stripe->rw_mutex), os_rw_mutex_take_w(stripe->rw_mutex))
{
async_push_work(di_parse_work, .completion_counter = &node->completion_count);
}
}
}
}
@@ -616,7 +619,10 @@ di_rdi_from_key(DI_Scope *scope, DI_Key *key, U64 endt_us)
{
ins_atomic_u64_eval_assign(&node->last_time_requested_us, os_now_microseconds());
ins_atomic_u64_inc_eval(&node->request_count);
async_push_work(di_parse_work, .completion_counter = &node->completion_count);
DeferLoop(os_rw_mutex_drop_w(stripe->rw_mutex), os_rw_mutex_take_w(stripe->rw_mutex))
{
async_push_work(di_parse_work, .completion_counter = &node->completion_count);
}
}
//- rjf: time expired -> break
+4 -1
View File
@@ -152,7 +152,10 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
{
ins_atomic_u64_eval_assign(&range_node->last_time_requested_us, os_now_microseconds());
ins_atomic_u64_inc_eval(&range_node->request_count);
async_push_work(fs_stream_work, .completion_counter = &range_node->completion_count);
DeferLoop(os_rw_mutex_drop_w(path_stripe->rw_mutex), os_rw_mutex_take_w(path_stripe->rw_mutex))
{
async_push_work(fs_stream_work, .completion_counter = &range_node->completion_count);
}
}
// rjf: try to reobtain results