[Git][ghc/ghc][master] 2 commits: rts: Ensure non-moving gc is not running when pausing

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Fri May 12 23:27:42 UTC 2023



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


Commits:
aa84cff4 by Teo Camarasu at 2023-05-12T19:27:23-04:00
rts: Ensure non-moving gc is not running when pausing

- - - - -
5ad776ab by Teo Camarasu at 2023-05-12T19:27:23-04:00
rts: Teach listAllBlocks about nonmoving heap

List all blocks on the non-moving heap.

Resolves #22627

- - - - -


2 changed files:

- rts/RtsAPI.c
- rts/sm/Storage.c


Changes:

=====================================
rts/RtsAPI.c
=====================================
@@ -19,6 +19,7 @@
 #include "StablePtr.h"
 #include "Threads.h"
 #include "Weak.h"
+#include "sm/NonMoving.h"
 
 /* ----------------------------------------------------------------------------
    Building Haskell objects from C datatypes.
@@ -709,6 +710,16 @@ Capability *pauseTokenCapability(PauseToken *pauseToken) {
 // See Note [Locking and Pausing the RTS]
 PauseToken *rts_pause (void)
 {
+
+    // Wait for any nonmoving collection to finish before pausing the RTS.
+    // The nonmoving collector needs to synchronise with the mutator,
+    // so pausing the mutator while a collection is ongoing might lead to deadlock or
+    // capabilities being prematurely re-awoken.
+    if (RtsFlags.GcFlags.useNonmoving) {
+      ACQUIRE_LOCK(&nonmoving_collection_mutex);
+    }
+
+
     // It is an error if this thread already paused the RTS. If another
     // thread has paused the RTS, then rts_pause will block until rts_resume is
     // called (and compete with other threads calling rts_pause). The blocking
@@ -771,6 +782,10 @@ void rts_resume (PauseToken *pauseToken)
     releaseAllCapabilities(getNumCapabilities(), NULL, task);
     exitMyTask();
     stgFree(pauseToken);
+
+    if (RtsFlags.GcFlags.useNonmoving) {
+      RELEASE_LOCK(&nonmoving_collection_mutex);
+    }
 }
 
 // See RtsAPI.h


=====================================
rts/sm/Storage.c
=====================================
@@ -42,7 +42,7 @@
 #include "GC.h"
 #include "Evac.h"
 #include "NonMovingAllocate.h"
-#include "sm/NonMovingMark.h"
+#include "NonMovingMark.h"
 #if defined(ios_HOST_OS) || defined(darwin_HOST_OS)
 #include "Hash.h"
 #endif
@@ -365,11 +365,20 @@ listGenBlocks (ListBlocksCb cb, void *user, generation* gen)
     cb(user, gen->compact_blocks_in_import);
 }
 
+static void
+listSegmentBlocks (ListBlocksCb cb, void *user, struct NonmovingSegment *seg)
+{
+  while (seg) {
+    cb(user, Bdescr((StgPtr) seg));
+    seg = seg->link;
+  }
+}
+
 // Traverse all the different places that the rts stores blocks
 // and call a callback on each of them.
 void listAllBlocks (ListBlocksCb cb, void *user)
 {
-  uint32_t g, i;
+  uint32_t g, i, s;
   for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
       for (i = 0; i < getNumCapabilities(); i++) {
           cb(user, getCapability(i)->mut_lists[g]);
@@ -389,6 +398,24 @@ void listAllBlocks (ListBlocksCb cb, void *user)
       }
       cb(user, getCapability(i)->pinned_object_blocks);
       cb(user, getCapability(i)->pinned_object_empty);
+
+      // list capabilities' current segments
+      if(RtsFlags.GcFlags.useNonmoving) {
+        for (s = 0; s < NONMOVING_ALLOCA_CNT; s++) {
+          listSegmentBlocks(cb, user, getCapability(i)->current_segments[s]);
+        }
+      }
+  }
+
+  // list blocks on the nonmoving heap
+  if(RtsFlags.GcFlags.useNonmoving) {
+    for(s = 0; s < NONMOVING_ALLOCA_CNT; s++) {
+      listSegmentBlocks(cb, user, nonmovingHeap.allocators[s].filled);
+      listSegmentBlocks(cb, user, nonmovingHeap.allocators[s].saved_filled);
+      listSegmentBlocks(cb, user, nonmovingHeap.allocators[s].active);
+    }
+    cb(user, nonmoving_large_objects);
+    cb(user, nonmoving_compact_objects);
   }
 }
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eb60ec18eff7943fb9f22b2d2ad29709b56ce02d...5ad776abbb7c72d65d2ae27de5b2ec48b6e72cde

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eb60ec18eff7943fb9f22b2d2ad29709b56ce02d...5ad776abbb7c72d65d2ae27de5b2ec48b6e72cde
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/20230512/0ed7d48b/attachment-0001.html>


More information about the ghc-commits mailing list