Skip to content

Commit 86a15cc

Browse files
committed
use atomic for huge_pages_available on Windows huge page allocation (issue 1271, issue 32)
1 parent 020b093 commit 86a15cc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/prim/windows/prim.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ static void* _mi_prim_alloc_huge_os_pagesx(void* hint_addr, size_t size, int num
395395

396396
MI_MEM_EXTENDED_PARAMETER params[3] = { {{0,0},{0}},{{0,0},{0}},{{0,0},{0}} };
397397
// on modern Windows try use NtAllocateVirtualMemoryEx for 1GiB huge pages
398-
static bool mi_huge_pages_available = true;
399-
if (pNtAllocateVirtualMemoryEx != NULL && mi_huge_pages_available) {
398+
static _Atomic(size_t) mi_huge_pages_available = ATOMIC_VAR_INIT(1);
399+
if (pNtAllocateVirtualMemoryEx != NULL && mi_atomic_load_acquire(&mi_huge_pages_available) != 0) {
400400
params[0].Type.Type = MiMemExtendedParameterAttributeFlags;
401401
params[0].Arg.ULong64 = MI_MEM_EXTENDED_PARAMETER_NONPAGED_HUGE;
402402
ULONG param_count = 1;
@@ -413,7 +413,7 @@ static void* _mi_prim_alloc_huge_os_pagesx(void* hint_addr, size_t size, int num
413413
}
414414
else {
415415
// fall back to regular large pages
416-
mi_huge_pages_available = false; // don't try further huge pages
416+
mi_atomic_store_release(&mi_huge_pages_available,0); // don't try further huge pages
417417
_mi_warning_message("unable to allocate using huge (1GiB) pages, trying large (2MiB) pages instead (status 0x%lx)\n", err);
418418
}
419419
}

0 commit comments

Comments
 (0)