mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-04 22:49:32 +03:00
use most performant reset on Linux (MADV_FREE) and Windows (MEM_RESET) as we use the precise decommit by default for purging anyways
This commit is contained in:
parent
7e4e545060
commit
0bb5cecbc2
2 changed files with 7 additions and 5 deletions
|
@ -391,9 +391,11 @@ int _mi_prim_decommit(void* start, size_t size, bool* needs_recommit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int _mi_prim_reset(void* start, size_t size) {
|
int _mi_prim_reset(void* start, size_t size) {
|
||||||
// We always use MADV_DONTNEED if possible even if it may be a bit more expensive as MADV_FREE
|
// We try to use `MADV_FREE` as that is the fastest. A drawback though is that it
|
||||||
// as this guarantees that we see the actual rss reflected in tools like `top`.
|
// will not reduce the `rss` stats in tools like `top` even though the memory is available
|
||||||
#if 0 && defined(MADV_FREE)
|
// to other processes. With the default `MIMALLOC_PURGE_DECOMMITS=1` we ensure that by
|
||||||
|
// default `MADV_DONTNEED` is used though.
|
||||||
|
#if defined(MADV_FREE)
|
||||||
static _Atomic(size_t) advice = MI_ATOMIC_VAR_INIT(MADV_FREE);
|
static _Atomic(size_t) advice = MI_ATOMIC_VAR_INIT(MADV_FREE);
|
||||||
int oadvice = (int)mi_atomic_load_relaxed(&advice);
|
int oadvice = (int)mi_atomic_load_relaxed(&advice);
|
||||||
int err;
|
int err;
|
||||||
|
|
|
@ -285,9 +285,9 @@ int _mi_prim_decommit(void* addr, size_t size, bool* needs_recommit) {
|
||||||
int _mi_prim_reset(void* addr, size_t size) {
|
int _mi_prim_reset(void* addr, size_t size) {
|
||||||
void* p = VirtualAlloc(addr, size, MEM_RESET, PAGE_READWRITE);
|
void* p = VirtualAlloc(addr, size, MEM_RESET, PAGE_READWRITE);
|
||||||
mi_assert_internal(p == addr);
|
mi_assert_internal(p == addr);
|
||||||
#if 1
|
#if 0
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
VirtualUnlock(addr,size); // VirtualUnlock after MEM_RESET removes the memory from the working set
|
VirtualUnlock(addr,size); // VirtualUnlock after MEM_RESET removes the memory directly from the working set
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return (p != NULL ? 0 : (int)GetLastError());
|
return (p != NULL ? 0 : (int)GetLastError());
|
||||||
|
|
Loading…
Add table
Reference in a new issue