bug fixes

This commit is contained in:
daanx 2024-12-01 12:54:16 -08:00
parent 8f2a5864b8
commit 1d7a9f62a5
6 changed files with 34 additions and 32 deletions

View file

@ -219,11 +219,12 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit
if (!(alignment >= _mi_os_page_size() && ((alignment & (alignment - 1)) == 0))) return NULL;
size = _mi_align_up(size, _mi_os_page_size());
const bool use_overalloc = (alignment > mi_os_mem_config.alloc_granularity && alignment <= size/8);
// try a direct allocation if the alignment is below the default, or if larger than 1/64 fraction of the size (to avoid waste).
const bool try_direct_alloc = (alignment <= mi_os_mem_config.alloc_granularity || alignment > size/64);
// try first with a requested alignment hint (this will usually be aligned directly on Win 10+ or BSD)
void* p = NULL;
if (!use_overalloc) {
if (try_direct_alloc) {
p = mi_os_prim_alloc(size, alignment, commit, allow_large, is_large, is_zero, stats);
}
@ -234,7 +235,7 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit
else {
// if not aligned, free it, overallocate, and unmap around it
#if !MI_TRACK_ASAN
if (!use_overalloc) {
if (try_direct_alloc) {
_mi_warning_message("unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x%zx bytes, address: %p, alignment: 0x%zx, commit: %d)\n", size, p, alignment, commit);
}
#endif