<div dir="ltr">sending the patch inline as the mail system does not see to like attachments.<br><br>diff -rupN jemalloc-3.3.1/include/jemalloc/internal/chunk.h jemalloc-3.3.1_changed/include/jemalloc/internal/chunk.h<br>--- jemalloc-3.3.1/include/jemalloc/internal/chunk.h 2013-03-07 01:34:18.000000000 +0530<br>
+++ jemalloc-3.3.1_changed/include/jemalloc/internal/chunk.h 2013-04-26 19:40:12.000000000 +0530<br>@@ -45,8 +45,8 @@ extern size_t arena_maxclass; /* Max si<br><br> void *chunk_alloc(size_t size, size_t alignment, bool base, bool *zero,<br>
dss_prec_t dss_prec);<br>-void chunk_unmap(void *chunk, size_t size);<br>-void chunk_dealloc(void *chunk, size_t size, bool unmap);<br>+void chunk_unmap(void *chunk, size_t size, bool force_unmap);<br>+void chunk_dealloc(void *chunk, size_t size, bool unmap, bool force_unmap);<br>
bool chunk_boot(void);<br> void chunk_prefork(void);<br> void chunk_postfork_parent(void);<br>diff -rupN jemalloc-3.3.1/include/jemalloc/internal/chunk_mmap.h jemalloc-3.3.1_changed/include/jemalloc/internal/chunk_mmap.h<br>
--- jemalloc-3.3.1/include/jemalloc/internal/chunk_mmap.h 2013-03-07 01:34:18.000000000 +0530<br>+++ jemalloc-3.3.1_changed/include/jemalloc/internal/chunk_mmap.h 2013-04-26 19:34:36.000000000 +0530<br>@@ -12,7 +12,7 @@<br>
bool pages_purge(void *addr, size_t length);<br><br> void *chunk_alloc_mmap(size_t size, size_t alignment, bool *zero);<br>-bool chunk_dealloc_mmap(void *chunk, size_t size);<br>+bool chunk_dealloc_mmap(void *chunk, size_t size, bool force_unmap);<br>
<br> #endif /* JEMALLOC_H_EXTERNS */<br> /******************************************************************************/<br> /******************************************************************************/<br>Binary files jemalloc-3.3.1/lib/libjemalloc.so.2 and jemalloc-3.3.1_changed/lib/libjemalloc.so.2 differ<br>
diff -rupN jemalloc-3.3.1/src/arena.c jemalloc-3.3.1_changed/src/arena.c<br>--- jemalloc-3.3.1/src/arena.c 2013-03-07 01:34:18.000000000 +0530<br>+++ jemalloc-3.3.1_changed/src/arena.c 2013-04-26 19:40:33.000000000 +0530<br>
@@ -617,7 +617,7 @@ arena_chunk_dealloc(arena_t *arena, aren<br><br> arena->spare = chunk;<br> malloc_mutex_unlock(&arena->lock);<br>- chunk_dealloc((void *)spare, chunksize, true);<br>
+ chunk_dealloc((void *)spare, chunksize, true, false);<br> malloc_mutex_lock(&arena->lock);<br> if (config_stats)<br> arena->stats.mapped -= chunksize;<br>
diff -rupN jemalloc-3.3.1/src/chunk.c jemalloc-3.3.1_changed/src/chunk.c<br>--- jemalloc-3.3.1/src/chunk.c 2013-03-07 01:34:18.000000000 +0530<br>+++ jemalloc-3.3.1_changed/src/chunk.c 2013-04-26 19:39:33.000000000 +0530<br>
@@ -104,7 +104,7 @@ chunk_recycle(extent_tree_t *chunks_szad<br> malloc_mutex_unlock(&chunks_mtx);<br> node = base_node_alloc();<br> if (node == NULL) {<br>
- chunk_dealloc(ret, size, true);<br>+ chunk_dealloc(ret, size, true, false);<br> return (NULL);<br> }<br>
malloc_mutex_lock(&chunks_mtx);<br>
@@ -181,7 +181,7 @@ label_return:<br> if (ret != NULL) {<br> if (config_ivsalloc && base == false) {<br> if (rtree_set(chunks_rtree, (uintptr_t)ret, ret)) {<br>- chunk_dealloc(ret, size, true);<br>
+ chunk_dealloc(ret, size, true, false);<br> return (NULL);<br> }<br> }<br>@@ -288,7 +288,7 @@ chunk_record(extent_tree_t *chunks_szad,<br>
}<br><br> void<br>-chunk_unmap(void *chunk, size_t size)<br>+chunk_unmap(void *chunk, size_t size, bool force_unmap)<br> {<br> assert(chunk != NULL);<br> assert(CHUNK_ADDR2BASE(chunk) == chunk);<br>@@ -297,12 +297,12 @@ chunk_unmap(void *chunk, size_t size)<br>
<br> if (config_dss && chunk_in_dss(chunk))<br> chunk_record(&chunks_szad_dss, &chunks_ad_dss, chunk, size);<br>- else if (chunk_dealloc_mmap(chunk, size))<br>+ else if (chunk_dealloc_mmap(chunk, size, force_unmap))<br>
chunk_record(&chunks_szad_mmap, &chunks_ad_mmap, chunk, size);<br> }<br><br> void<br>-chunk_dealloc(void *chunk, size_t size, bool unmap)<br>+chunk_dealloc(void *chunk, size_t size, bool unmap, bool force_unmap)<br>
{<br><br> assert(chunk != NULL);<br>@@ -320,7 +320,7 @@ chunk_dealloc(void *chunk, size_t size,<br> }<br><br> if (unmap)<br>- chunk_unmap(chunk, size);<br>+ chunk_unmap(chunk, size, force_unmap);<br>
}<br><br> bool<br>diff -rupN jemalloc-3.3.1/src/chunk_dss.c jemalloc-3.3.1_changed/src/chunk_dss.c<br>--- jemalloc-3.3.1/src/chunk_dss.c 2013-03-07 01:34:18.000000000 +0530<br>+++ jemalloc-3.3.1_changed/src/chunk_dss.c 2013-04-26 19:38:11.000000000 +0530<br>
@@ -123,7 +123,7 @@ chunk_alloc_dss(size_t size, size_t alig<br> dss_max = dss_next;<br> malloc_mutex_unlock(&dss_mtx);<br> if (cpad_size != 0)<br>
- chunk_unmap(cpad, cpad_size);<br>+ chunk_unmap(cpad, cpad_size, false);<br> if (*zero) {<br> VALGRIND_MAKE_MEM_UNDEFINED(ret, size);<br>
memset(ret, 0, size);<br>diff -rupN jemalloc-3.3.1/src/chunk_mmap.c jemalloc-3.3.1_changed/src/chunk_mmap.c<br>--- jemalloc-3.3.1/src/chunk_mmap.c 2013-03-07 01:34:18.000000000 +0530<br>
+++ jemalloc-3.3.1_changed/src/chunk_mmap.c 2013-04-26 19:48:15.000000000 +0530<br>@@ -200,11 +200,10 @@ chunk_alloc_mmap(size_t size, size_t ali<br> }<br><br> bool<br>-chunk_dealloc_mmap(void *chunk, size_t size)<br>
+chunk_dealloc_mmap(void *chunk, size_t size, bool force_unmap)<br> {<br>-<br>- if (config_munmap)<br>+ if (config_munmap || force_unmap)<br> pages_unmap(chunk, size);<br><br>- return (config_munmap == false);<br>
+ return (config_munmap == false) && (force_unmap == false);<br> }<br>diff -rupN jemalloc-3.3.1/src/huge.c jemalloc-3.3.1_changed/src/huge.c<br>--- jemalloc-3.3.1/src/huge.c 2013-03-07 01:34:18.000000000 +0530<br>
+++ jemalloc-3.3.1_changed/src/huge.c 2013-04-26 19:49:39.000000000 +0530<br>@@ -175,7 +175,7 @@ huge_ralloc(void *ptr, size_t oldsize, s<br> if (opt_abort)<br> abort();<br>
memcpy(ret, ptr, copysize);<br>- chunk_dealloc_mmap(ptr, oldsize);<br>+ chunk_dealloc_mmap(ptr, oldsize, true);<br> }<br> } else<br>
#endif<br>@@ -211,7 +211,7 @@ huge_dalloc(void *ptr, bool unmap)<br> if (unmap && config_fill && config_dss && opt_junk)<br> memset(node->addr, 0x5a, node->size);<br><br>
- chunk_dealloc(node->addr, node->size, unmap);<br>+ chunk_dealloc(node->addr, node->size, unmap, unmap);<br><br> base_node_dealloc(node);<br> }<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Apr 29, 2013 at 9:33 AM, Abhishek Singh <span dir="ltr"><<a href="mailto:abhishek@abhishek-singh.com" target="_blank">abhishek@abhishek-singh.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>Hi <br><br></div>We are trying to replace glibc malloc with jemalloc because we have several concurrent allocations and in all our benchmarks jemalloc is consistently better than glibc malloc and many others. <br>
<br>Our setups start typically with 96 GB of RAM and up. We have observed that using jemalloc the virtual memory usage of our process rises up to around 75GB. While the resident memory stays low and it is not a problem as such, when we try to fork a process from within here, it fails as the kernel assumes there is not enough memory to copy the VM space. Perhaps a vfork would be better but we can't use that for now.<br>
<br>So we have made some modifications to jemalloc so that all huge memory allocations are forced to unmap their memory on freeing up. Non huge memory allocations and freeing up remain the same. This seems to help us. I have attached the patch here which is against jemalloc-3.3.1. Please review and suggest if there is a better way to handle this.<span class="HOEnZb"><font color="#888888"><br>
<br>-- <br>Regards<br>Abhishek
</font></span></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Regards<br>Abhishek Kumar Singh
</div>