calcNeeded: add in the large blocks too
[ghc-hetmet.git] / rts / sm / Storage.c
index ecd9b54..0bc15c0 100644 (file)
@@ -956,6 +956,8 @@ countOccupied(bdescr *bd)
     return words;
 }
 
+// Return an accurate count of the live data in the heap, excluding
+// generation 0.
 lnat
 calcLiveWords(void)
 {
@@ -970,9 +972,6 @@ calcLiveWords(void)
     live = 0;
     for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
         for (s = 0; s < generations[g].n_steps; s++) {
-            /* approximate amount of live data (doesn't take into account slop
-             * at end of each block).
-             */
             if (g == 0 && s == 0) continue; 
             stp = &generations[g].steps[s];
             live += countOccupied(stp->blocks) + 
@@ -1004,9 +1003,9 @@ calcNeeded(void)
                generations[g].steps[0].n_large_blocks 
                > generations[g].max_blocks
                && stp->is_compacted == 0) {
-               needed += 2 * stp->n_blocks;
+               needed += 2 * stp->n_blocks + stp->n_large_blocks;
            } else {
-               needed += stp->n_blocks;
+               needed += stp->n_blocks + stp->n_large_blocks;
            }
        }
     }
@@ -1118,6 +1117,21 @@ void freeExec (void *addr)
 
 #ifdef DEBUG
 
+// Useful for finding partially full blocks in gdb
+void findSlop(bdescr *bd);
+void findSlop(bdescr *bd)
+{
+    lnat slop;
+
+    for (; bd != NULL; bd = bd->link) {
+        slop = (bd->blocks * BLOCK_SIZE_W) - (bd->free - bd->start);
+        if (slop > (1024/sizeof(W_))) {
+            debugBelch("block at %p (bdescr %p) has %ldKB slop\n",
+                       bd->start, bd, slop / (1024/sizeof(W_)));
+        }
+    }
+}
+
 nat
 countBlocks(bdescr *bd)
 {