mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-07 03:48:42 +03:00
cleanup madv_resuable
This commit is contained in:
parent
cbc14a9287
commit
f37a3db37c
2 changed files with 13 additions and 14 deletions
23
src/os.c
23
src/os.c
|
@ -721,9 +721,9 @@ static bool mi_os_commitx(void* addr, size_t size, bool commit, bool conservativ
|
|||
// for commit, just change the protection
|
||||
err = mprotect(start, csize, (PROT_READ | PROT_WRITE));
|
||||
if (err != 0) { err = errno; }
|
||||
#if defined(MADV_FREE_REUSE)
|
||||
while ((err = madvise(start, csize, MADV_FREE_REUSE)) != 0 && errno == EAGAIN) {}
|
||||
#endif
|
||||
#if defined(MADV_FREE_REUSE)
|
||||
while ((err = madvise(start, csize, MADV_FREE_REUSE)) != 0 && errno == EAGAIN) { errno = 0; }
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
err = mprotect(start, csize, (commit ? (PROT_READ | PROT_WRITE) : PROT_NONE));
|
||||
|
@ -786,17 +786,16 @@ static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats)
|
|||
#else
|
||||
#if defined(MADV_FREE)
|
||||
#if defined(MADV_FREE_REUSABLE)
|
||||
static _Atomic(uintptr_t) advice = ATOMIC_VAR_INIT(MADV_FREE_REUSABLE);
|
||||
#define KK_MADV_FREE_INITIAL MADV_FREE_REUSABLE
|
||||
#else
|
||||
#define KK_MADV_FREE_INITIAL MADV_FREE
|
||||
#endif
|
||||
static _Atomic(uintptr_t) advice = ATOMIC_VAR_INIT(KK_MADV_FREE_INITIAL);
|
||||
int oadvice = (int)mi_atomic_load_relaxed(&advice);
|
||||
int err;
|
||||
while ((err = madvise(start, csize, oadvice)) != 0 && errno == EAGAIN) {}
|
||||
if (err != 0 && errno == EINVAL && advice == MADV_FREE_REUSABLE) {
|
||||
#else
|
||||
static _Atomic(uintptr_t) advice = ATOMIC_VAR_INIT(MADV_FREE);
|
||||
int err = madvise(start, csize, (int)mi_atomic_load_relaxed(&advice));
|
||||
if (err != 0 && errno == EINVAL && advice == MADV_FREE) {
|
||||
#endif
|
||||
// if MADV_FREE is not supported, fall back to MADV_DONTNEED from now on
|
||||
while ((err = madvise(start, csize, oadvice)) != 0 && errno == EAGAIN) { errno = 0; };
|
||||
if (err != 0 && errno == EINVAL && oadvice == KK_MADV_FREE_INITIAL) {
|
||||
// if MADV_FREE/MADV_FREE_REUSABLE is not supported, fall back to MADV_DONTNEED from now on
|
||||
mi_atomic_store_release(&advice, (uintptr_t)MADV_DONTNEED);
|
||||
err = madvise(start, csize, MADV_DONTNEED);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue