]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
In an attempt to fix the accounting for dynamic memory allocation
authorFlorian Krohm <florian@eich-krohm.de>
Fri, 20 Sep 2013 21:34:40 +0000 (21:34 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Fri, 20 Sep 2013 21:34:40 +0000 (21:34 +0000)
it turned out that coregrind freely allocates memory on the tool
arena (which it should not, conceptually) and tools rely on coregrind
doing so (by VG_(free)'ing memory allocated by coregrind).
Entangling this mess is risky and provides little benefit except
architectural cleanliness.
Thinking more about it... It isn't really all that interesting how
much memory is allocated by tool code in and by itself.  What is
interesting is the total memory impact a tool has, e.g. as compared
to running "none".
So in this patch the number of memory arenas is consolidated by
subsuming VG_AR_TOOL/ERRORS/EXECCTXT into VG_AR_CORE.
VG_(malloc) and friends have been modified to operate on VG_AR_CORE.

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

coregrind/m_clientstate.c
coregrind/m_errormgr.c
coregrind/m_execontext.c
coregrind/m_mallocfree.c
coregrind/pub_core_mallocfree.h

index 5046c3b7c1e8a0c749db07e215be334418738c3d..b7fa34ca63c5a4b4a1d9f20166804cea2ffd18cb 100644 (file)
@@ -69,7 +69,7 @@ Int VG_(cl_cmdline_fd) = -1;
 Int VG_(cl_auxv_fd) = -1;
 
 // Command line pieces, after they have been extracted from argv in
-// m_main.main().  The payload vectors are allocated in VG_AR_TOOL
+// m_main.main().  The payload vectors are allocated in VG_AR_CORE
 // (the default arena).  They are never freed.
 
 /* Args for the client. */
index 35b334f0db95a272f83f6aa781b046143abc3f7e..106bb8cd63d6ddf8ce5d633e9d897dac3b66f825 100644 (file)
@@ -791,7 +791,7 @@ void VG_(maybe_record_error) ( ThreadId tid,
    */
 
    /* copy main part */
-   p = VG_(arena_malloc)(VG_AR_ERRORS, "errormgr.mre.1", sizeof(Error));
+   p = VG_(malloc)("errormgr.mre.1", sizeof(Error));
    *p = err;
 
    /* update 'extra' */
index 2da7e3947fb3aa5df7f2281ded9ffb7314d4cb5d..0b7f958d5e8ba94552c3611b1c1810d98ecd3b09 100644 (file)
@@ -139,8 +139,8 @@ static void init_ExeContext_storage ( void )
 
    ec_htab_size_idx = 0;
    ec_htab_size = ec_primes[ec_htab_size_idx];
-   ec_htab = VG_(arena_malloc)(VG_AR_EXECTXT, "execontext.iEs1",
-                               sizeof(ExeContext*) * ec_htab_size);
+   ec_htab = VG_(malloc)("execontext.iEs1",
+                         sizeof(ExeContext*) * ec_htab_size);
    for (i = 0; i < ec_htab_size; i++)
       ec_htab[i] = NULL;
 
@@ -289,8 +289,8 @@ static void resize_ec_htab ( void )
       return; /* out of primes - can't resize further */
 
    new_size = ec_primes[ec_htab_size_idx + 1];
-   new_ec_htab = VG_(arena_malloc)(VG_AR_EXECTXT, "execontext.reh1",
-                                   sizeof(ExeContext*) * new_size);
+   new_ec_htab = VG_(malloc)("execontext.reh1",
+                             sizeof(ExeContext*) * new_size);
 
    VG_(debugLog)(
       1, "execontext",
@@ -312,7 +312,7 @@ static void resize_ec_htab ( void )
       }
    }
 
-   VG_(arena_free)(VG_AR_EXECTXT, ec_htab);
+   VG_(free)(ec_htab);
    ec_htab      = new_ec_htab;
    ec_htab_size = new_size;
    ec_htab_size_idx++;
@@ -420,10 +420,9 @@ static ExeContext* record_ExeContext_wrk2 ( Addr* ips, UInt n_ips )
    /* Bummer.  We have to allocate a new context record. */
    ec_totstored++;
 
-   new_ec = VG_(arena_perm_malloc)( VG_AR_EXECTXT,
-                                    sizeof(struct _ExeContext) 
-                                    + n_ips * sizeof(Addr),
-                                    vg_alignof(struct _ExeContext));
+   new_ec = VG_(perm_malloc)( sizeof(struct _ExeContext) 
+                              + n_ips * sizeof(Addr),
+                              vg_alignof(struct _ExeContext));
 
    for (i = 0; i < n_ips; i++)
       new_ec->ips[i] = ips[i];
index 8cd324c563c954b04571589d434f7d0effae2654..9ba5855ace66dc880a7e8a5461a58dd8449cffaa 100644 (file)
@@ -684,17 +684,11 @@ void ensure_mm_init ( ArenaId aid )
       // Initialise the non-client arenas
       // Similarly to client arena, big allocations will be unsplittable.
       arena_init ( VG_AR_CORE,      "core",     CORE_REDZONE_DEFAULT_SZB,
-                   1048576, 1048576+1 );
-      arena_init ( VG_AR_TOOL,      "tool",     CORE_REDZONE_DEFAULT_SZB,
                    4194304, 4194304+1 );
       arena_init ( VG_AR_DINFO,     "dinfo",    CORE_REDZONE_DEFAULT_SZB,
                    1048576, 1048576+1 );
       arena_init ( VG_AR_DEMANGLE,  "demangle", CORE_REDZONE_DEFAULT_SZB,
                    65536,   65536+1 );
-      arena_init ( VG_AR_EXECTXT,   "exectxt",  CORE_REDZONE_DEFAULT_SZB,
-                   1048576, 1048576+1 );
-      arena_init ( VG_AR_ERRORS,    "errors",   CORE_REDZONE_DEFAULT_SZB,
-                   65536,   65536+1 );
       arena_init ( VG_AR_TTAUX,     "ttaux",    CORE_REDZONE_DEFAULT_SZB,
                    65536,   65536+1 );
       nonclient_inited = True;
@@ -2307,27 +2301,27 @@ void* VG_(arena_perm_malloc) ( ArenaId aid, SizeT size, Int align  )
 
 void* VG_(malloc) ( const HChar* cc, SizeT nbytes )
 {
-   return VG_(arena_malloc) ( VG_AR_TOOL, cc, nbytes );
+   return VG_(arena_malloc) ( VG_AR_CORE, cc, nbytes );
 }
 
 void  VG_(free) ( void* ptr )
 {
-   VG_(arena_free) ( VG_AR_TOOL, ptr );
+   VG_(arena_free) ( VG_AR_CORE, ptr );
 }
 
 void* VG_(calloc) ( const HChar* cc, SizeT nmemb, SizeT bytes_per_memb )
 {
-   return VG_(arena_calloc) ( VG_AR_TOOL, cc, nmemb, bytes_per_memb );
+   return VG_(arena_calloc) ( VG_AR_CORE, cc, nmemb, bytes_per_memb );
 }
 
 void* VG_(realloc) ( const HChar* cc, void* ptr, SizeT size )
 {
-   return VG_(arena_realloc) ( VG_AR_TOOL, cc, ptr, size );
+   return VG_(arena_realloc) ( VG_AR_CORE, cc, ptr, size );
 }
 
 HChar* VG_(strdup) ( const HChar* cc, const HChar* s )
 {
-   return VG_(arena_strdup) ( VG_AR_TOOL, cc, s ); 
+   return VG_(arena_strdup) ( VG_AR_CORE, cc, s ); 
 }
 
 // Useful for querying user blocks.           
@@ -2338,7 +2332,7 @@ SizeT VG_(malloc_usable_size) ( void* p )
   
 void* VG_(perm_malloc) ( SizeT size, Int align  )
 {
-   return VG_(arena_perm_malloc) ( VG_AR_TOOL, size, align );
+   return VG_(arena_perm_malloc) ( VG_AR_CORE, size, align );
 }
 
 
index bb163a77db12794d76a5534d9483ff44790ed617..4bbc9fffa775b6f821ae10a76c22d8d00eb59972 100644 (file)
 
 /* Allocation arenas.  
 
-      CORE      for the core's general use.
-      TOOL      for the tool to use (and the only one it uses).
+      CORE      for the core's and tools' general use.
       DINFO     for debug info (symbols, line #s, CFI, etc) storage.
       CLIENT    for the client's mallocs/frees, if the tool replaces glibc's
                     malloc() et al -- redzone size is chosen by the tool.
       DEMANGLE  for the C++ demangler.
-      EXECTXT   for storing ExeContexts.
-      ERRORS    for storing CoreErrors.
       TTAUX     for storing TT/TC auxiliary structures (address range
                 equivalence classes).
 
 */
 typedef Int ArenaId;
 
-#define VG_N_ARENAS        8
+#define VG_N_ARENAS        5
 
 #define VG_AR_CORE         0
-#define VG_AR_TOOL         1
-#define VG_AR_DINFO        2
-#define VG_AR_CLIENT       3
-#define VG_AR_DEMANGLE     4
-#define VG_AR_EXECTXT      5
-#define VG_AR_ERRORS       6
-#define VG_AR_TTAUX        7
+#define VG_AR_DINFO        1
+#define VG_AR_CLIENT       2
+#define VG_AR_DEMANGLE     3
+#define VG_AR_TTAUX        4
 
 // This is both the minimum payload size of a malloc'd block, and its
 // minimum alignment.  Must be a power of 2 greater than 4, and should be