mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 23:19:31 +03:00
fix huge page madvise in case mmap failed
This commit is contained in:
parent
e96614961f
commit
8c9ccea2f5
1 changed files with 23 additions and 22 deletions
9
src/os.c
9
src/os.c
|
@ -510,7 +510,7 @@ static void* mi_unix_mmap(void* addr, size_t size, size_t try_alignment, int pro
|
||||||
#endif
|
#endif
|
||||||
if (large_only) return p;
|
if (large_only) return p;
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
mi_atomic_store_release(&large_page_try_ok, (uintptr_t)10); // on error, don't try again for the next N allocations
|
mi_atomic_store_release(&large_page_try_ok, (uintptr_t)8); // on error, don't try again for the next N allocations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,9 +518,10 @@ static void* mi_unix_mmap(void* addr, size_t size, size_t try_alignment, int pro
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
*is_large = false;
|
*is_large = false;
|
||||||
p = mi_unix_mmapx(addr, size, try_alignment, protect_flags, flags, fd);
|
p = mi_unix_mmapx(addr, size, try_alignment, protect_flags, flags, fd);
|
||||||
|
if (p != NULL) {
|
||||||
#if defined(MADV_HUGEPAGE)
|
#if defined(MADV_HUGEPAGE)
|
||||||
// Many Linux systems don't allow MAP_HUGETLB but they support instead
|
// Many Linux systems don't allow MAP_HUGETLB but they support instead
|
||||||
// transparent huge pages (THP). It is not required to call `madvise` with MADV_HUGE
|
// transparent huge pages (THP). Generally, it is not required to call `madvise` with MADV_HUGE
|
||||||
// though since properly aligned allocations will already use large pages if available
|
// though since properly aligned allocations will already use large pages if available
|
||||||
// in that case -- in particular for our large regions (in `memory.c`).
|
// in that case -- in particular for our large regions (in `memory.c`).
|
||||||
// However, some systems only allow THP if called with explicit `madvise`, so
|
// However, some systems only allow THP if called with explicit `madvise`, so
|
||||||
|
@ -530,8 +531,7 @@ static void* mi_unix_mmap(void* addr, size_t size, size_t try_alignment, int pro
|
||||||
*is_large = true; // possibly
|
*is_large = true; // possibly
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#elif defined(__sun)
|
||||||
#if defined(__sun)
|
|
||||||
if (allow_large && use_large_os_page(size, try_alignment)) {
|
if (allow_large && use_large_os_page(size, try_alignment)) {
|
||||||
struct memcntl_mha cmd = {0};
|
struct memcntl_mha cmd = {0};
|
||||||
cmd.mha_pagesize = large_os_page_size;
|
cmd.mha_pagesize = large_os_page_size;
|
||||||
|
@ -542,6 +542,7 @@ static void* mi_unix_mmap(void* addr, size_t size, size_t try_alignment, int pro
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
_mi_warning_message("unable to allocate OS memory (%zu bytes, error code: %i, address: %p, large only: %d, allow large: %d)\n", size, errno, addr, large_only, allow_large);
|
_mi_warning_message("unable to allocate OS memory (%zu bytes, error code: %i, address: %p, large only: %d, allow large: %d)\n", size, errno, addr, large_only, allow_large);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue