Add a pages_purge function to wrap madvise(JEMALLOC_MADV_PURGE) calls

This will be used to implement the feature on mingw, which doesn't have
madvise.
This commit is contained in:
Mike Hommey 2012-04-18 18:29:43 +02:00 committed by Jason Evans
parent e38e45743f
commit 666c5bf7a8
6 changed files with 20 additions and 10 deletions

View File

@ -9,6 +9,8 @@
/******************************************************************************/
#ifdef JEMALLOC_H_EXTERNS
void pages_purge(void *addr, size_t length);
void *chunk_alloc_mmap(size_t size, size_t alignment);
bool chunk_dealloc_mmap(void *chunk, size_t size);

View File

@ -196,6 +196,7 @@
#define opt_xmalloc JEMALLOC_N(opt_xmalloc)
#define opt_zero JEMALLOC_N(opt_zero)
#define p2rz JEMALLOC_N(p2rz)
#define pages_purge JEMALLOC_N(pages_purge)
#define pow2_ceil JEMALLOC_N(pow2_ceil)
#define prof_backtrace JEMALLOC_N(prof_backtrace)
#define prof_boot0 JEMALLOC_N(prof_boot0)

View File

@ -220,13 +220,6 @@
*/
#undef JEMALLOC_PURGE_MADVISE_DONTNEED
#undef JEMALLOC_PURGE_MADVISE_FREE
#ifdef JEMALLOC_PURGE_MADVISE_DONTNEED
# define JEMALLOC_MADV_PURGE MADV_DONTNEED
#elif defined(JEMALLOC_PURGE_MADVISE_FREE)
# define JEMALLOC_MADV_PURGE MADV_FREE
#else
# error "No method defined for purging unused dirty pages."
#endif
/* sizeof(void *) == 2^LG_SIZEOF_PTR. */
#undef LG_SIZEOF_PTR

View File

@ -676,8 +676,8 @@ arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk)
if (config_debug)
ndirty -= npages;
madvise((void *)((uintptr_t)chunk + (pageind << LG_PAGE)),
(npages << LG_PAGE), JEMALLOC_MADV_PURGE);
pages_purge((void *)((uintptr_t)chunk + (pageind << LG_PAGE)),
(npages << LG_PAGE));
if (config_stats)
nmadvise++;
}

View File

@ -171,7 +171,7 @@ chunk_record(void *chunk, size_t size)
{
extent_node_t *xnode, *node, *prev, key;
madvise(chunk, size, JEMALLOC_MADV_PURGE);
pages_purge(chunk, size);
xnode = NULL;
malloc_mutex_lock(&chunks_mtx);

View File

@ -72,6 +72,20 @@ pages_unmap(void *addr, size_t size)
}
}
void
pages_purge(void *addr, size_t length)
{
#ifdef JEMALLOC_PURGE_MADVISE_DONTNEED
# define JEMALLOC_MADV_PURGE MADV_DONTNEED
#elif defined(JEMALLOC_PURGE_MADVISE_FREE)
# define JEMALLOC_MADV_PURGE MADV_FREE
#else
# error "No method defined for purging unused dirty pages."
#endif
madvise(addr, length, JEMALLOC_MADV_PURGE);
}
static void *
chunk_alloc_mmap_slow(size_t size, size_t alignment, bool unaligned)
{