eliminate attempts at clever read-only synchronization in file stream & ctrl layer, just fall back to simple locking mechanism

This commit is contained in:
Ryan Fleury
2024-11-10 11:25:55 -08:00
parent bd4f82c8e8
commit 31f25d0fe7
4 changed files with 18 additions and 25 deletions
+12 -16
View File
@@ -47,8 +47,7 @@ fs_init(void)
{
fs_shared->stripes[idx].arena = arena_alloc();
fs_shared->stripes[idx].cv = os_condition_variable_alloc();
fs_shared->stripes[idx].r_mutex = os_rw_mutex_alloc();
fs_shared->stripes[idx].w_mutex = os_rw_mutex_alloc();
fs_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
}
fs_shared->u2s_ring_size = KB(64);
fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size);
@@ -107,7 +106,7 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
FS_Stripe *path_stripe = &fs_shared->stripes[path_stripe_idx];
// rjf: loop: request, check for results, return until we can't
OS_MutexScopeR(path_stripe->r_mutex) for(;;)
OS_MutexScopeW(path_stripe->rw_mutex) for(;;)
{
// rjf: path -> node
FS_Node *node = 0;
@@ -121,7 +120,7 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
}
// rjf: node does not exist? -> create & store
if(node == 0) OS_MutexScopeW(path_stripe->w_mutex) OS_MutexScopeRWPromote(path_stripe->r_mutex)
if(node == 0)
{
node = push_array(path_stripe->arena, FS_Node, 1);
SLLQueuePush(path_slot->first, path_slot->last, node);
@@ -145,14 +144,11 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
}
// rjf: range node does not exist? create & store
if(range_node == 0) OS_MutexScopeW(path_stripe->w_mutex) OS_MutexScopeRWPromote(path_stripe->r_mutex)
if(range_node == 0)
{
if(range_node == 0)
{
range_node = push_array(path_stripe->arena, FS_RangeNode, 1);
SLLQueuePush(range_slot->first, range_slot->last, range_node);
range_node->range = range;
}
range_node = push_array(path_stripe->arena, FS_RangeNode, 1);
SLLQueuePush(range_slot->first, range_slot->last, range_node);
range_node->range = range;
}
// rjf: try to send stream request
@@ -169,7 +165,7 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
// rjf: have time to wait? -> wait on this stripe; otherwise exit
if(u128_match(result, u128_zero()) && os_now_microseconds() <= endt_us)
{
os_condition_variable_wait_rw_r(path_stripe->cv, path_stripe->r_mutex, endt_us);
os_condition_variable_wait_rw_w(path_stripe->cv, path_stripe->rw_mutex, endt_us);
}
else
{
@@ -205,7 +201,7 @@ fs_timestamp_from_path(String8 path)
U64 stripe_idx = slot_idx%fs_shared->stripes_count;
FS_Slot *slot = &fs_shared->slots[slot_idx];
FS_Stripe *stripe = &fs_shared->stripes[stripe_idx];
OS_MutexScopeR(stripe->r_mutex)
OS_MutexScopeR(stripe->rw_mutex)
{
for(FS_Node *n = slot->first; n != 0; n = n->next)
{
@@ -231,7 +227,7 @@ fs_size_from_path(String8 path)
U64 stripe_idx = slot_idx%fs_shared->stripes_count;
FS_Slot *slot = &fs_shared->slots[slot_idx];
FS_Stripe *stripe = &fs_shared->stripes[stripe_idx];
OS_MutexScopeR(stripe->r_mutex)
OS_MutexScopeR(stripe->rw_mutex)
{
for(FS_Node *n = slot->first; n != 0; n = n->next)
{
@@ -357,7 +353,7 @@ ASYNC_WORK_DEF(fs_stream_work)
}
//- rjf: commit info to cache
ProfScope("commit to cache") OS_MutexScopeW(path_stripe->r_mutex) OS_MutexScopeW(path_stripe->w_mutex)
ProfScope("commit to cache") OS_MutexScopeW(path_stripe->rw_mutex)
{
FS_Node *node = 0;
for(FS_Node *n = path_slot->first; n != 0; n = n->next)
@@ -414,7 +410,7 @@ fs_detector_thread__entry_point(void *p)
for(U64 stripe_idx = 0; stripe_idx < fs_shared->stripes_count; stripe_idx += 1)
{
FS_Stripe *stripe = &fs_shared->stripes[stripe_idx];
OS_MutexScopeR(stripe->r_mutex) for(U64 slot_in_stripe_idx = 0; slot_in_stripe_idx < slots_per_stripe; slot_in_stripe_idx += 1)
OS_MutexScopeR(stripe->rw_mutex) for(U64 slot_in_stripe_idx = 0; slot_in_stripe_idx < slots_per_stripe; slot_in_stripe_idx += 1)
{
U64 slot_idx = stripe_idx*slots_per_stripe + slot_in_stripe_idx;
FS_Slot *slot = &fs_shared->slots[slot_idx];
+1 -2
View File
@@ -50,8 +50,7 @@ struct FS_Stripe
{
Arena *arena;
OS_Handle cv;
OS_Handle r_mutex;
OS_Handle w_mutex;
OS_Handle rw_mutex;
};
////////////////////////////////