Refactor decommit to arena_trim

This commit is contained in:
Nils O. Selåsdal
2026-06-16 23:53:30 +02:00
parent 4a75eddd8f
commit 4b61f589fd
2 changed files with 15 additions and 6 deletions
+13 -6
View File
@@ -128,12 +128,7 @@ void arena_reset_to(Arena *arena, U64 total_offset)
ASAN_POISON_MEMORY_REGION(&block->base[block->first_free], memoryblock_available(block));
if ((arena->flags & ArenaFlag_NoDecommit) == 0) {
U32 aligned_pos = RoundUpToMultiple(block->first_free, arena->commit_size);
if (aligned_pos < block->committed_end) {
ASAN_UNPOISON_MEMORY_REGION(&block->base[aligned_pos], block->committed_end);
memory_decommit(&block->base[aligned_pos], block->committed_end - aligned_pos);
block->committed_end = aligned_pos;
}
arena_trim(arena);
}
break;
@@ -143,6 +138,18 @@ void arena_reset_to(Arena *arena, U64 total_offset)
}
}
void arena_trim(Arena *arena)
{
MemoryBlock *block = arena->current;
U32 aligned_pos = RoundUpToMultiple(block->first_free, arena->commit_size);
if (aligned_pos < block->committed_end) {
void *trim_start = &block->base[aligned_pos];
// Note(nos): Should we unpoision ?
//ASAN_UNPOISON_MEMORY_REGION(trim_start, block->committed_end);
memory_decommit(trim_start, block->committed_end - aligned_pos);
block->committed_end = aligned_pos;
}
}
ATemp arena_temp_begin(Arena *arena)
{
ATemp checkpoint = {};