-
-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual growing arena Out_Of_Memory bug #4834
Comments
I think it's something with how 896 + 64 + 4193371 just barely goes over 4 MB, but only because of the 64 bytes alignment. For some reason it then blows up. |
Actually, this no longer happens in latest version of Odin. It was fixed by this: 98b3a9e |
Actually, now I got this again, with the exact same repro as above. Either I messed something up or it's slightly system-dependent. |
That change only affects resizes. There are no resizes in your repro, so I wouldn't expect that change to have any impact. |
Yeah, I think it only made it slightly more rare in my real-world case. But like you say, in my repro it shouldn't matter. |
It does seem to reproduce consistently for me using the current repro code. |
This fixes it: diff --git a/core/mem/virtual/arena.odin b/core/mem/virtual/arena.odin
index 5191505cf..e2fb36688 100644
--- a/core/mem/virtual/arena.odin
+++ b/core/mem/virtual/arena.odin
@@ -108,6 +108,14 @@ arena_alloc :: proc(arena: ^Arena, size: uint, alignment: uint, loc := #caller_l
switch arena.kind {
case .Growing:
needed := mem.align_forward_uint(size, alignment)
+ if arena.curr_block != nil {
+ ptr := uintptr(arena.curr_block.base[arena.curr_block.used:])
+ mask := uintptr(alignment)-1
+ if ptr & mask != 0 {
+ needed += uint(uintptr(alignment) - (ptr & mask))
+ }
+ }
+
if arena.curr_block == nil || (safe_add(arena.curr_block.used, needed) or_else 0) > arena.curr_block.reserved {
if arena.minimum_block_size == 0 {
arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE That is essentially E: The logic to decide to allocate a new block does not account for aligning the current block forward. |
Thank you @jasonKercher! Would you mind making a PR with that fix? |
I could. That was just proof. Do we think it would be cleaner to expose |
The logic that determines whether we need to allocate more space does not account having to align the end forward for requested alignment.
Context
Current Behavior
Run this program. It crashes with:
C:/Projects/Odin Playground/playground.odin(15:2) runtime assertion: Out_Of_Memory
The text was updated successfully, but these errors were encountered: