[Git][ghc/ghc][master] 2 commits: rts/ProfHeap: Only allocate the Censuses that we need

Marge Bot gitlab at gitlab.haskell.org
Fri Jul 3 06:49:34 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00
rts/ProfHeap: Only allocate the Censuses that we need

When not LDV profiling there is no reason to allocate 32 Censuses; one
will do. This is a very small memory footprint optimisation, but it
comes for free.

- - - - -
b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00
rts/ProfHeap: Free old allocations when reinitialising Censuses

Previously when not LDV profiling we would repeatedly reinitialise
`censuses[0]` with `initEra`. This failed to free the `Arena` and
`HashTable` from the old census, resulting in a memory leak.

Fixes #18348.

- - - - -


1 changed file:

- rts/ProfHeap.c


Changes:

=====================================
rts/ProfHeap.c
=====================================
@@ -347,6 +347,16 @@ LDV_recordDead( const StgClosure *c, uint32_t size )
 STATIC_INLINE void
 initEra(Census *census)
 {
+    // N.B. When not LDV profiling we reinitialise the same Census over
+    // and over again. Consequently, we need to ensure that we free the
+    // resources from the previous census.
+    if (census->hash) {
+        freeHashTable(census->hash, NULL);
+    }
+    if (census->arena) {
+        arenaFree(census->arena);
+    }
+
     census->hash  = allocHashTable();
     census->ctrs  = NULL;
     census->arena = newArena();
@@ -498,18 +508,24 @@ initHeapProfiling(void)
 #if defined(PROFILING)
     if (doingLDVProfiling()) {
         era = 1;
+        n_censuses = 32;
     } else
 #endif
     {
         era = 0;
+        n_censuses = 1;
     }
 
     // max_era = 2^LDV_SHIFT
     max_era = 1 << LDV_SHIFT;
 
-    n_censuses = 32;
     censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
 
+    // Ensure that arena and hash are NULL since otherwise initEra will attempt to free them.
+    for (unsigned int i=0; i < n_censuses; i++) {
+        censuses[i].arena = NULL;
+        censuses[i].hash = NULL;
+    }
     initEra( &censuses[era] );
 
     /* initProfilingLogFile(); */



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f08d6316d3d19b627550d99b4364e9bf0b45c329...b835112cbeaa6e34a8bae7b7697bdf2826edaa9a

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f08d6316d3d19b627550d99b4364e9bf0b45c329...b835112cbeaa6e34a8bae7b7697bdf2826edaa9a
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200703/5fb6675b/attachment-0001.html>


More information about the ghc-commits mailing list