-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
First, thank you for the incredible work on mimalloc. I recently ported it to a proprietary game engine (20+ years old) for a modern console environment. (Thanks to your support at #1213) Due to the lowest-resourced newgen console😉, the arena and heap management have been vital for our performance.
I am observing a specific behavior regarding the maximum contiguous allocation size allowed within a custom arena.
The Setup:
I am using mi_arena_alloc to reserve a large block of memory, then creating heaps associated with that arena_id to categorize allocations (e.g., Physics, Textures). (X,Y,Z... sized M different arenas)
The Issue:
I've noticed a correlation between the total Arena size and the maximum possible contiguous allocation:
Arena Size < 2 GB: The maximum contiguous allocation (mi_heap_malloc) fails for anything larger than ~64 MB.
Arena Size > 3 GB: I can successfully allocate 1 GB of contiguous memory without issue.
mi_option_set(mi_option_disallow_os_alloc, 1);
size_t sizeArena = 2ull * 1024 * 1024 * 1024;
mi_arena_id_t id;
mi_manage_os_memory_ex(x, sizeArena , true, false, false, -1, false, &id);
auto heap = mi_heap_new_in_arena(id);
void* ptr{ nullptr };
ptr = mi_heap_alloc_new(heap, 512 * 1024 * 1024); //fails for 2gb arena
ptr = mi_heap_alloc_new(heap, 128* 1024 * 1024); //fails for 2gb arena
ptr = mi_heap_alloc_new(heap, 64* 1024 * 1024); //fails for 2gb arenaQuestions:
Is there a specific constant or internal "Region" logic that limits contiguous allocations to the segment size (64 MB) when the total Arena pool is below a certain threshold?
Is there a recommended way to fine-tune the segment/region mapping for custom arenas to allow large contiguous allocations (e.g., for large streaming buffers) without needing to over-reserve the total arena size?
Is this intended behavior, or is it a side effect of how MI_ARENA_REGION_SIZE or similar internal macros interact with the total pool?
Any guidance on where to look in the source to adjust this behavior for restricted-memory environments would be greatly appreciated.
Similar question albeit a bit tangential
#1228