From 30e600699df9c2a01285987647dd358a5bb2d6ec Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:31:00 -0500 Subject: [PATCH] Strengthen order to prevent reordering --- base/runtime/heap_allocator_implementation.odin | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/base/runtime/heap_allocator_implementation.odin b/base/runtime/heap_allocator_implementation.odin index be3a4097f..3faacbe31 100644 --- a/base/runtime/heap_allocator_implementation.odin +++ b/base/runtime/heap_allocator_implementation.odin @@ -1438,8 +1438,11 @@ heap_alloc :: proc "contextless" (size: int, zero: bool = true) -> (ptr: rawptr) } if should_remove { + // NOTE: The order of operations here is important to keep + // the cache from overflowing. The entry must first be + // removed, then the superpage has its flag cleared. intrinsics.atomic_store_explicit(&cache.superpages_with_remote_frees[i], nil, .Release) - intrinsics.atomic_store_explicit(&superpage.remote_free_set, false, .Release) + intrinsics.atomic_store_explicit(&superpage.remote_free_set, false, .Seq_Cst) removed += 1 }