[Git][ghc/ghc][wip/T7275] 2 commits: rts: Zero shrunk array slop in vanilla RTS

Ben Gamari gitlab at gitlab.haskell.org
Thu Dec 10 18:02:32 UTC 2020



Ben Gamari pushed to branch wip/T7275 at Glasgow Haskell Compiler / GHC


Commits:
adb87d30 by Ben Gamari at 2020-12-10T13:02:23-05:00
rts: Zero shrunk array slop in vanilla RTS

But only when profiling or DEBUG are enabled.

Fixes #17572.

- - - - -
73f23069 by Ben Gamari at 2020-12-10T13:02:26-05:00
rts: Enforce that mark-region isn't used with -h

As noted in #9666, the mark-region GC is not compatible with heap
profiling. Also add documentation for this flag.

Closes #9666.

- - - - -


5 changed files:

- docs/users_guide/runtime_control.rst
- includes/Cmm.h
- rts/RtsFlags.c
- rts/sm/Storage.c
- utils/deriveConstants/Main.hs


Changes:

=====================================
docs/users_guide/runtime_control.rst
=====================================
@@ -411,6 +411,17 @@ performance.
     Note that :rts-flag:`--nonmoving-gc` cannot be used with ``-G1``,
     :rts-flag:`profiling <-hc>` nor :rts-flag:`-c`.
 
+.. rts-flag:: -w
+
+    :default: off
+    :since: a long time ago
+    :reverse: none
+
+    Uses a mark-region garbage collection strategy for the oldest-generation heap.
+    Note that this cannot be used in conjunction with heap profiling
+    (:rts-flag:`-hT`) unless linked against the profiling runtime system with
+    :ghc-flag:`-prof`.
+
 .. rts-flag:: -xn
 
     :default: off


=====================================
includes/Cmm.h
=====================================
@@ -630,7 +630,11 @@
 #else
 #define OVERWRITING_CLOSURE_SIZE(c, size) /* nothing */
 #define OVERWRITING_CLOSURE(c) /* nothing */
-#define OVERWRITING_CLOSURE_MUTABLE(c, off) /* nothing */
+/* This is used to zero slop after shrunk arrays. It is important that we do
+ * this whenever profiling is enabled as described in Note [slop on the heap]
+ * in Storage.c. */
+#define OVERWRITING_CLOSURE_MUTABLE(c, off) \
+  if (RtsFlags_ProfFlags_doHeapProfile(RtsFlags) != 0) { foreign "C" overwritingMutableClosureOfs(c "ptr", off); }
 #endif
 
 // Memory barriers.


=====================================
rts/RtsFlags.c
=====================================
@@ -1849,6 +1849,16 @@ static void normaliseRtsOpts (void)
         barf("The non-moving collector doesn't support -G1");
     }
 
+#if !defined(PROFILING) && !defined(DEBUG)
+    // The mark-region collector is incompatible with heap census unless
+    // we zero slop of blackhole'd thunks, which doesn't happen in the
+    // vanilla way. See #9666.
+    if (RtsFlags.ProfFlags.doHeapProfile && RtsFlags.GcFlags.sweep) {
+        barf("The mark-region collector can only be used with profiling\n"
+             "when linked against the profiled RTS.");
+    }
+#endif
+
     if (RtsFlags.ProfFlags.doHeapProfile != NO_HEAP_PROFILING &&
             RtsFlags.GcFlags.useNonmoving) {
         barf("The non-moving collector doesn't support profiling");


=====================================
rts/sm/Storage.c
=====================================
@@ -953,14 +953,19 @@ accountAllocation(Capability *cap, W_ n)
  * profiler, see Note [skipping slop in the heap profiler].
  *
  * In general we zero:
+ *
  *  - Pinned object alignment slop, see MEMSET_SLOP_W in allocatePinned.
  *  - Large object alignment slop, see MEMSET_SLOP_W in allocatePinned.
- * This is necessary even in the vanilla RTS since the user may trigger a heap
- * census via +RTS -hT even when not linking against the profiled RTS.
- *
- * Only when profiling we zero:
  *  - Shrunk array slop, see OVERWRITING_CLOSURE_MUTABLE.
  *
+ * Note that this is necessary even in the vanilla (e.g. non-profiling) RTS
+ * since the user may trigger a heap census via +RTS -hT, which can be used
+ * even when not linking against the profiled RTS. Failing to zero slop
+ * due to array shrinking has resulted in a few nasty bugs (#17572, #9666).
+ * However, since array shrink may result in large amounts of slop (unlike
+ * alignment), we take care to only zero such slop when heap profiling or DEBUG
+ * are enabled.
+ *
  * When performing LDV profiling or using a (single threaded) debug RTS we zero
  * slop even when overwriting immutable closures, see Note [zeroing slop when
  * overwriting closures].


=====================================
utils/deriveConstants/Main.hs
=====================================
@@ -561,6 +561,8 @@ wanteds os = concat
           ,structField  C "StgCompactNFDataBlock" "owner"
           ,structField  C "StgCompactNFDataBlock" "next"
 
+          ,structField_ C "RtsFlags_ProfFlags_doHeapProfile"
+                          "RTS_FLAGS" "ProfFlags.doHeapProfile"
           ,structField_ C "RtsFlags_ProfFlags_showCCSOnException"
                           "RTS_FLAGS" "ProfFlags.showCCSOnException"
           ,structField_ C "RtsFlags_DebugFlags_apply"



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/decf9ef5f770d0fa95cf35608cfdea25c0520091...73f23069b34cea50d237c10125b5814df6b19bff

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/decf9ef5f770d0fa95cf35608cfdea25c0520091...73f23069b34cea50d237c10125b5814df6b19bff
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/20201210/0503fa9b/attachment-0001.html>


More information about the ghc-commits mailing list