mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Merge pull request #6398 from Faker-09/virtual_arena_overcommit_bug_5821
Fix for virtual arena overcommit bug #5821
This commit is contained in:
@@ -141,9 +141,9 @@ arena_alloc_unguarded :: proc(arena: ^Arena, size: uint, alignment: uint, loc :=
|
||||
|
||||
needed := mem.align_forward_uint(size, alignment)
|
||||
needed = max(needed, arena.default_commit_size)
|
||||
block_size := max(needed, arena.minimum_block_size)
|
||||
block_size := max(needed, arena.minimum_block_size) + alignment
|
||||
|
||||
new_block := memory_block_alloc(needed, block_size, alignment, {}) or_return
|
||||
new_block := memory_block_alloc(needed, block_size) or_return
|
||||
new_block.prev = arena.curr_block
|
||||
arena.curr_block = new_block
|
||||
arena.total_reserved += new_block.reserved
|
||||
|
||||
@@ -154,7 +154,7 @@ alloc_from_memory_block :: proc(block: ^Memory_Block, min_size, alignment: uint,
|
||||
|
||||
pmblock.committed = platform_total_commit
|
||||
block.committed = pmblock.committed - base_offset
|
||||
|
||||
assert(block.committed <= block.reserved)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -174,7 +174,7 @@ alloc_from_memory_block :: proc(block: ^Memory_Block, min_size, alignment: uint,
|
||||
err = .Out_Of_Memory
|
||||
return
|
||||
}
|
||||
assert(block.committed <= block.reserved)
|
||||
|
||||
do_commit_if_necessary(block, size, default_commit_size) or_return
|
||||
|
||||
data = block.base[block.used+alignment_offset:][:min_size]
|
||||
|
||||
@@ -57,6 +57,33 @@ test_align_bumping_block_limit :: proc(t: ^testing.T) {
|
||||
testing.expect(t, len(data) == 896)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_large_minimum_block_size :: proc(t: ^testing.T) {
|
||||
a: virtual.Arena
|
||||
defer virtual.arena_destroy(&a)
|
||||
|
||||
init_err := virtual.arena_init_growing(&a, 16*mem.Megabyte)
|
||||
testing.expect_value(t, init_err, nil)
|
||||
|
||||
align : uint = 4
|
||||
for _ in 0..<6 {
|
||||
data, err := virtual.arena_alloc(&a, 18874368, align)
|
||||
testing.expect_value(t, err, nil)
|
||||
testing.expect(t, len(data) == 18874368)
|
||||
testing.expect(t, uintptr(raw_data(data)) & uintptr(align-1) == 0)
|
||||
align *= 2
|
||||
virtual.arena_free_all(&a)
|
||||
}
|
||||
|
||||
align = 4
|
||||
for _ in 0..<32 {
|
||||
data, err := virtual.arena_alloc(&a, 1048576, align)
|
||||
testing.expect_value(t, err, nil)
|
||||
testing.expect(t, len(data) == 1048576)
|
||||
testing.expect(t, uintptr(raw_data(data)) & uintptr(align-1) == 0)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
tlsf_test_overlap_and_zero :: proc(t: ^testing.T) {
|
||||
default_allocator := context.allocator
|
||||
|
||||
Reference in New Issue
Block a user