From: Philippe Waroquiers Date: Sun, 1 Dec 2013 19:28:48 +0000 (+0000) Subject: Decrease helgrind memory use for applications allocating many blocks X-Git-Tag: svn/VALGRIND_3_10_0~692 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=deafe374caacd023adf66bcab6d66b56863b5348;p=thirdparty%2Fvalgrind.git Decrease helgrind memory use for applications allocating many blocks 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 --- diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index 0e10ed2e71..dca958320e 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -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*/); }