From 5a0725ce9448946a517628ab2d4631d49b39c40d Mon Sep 17 00:00:00 2001 From: Ujval Misra Date: Mon, 3 Oct 2016 18:35:13 -0700 Subject: [PATCH] Increase dlmalloc threshold along with granularity (#33) * Increase allocation granularity dynamically with each MMAP call * Fewer MMAP calls required when workload contains several objects. * Delay hitting the per-process file descriptor constraint. * Change type of GRANULARITY_MULTIPLIER * Make granularity update more concise. * Increase dlmalloc threshold along with granularity * Eventually resolve issue of objects being allocated their own file if larger than dlmalloc threshold * Avoid dlmalloc threshold and granularity integer overflow * Update granularity directly without invoking dlmallopt * Set the threshold to a fixed size (MAX_SIZE_T) * Removed trailing whitespace --- src/malloc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/malloc.c b/src/malloc.c index 230fee38d..7dfd186ce 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -13,15 +13,14 @@ void *fake_mmap(size_t); int fake_munmap(void *, size_t); -size_t dlmalloc_granularity = ((size_t) 128U * 1024U); - #define MMAP(s) fake_mmap(s) #define MUNMAP(a, s) fake_munmap(a, s) #define DIRECT_MMAP(s) fake_mmap(s) #define DIRECT_MUNMAP(a, s) fake_munmap(a, s) #define USE_DL_PREFIX #define HAVE_MORECORE 0 -#define DEFAULT_GRANULARITY (dlmalloc_granularity) +#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T +#define DEFAULT_GRANULARITY ((size_t) 128U * 1024U) #include "thirdparty/dlmalloc.c" @@ -84,9 +83,8 @@ void *fake_mmap(size_t size) { return pointer; } - /* Update dlmalloc's allocation granularity for future calls */ - dlmalloc_granularity *= GRANULARITY_MULTIPLIER; - dlmallopt(M_GRANULARITY, dlmalloc_granularity); + /* Increase dlmalloc's allocation granularity directly. */ + mparams.granularity *= GRANULARITY_MULTIPLIER; struct mmap_record *record = malloc(sizeof(struct mmap_record)); record->fd = fd;