Use madvise(..., MADV_FREE) on OS X.

Use madvise(..., MADV_FREE) rather than msync(..., MS_KILLPAGES) on OS
X, since it works for at least OS X 10.5 and 10.6.
This commit is contained in:
Jason Evans 2010-10-24 13:03:07 -07:00
parent 0d38791e7a
commit ce93055c49
3 changed files with 4 additions and 10 deletions

View File

@ -166,7 +166,7 @@ case "${host}" in
*-*-darwin*) *-*-darwin*)
CFLAGS="$CFLAGS -fno-common -no-cpp-precomp" CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
abi="macho" abi="macho"
AC_DEFINE([JEMALLOC_PURGE_MSYNC_KILLPAGES]) AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
RPATH="" RPATH=""
;; ;;
*-*-freebsd*) *-*-freebsd*)

View File

@ -121,15 +121,12 @@
* madvise(..., MADV_DONTNEED) : On Linux, this immediately discards pages, * madvise(..., MADV_DONTNEED) : On Linux, this immediately discards pages,
* such that new pages will be demand-zeroed if * such that new pages will be demand-zeroed if
* the address region is later touched. * the address region is later touched.
* madvise(..., MADV_FREE) : On FreeBSD, this marks pages as being unused, * madvise(..., MADV_FREE) : On FreeBSD and Darwin, this marks pages as being
* such that they will be discarded rather than * unused, such that they will be discarded rather
* swapped out. * than swapped out.
* msync(..., MS_KILLPAGES) : On Darwin, this behaves similarly to
* madvise(..., MADV_FREE) on FreeBSD.
*/ */
#undef JEMALLOC_PURGE_MADVISE_DONTNEED #undef JEMALLOC_PURGE_MADVISE_DONTNEED
#undef JEMALLOC_PURGE_MADVISE_FREE #undef JEMALLOC_PURGE_MADVISE_FREE
#undef JEMALLOC_PURGE_MSYNC_KILLPAGES
/* sizeof(void *) == 2^LG_SIZEOF_PTR. */ /* sizeof(void *) == 2^LG_SIZEOF_PTR. */
#undef LG_SIZEOF_PTR #undef LG_SIZEOF_PTR

View File

@ -800,9 +800,6 @@ arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk)
#elif defined(JEMALLOC_PURGE_MADVISE_FREE) #elif defined(JEMALLOC_PURGE_MADVISE_FREE)
madvise((void *)((uintptr_t)chunk + (pageind << PAGE_SHIFT)), madvise((void *)((uintptr_t)chunk + (pageind << PAGE_SHIFT)),
(npages << PAGE_SHIFT), MADV_FREE); (npages << PAGE_SHIFT), MADV_FREE);
#elif defined(JEMALLOC_PURGE_MSYNC_KILLPAGES)
msync((void *)((uintptr_t)chunk + (pageind << PAGE_SHIFT)),
(npages << PAGE_SHIFT), MS_KILLPAGES);
#else #else
# error "No method defined for purging unused dirty pages." # error "No method defined for purging unused dirty pages."
#endif #endif