mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 23:39:31 +03:00
consistent commit order
This commit is contained in:
parent
828613a694
commit
8e0d846b40
1 changed files with 14 additions and 15 deletions
29
src/os.c
29
src/os.c
|
@ -704,8 +704,7 @@ static bool mi_os_commitx(void* addr, size_t size, bool commit, bool conservativ
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (commit) {
|
if (commit) {
|
||||||
// if the memory was already committed, the call succeeds but it is not zero'd
|
// *is_zero = true; // note: if the memory was already committed, the call succeeds but the memory is not zero'd
|
||||||
// *is_zero = true;
|
|
||||||
void* p = VirtualAlloc(start, csize, MEM_COMMIT, PAGE_READWRITE);
|
void* p = VirtualAlloc(start, csize, MEM_COMMIT, PAGE_READWRITE);
|
||||||
err = (p == start ? 0 : GetLastError());
|
err = (p == start ? 0 : GetLastError());
|
||||||
}
|
}
|
||||||
|
@ -717,22 +716,27 @@ static bool mi_os_commitx(void* addr, size_t size, bool commit, bool conservativ
|
||||||
// WebAssembly guests can't control memory protection
|
// WebAssembly guests can't control memory protection
|
||||||
#elif defined(MAP_FIXED) && !defined(__APPLE__)
|
#elif defined(MAP_FIXED) && !defined(__APPLE__)
|
||||||
// Linux
|
// Linux
|
||||||
if (!commit) {
|
if (commit) {
|
||||||
|
// commit: just change the protection
|
||||||
|
err = mprotect(start, csize, (PROT_READ | PROT_WRITE));
|
||||||
|
if (err != 0) { err = errno; }
|
||||||
|
}
|
||||||
|
else {
|
||||||
// decommit: use mmap with MAP_FIXED to discard the existing memory (and reduce rss)
|
// decommit: use mmap with MAP_FIXED to discard the existing memory (and reduce rss)
|
||||||
const int fd = mi_unix_mmap_fd();
|
const int fd = mi_unix_mmap_fd();
|
||||||
void* p = mmap(start, csize, PROT_NONE, (MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE), fd, 0);
|
void* p = mmap(start, csize, PROT_NONE, (MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE), fd, 0);
|
||||||
if (p != start) { err = errno; }
|
if (p != start) { err = errno; }
|
||||||
}
|
}
|
||||||
else {
|
#else
|
||||||
// commit: just change the protection
|
// macOSX and others.
|
||||||
|
if (commit) {
|
||||||
|
// commit: ensure we can access the area
|
||||||
err = mprotect(start, csize, (PROT_READ | PROT_WRITE));
|
err = mprotect(start, csize, (PROT_READ | PROT_WRITE));
|
||||||
if (err != 0) { err = errno; }
|
if (err != 0) { err = errno; }
|
||||||
}
|
}
|
||||||
#else
|
else {
|
||||||
// MacOS and others.
|
|
||||||
if (!commit) {
|
|
||||||
#if defined(MADV_DONTNEED)
|
#if defined(MADV_DONTNEED)
|
||||||
// decommit: use MADV_DONTNEED as it decrease rss immediately (unlike MADV_FREE)
|
// decommit: use MADV_DONTNEED as it decreases rss immediately (unlike MADV_FREE)
|
||||||
err = madvise(start, csize, MADV_DONTNEED);
|
err = madvise(start, csize, MADV_DONTNEED);
|
||||||
#else
|
#else
|
||||||
// decommit: just disable access
|
// decommit: just disable access
|
||||||
|
@ -740,11 +744,6 @@ static bool mi_os_commitx(void* addr, size_t size, bool commit, bool conservativ
|
||||||
if (err != 0) { err = errno; }
|
if (err != 0) { err = errno; }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// commit: ensure we can access the area
|
|
||||||
err = mprotect(start, csize, (PROT_READ | PROT_WRITE));
|
|
||||||
if (err != 0) { err = errno; }
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
_mi_warning_message("%s error: start: %p, csize: 0x%x, err: %i\n", commit ? "commit" : "decommit", start, csize, err);
|
_mi_warning_message("%s error: start: %p, csize: 0x%x, err: %i\n", commit ? "commit" : "decommit", start, csize, err);
|
||||||
|
|
Loading…
Add table
Reference in a new issue