correctly compute size_to_zero for new blocks

This commit is contained in:
Nikita Smith
2026-02-13 17:29:48 -08:00
parent d7a87b7765
commit e14d3b7cdb
+16 -10
View File
@@ -101,6 +101,16 @@ arena_push(Arena *arena, U64 size, U64 align, B32 zero)
U64 pos_pre = AlignPow2(current->pos, align);
U64 pos_pst = pos_pre + size;
// TODO: Newly allocated arenas already have zeroed commited pages,
// so this unnecessarily zeroes them again.
//
// rjf: compute the size we need to zero
U64 size_to_zero = 0;
if(zero)
{
size_to_zero = Min(current->cmt, pos_pst) - pos_pre;
}
// rjf: chain, if needed
if(current->res < pos_pst && !(arena->flags & ArenaFlag_NoChain))
{
@@ -141,6 +151,12 @@ arena_push(Arena *arena, U64 size, U64 align, B32 zero)
.flags = current->flags,
.allocation_site_file = current->allocation_site_file,
.allocation_site_line = current->allocation_site_line);
size_to_zero = 0;
}
else
{
size_to_zero = size;
}
new_block->base_pos = current->base_pos + current->res;
@@ -151,13 +167,6 @@ arena_push(Arena *arena, U64 size, U64 align, B32 zero)
pos_pst = pos_pre + size;
}
// rjf: compute the size we need to zero
U64 size_to_zero = 0;
if(zero)
{
size_to_zero = Min(current->cmt, pos_pst) - pos_pre;
}
// rjf: commit new pages, if needed
if(current->cmt < pos_pst)
{
@@ -185,11 +194,8 @@ arena_push(Arena *arena, U64 size, U64 align, B32 zero)
result = (U8 *)current+pos_pre;
current->pos = pos_pst;
AsanUnpoisonMemoryRegion(result, size);
if(size_to_zero != 0)
{
MemoryZero(result, size_to_zero);
}
}
#if PROFILE_TELEMETRY
if(size > KB(1))