[PATCH 04/11] Add a pages_purge function to wrap madvise(JEMALLOC_MADV_PURGE) calls
Mike Hommey
mh+jemalloc at glandium.org
Wed Apr 18 09:29:43 PDT 2012
From: unknown <mh at jigen.(none)>
This will be used to implement the feature on mingw, which doesn't have
madvise.
---
include/jemalloc/internal/chunk_mmap.h | 2 ++
include/jemalloc/jemalloc_defs.h.in | 7 -------
src/arena.c | 4 ++--
src/chunk.c | 2 +-
src/chunk_mmap.c | 13 +++++++++++++
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/include/jemalloc/internal/chunk_mmap.h b/include/jemalloc/internal/chunk_mmap.h
index 04e86af..2d01ac2 100644
--- a/include/jemalloc/internal/chunk_mmap.h
+++ b/include/jemalloc/internal/chunk_mmap.h
@@ -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);
diff --git a/include/jemalloc/jemalloc_defs.h.in b/include/jemalloc/jemalloc_defs.h.in
index 90baa35..6e81655 100644
--- a/include/jemalloc/jemalloc_defs.h.in
+++ b/include/jemalloc/jemalloc_defs.h.in
@@ -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
diff --git a/src/arena.c b/src/arena.c
index 989034d..cbd92e2 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -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++;
}
diff --git a/src/chunk.c b/src/chunk.c
index 67e0d50..bcaedea 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -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);
diff --git a/src/chunk_mmap.c b/src/chunk_mmap.c
index e11cc0e..3ab9095 100644
--- a/src/chunk_mmap.c
+++ b/src/chunk_mmap.c
@@ -72,6 +72,19 @@ 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)
{
--
1.7.10
More information about the jemalloc-discuss
mailing list