From 9c223a1e4823047fa0143a125baef4e6a10976f5 Mon Sep 17 00:00:00 2001 From: Richard Shin Date: Thu, 29 Sep 2016 23:46:04 -0700 Subject: [PATCH] Increase dlmalloc's granularity to 1 << 25 (#30) * Increase dlmalloc's granularity to 1 << 10 * Prevent trimming in dlmalloc --- src/malloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/malloc.c b/src/malloc.c index f18535437..fbf8c8d92 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -18,6 +18,7 @@ int fake_munmap(void *, size_t); #define DIRECT_MUNMAP(a, s) fake_munmap(a, s) #define USE_DL_PREFIX #define HAVE_MORECORE 0 +#define DEFAULT_GRANULARITY ((size_t) 1U << 25) #include "thirdparty/dlmalloc.c" @@ -27,6 +28,7 @@ int fake_munmap(void *, size_t); #undef DIRECT_MUNMAP #undef USE_DL_PREFIX #undef HAVE_MORECORE +#undef DEFAULT_GRANULARITY struct mmap_record { int fd; @@ -98,7 +100,11 @@ int fake_munmap(void *addr, size_t size) { struct mmap_record *record; HASH_FIND(hh_pointer, records_by_pointer, &addr, sizeof(addr), record); - assert(record != NULL); + if (record == NULL || record->size != size) { + /* Reject requests to munmap that don't directly match previous + * calls to mmap, to prevent dlmalloc from trimming. */ + return -1; + } close(record->fd); HASH_DELETE(hh_fd, records_by_fd, record);