NonMoving: Don't do major GC if one is already running
authorBen Gamari <ben@smart-cactus.org>
Fri, 17 May 2019 23:18:42 +0000 (19:18 -0400)
committerBen Gamari <ben@smart-cactus.org>
Sun, 19 May 2019 18:50:02 +0000 (14:50 -0400)
Previously we would perform a preparatory moving collection, resulting
in many things being added to the mark queue. When we finished with this
we would realize in nonmovingCollect that there was already a collection
running, in which case we would simply not run the nonmoving collector.

However, it was very easy to end up in a "treadmilling" situation: all
subsequent GC following the first failed major GC would be scheduled as
major GCs. Consequently we would continuously feed the concurrent
collector with more mark queue entries and it would never finish.

This patch aborts the major collection far earlier, meaning that we
avoid adding nonmoving objects to the mark queue and allowing the
concurrent collector to finish.

rts/sm/GC.c
rts/sm/NonMoving.h

index 5769133..9ceccc9 100644 (file)
@@ -267,6 +267,14 @@ GarbageCollect (uint32_t collect_gen,
   N = collect_gen;
   major_gc = (N == RtsFlags.GcFlags.generations-1);
 
+#if defined(THREADED_RTS)
+  if (major_gc && RtsFlags.GcFlags.useNonmoving && concurrent_coll_running) {
+      N--;
+      collect_gen--;
+      major_gc = false;
+  }
+#endif
+
   /* N.B. The nonmoving collector works a bit differently. See
    * Note [Static objects under the nonmoving collector].
    */
index a26bc75..cbc8040 100644 (file)
@@ -92,6 +92,9 @@ struct NonmovingHeap {
 extern struct NonmovingHeap nonmovingHeap;
 
 extern uint64_t nonmoving_live_words;
+#if defined(THREADED_RTS)
+extern bool concurrent_coll_running;
+#endif
 
 void nonmovingInit(void);
 void nonmovingExit(void);