]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Decrease helgrind memory use for applications allocating many blocks
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 1 Dec 2013 19:28:48 +0000 (19:28 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 1 Dec 2013 19:28:48 +0000 (19:28 +0000)
Use a pool allocator for the MallocMeta struct that helgrind maintains
for each client allocated block.

For perf/heap on x86, this decreases the max amount of mmap-ed memory
for the core area from 56Mb to 36Mb.
On amd64, decreases from 104Mb to 62Mb.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13744

helgrind/hg_main.c

index 0e10ed2e712e9ae77b39d2b1eb75126a38d36647..dca958320e0e5aa1094128745564156c9f12f32b 100644 (file)
@@ -54,6 +54,7 @@
 #include "pub_tool_vki.h"       // VKI_PAGE_SIZE
 #include "pub_tool_libcproc.h"  // VG_(atfork)
 #include "pub_tool_aspacemgr.h" // VG_(am_is_valid_for_client)
+#include "pub_tool_poolalloc.h"
 
 #include "hg_basics.h"
 #include "hg_wordset.h"
@@ -3943,14 +3944,17 @@ typedef
    (obviously). */
 static VgHashTable hg_mallocmeta_table = NULL;
 
+/* MallocMeta are small elements. We use a pool to avoid
+   the overhead of malloc for each MallocMeta. */
+static PoolAlloc *MallocMeta_poolalloc = NULL;
 
 static MallocMeta* new_MallocMeta ( void ) {
-   MallocMeta* md = HG_(zalloc)( "hg.new_MallocMeta.1", sizeof(MallocMeta) );
-   tl_assert(md);
+   MallocMeta* md = VG_(allocEltPA) (MallocMeta_poolalloc);
+   VG_(memset)(md, 0, sizeof(MallocMeta));
    return md;
 }
 static void delete_MallocMeta ( MallocMeta* md ) {
-   HG_(free)(md);
+   VG_(freeEltPA)(MallocMeta_poolalloc, md);
 }
 
 
@@ -5359,6 +5363,12 @@ static void hg_pre_clo_init ( void )
    hg_mallocmeta_table
       = VG_(HT_construct)( "hg_malloc_metadata_table" );
 
+   MallocMeta_poolalloc = VG_(newPA) ( sizeof(MallocMeta),
+                                       1000,
+                                       HG_(zalloc),
+                                       "hg_malloc_metadata_pool",
+                                       HG_(free));
+
    // add a callback to clean up on (threaded) fork.
    VG_(atfork)(NULL/*pre*/, NULL/*parent*/, evh__atfork_child/*child*/);
 }