[Git][ghc/ghc][wip/T7275] 2 commits: Storage: Unconditionally enable zeroing of alignment slop

Ben Gamari gitlab at gitlab.haskell.org
Thu Dec 10 14:38:19 UTC 2020



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


Commits:
3d354644 by Ben Gamari at 2020-12-10T09:38:14-05:00
Storage: Unconditionally enable zeroing of alignment slop

This is necessary since the user may enable `+RTS -hT` at any time.

- - - - -
59cbb122 by Ben Gamari at 2020-12-10T09:38:14-05:00
rts: Zero shrunk array slop in vanilla RTS

But only when profiling or DEBUG are enabled.

Fixes #17572 and #9666.

- - - - -


3 changed files:

- includes/Cmm.h
- rts/sm/Storage.c
- utils/deriveConstants/Main.hs


Changes:

=====================================
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 != 0) { foreign "C" overwritingMutableClosureOfs(c "ptr", off); }
 #endif
 
 // Memory barriers.


=====================================
rts/sm/Storage.c
=====================================
@@ -952,10 +952,20 @@ accountAllocation(Capability *cap, W_ n)
  * of closures. This trick is used by the sanity checking code and the heap
  * profiler, see Note [skipping slop in the heap profiler].
  *
- * When profiling we zero:
- *  - Pinned object alignment slop, see MEMSET_IF_PROFILING_W in allocatePinned.
+ * In general we zero:
+ *
+ *  - Pinned object alignment slop, see MEMSET_SLOP_W in allocatePinned.
+ *  - Large object alignment slop, see MEMSET_SLOP_W in allocatePinned.
  *  - 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].
@@ -1126,12 +1136,7 @@ allocateMightFail (Capability *cap, W_ n)
  *
  * See Note [skipping slop in the heap profiler]
  */
-#if defined(PROFILING)
-#define MEMSET_IF_PROFILING_W(p, val, len_w) memset(p, val, (len_w) * sizeof(W_))
-#else
-#define MEMSET_IF_PROFILING_W(p, val, len_w) \
-    do { (void)(p); (void)(val); (void)(len_w); } while(0)
-#endif
+#define MEMSET_SLOP_W(p, val, len_w) memset(p, val, (len_w) * sizeof(W_))
 
 /* ---------------------------------------------------------------------------
    Allocate a fixed/pinned object.
@@ -1184,9 +1189,9 @@ allocatePinned (Capability *cap, W_ n /*words*/, W_ alignment /*bytes*/, W_ alig
         } else {
             Bdescr(p)->flags |= BF_PINNED;
             W_ off_w = ALIGN_WITH_OFF_W(p, alignment, align_off);
-            MEMSET_IF_PROFILING_W(p, 0, off_w);
+            MEMSET_SLOP_W(p, 0, off_w);
             p += off_w;
-            MEMSET_IF_PROFILING_W(p + n, 0, alignment_w - off_w - 1);
+            MEMSET_SLOP_W(p + n, 0, alignment_w - off_w - 1);
             return p;
         }
     }
@@ -1258,7 +1263,7 @@ allocatePinned (Capability *cap, W_ n /*words*/, W_ alignment /*bytes*/, W_ alig
 
     p = bd->free;
 
-    MEMSET_IF_PROFILING_W(p, 0, off_w);
+    MEMSET_SLOP_W(p, 0, off_w);
 
     n += off_w;
     p += off_w;


=====================================
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/aed297394b7d57aaced800e5341bc9a0a5312d26...59cbb1227761934dc97770f6cf84418513077c1e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/aed297394b7d57aaced800e5341bc9a0a5312d26...59cbb1227761934dc97770f6cf84418513077c1e
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/36805019/attachment-0001.html>


More information about the ghc-commits mailing list