summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeo Camarasu <teofilcamarasu@gmail.com>2022-07-15 09:47:15 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-07-18 16:38:44 -0400
commit6d8a715e20cf3583f99248383c1b2932d152bf52 (patch)
tree12b0696b69e76b5297055c3a21cbb0476e70ff24
parentd1c25a48154236861a413e058ea38d1b8320273f (diff)
downloadhaskell-6d8a715e20cf3583f99248383c1b2932d152bf52.tar.gz
Allow running memInventory when the concurrent nonmoving gc is enabled
If the nonmoving gc is enabled and we are using a threaded RTS, we now try to grab the collector mutex to avoid memInventory and the collection racing. Before memInventory was disabled.
-rw-r--r--rts/sm/NonMoving.h1
-rw-r--r--rts/sm/Sanity.c18
2 files changed, 14 insertions, 5 deletions
diff --git a/rts/sm/NonMoving.h b/rts/sm/NonMoving.h
index 6eabcb8493..17c0a3bec0 100644
--- a/rts/sm/NonMoving.h
+++ b/rts/sm/NonMoving.h
@@ -104,6 +104,7 @@ extern memcount nonmoving_live_words;
#if defined(THREADED_RTS)
extern bool concurrent_coll_running;
+extern Mutex nonmoving_collection_mutex;
#endif
void nonmovingInit(void);
diff --git a/rts/sm/Sanity.c b/rts/sm/Sanity.c
index 9c2ccc2c41..ba381bfc2c 100644
--- a/rts/sm/Sanity.c
+++ b/rts/sm/Sanity.c
@@ -1190,11 +1190,12 @@ memInventory (bool show)
bool leak;
#if defined(THREADED_RTS)
- // Can't easily do a memory inventory: We might race with the nonmoving
- // collector. In principle we could try to take nonmoving_collection_mutex
- // and do an inventory if we have it but we don't currently implement this.
- if (RtsFlags.GcFlags.useNonmoving)
- return;
+ // We need to be careful not to race with the nonmoving collector.
+ // If a nonmoving collection is on-going we simply abort the inventory.
+ if (RtsFlags.GcFlags.useNonmoving){
+ if(TRY_ACQUIRE_LOCK(&nonmoving_collection_mutex))
+ return;
+ }
#endif
// count the blocks we current have
@@ -1298,6 +1299,13 @@ memInventory (bool show)
}
ASSERT(n_alloc_blocks == live_blocks);
ASSERT(!leak);
+
+#if defined(THREADED_RTS)
+ if (RtsFlags.GcFlags.useNonmoving){
+ RELEASE_LOCK(&nonmoving_collection_mutex);
+ }
+#endif
+
}