Fix pages_purge_forced() to discard pages on non-Linux systems.

madvise(..., MADV_DONTNEED) only causes demand-zeroing on Linux, so fall
back to overlaying a new mapping.
This commit is contained in:
Jason Evans
2017-03-09 18:20:02 -08:00
parent 21a68e2d22
commit 7cbcd2e2b7
4 changed files with 21 additions and 5 deletions

View File

@@ -170,6 +170,9 @@ pages_purge_lazy(void *addr, size_t size) {
VirtualAlloc(addr, size, MEM_RESET, PAGE_READWRITE);
#elif defined(JEMALLOC_PURGE_MADVISE_FREE)
madvise(addr, size, MADV_FREE);
#elif defined(JEMALLOC_PURGE_MADVISE_DONTNEED) && \
!defined(JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS)
madvise(addr, size, MADV_DONTNEED);
#else
not_reached();
#endif
@@ -182,8 +185,12 @@ pages_purge_forced(void *addr, size_t size) {
return true;
}
#if defined(JEMALLOC_PURGE_MADVISE_DONTNEED)
#if defined(JEMALLOC_PURGE_MADVISE_DONTNEED) && \
defined(JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS)
return (madvise(addr, size, MADV_DONTNEED) != 0);
#elif defined(JEMALLOC_MAPS_COALESCE)
/* Try to overlay a new demand-zeroed mapping. */
return pages_commit(addr, size);
#else
not_reached();
#endif