[Git][ghc/ghc][wip/gc/ben] 3 commits: NonMoving: Accumulate live words during mark

Ben Gamari gitlab at gitlab.haskell.org
Tue Apr 16 13:40:44 UTC 2019



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


Commits:
64431c63 by Ben Gamari at 2019-04-16T13:40:38Z
NonMoving: Accumulate live words during mark

- - - - -
a4549e9a by Ben Gamari at 2019-04-16T13:40:38Z
Sanity: Don't double-count nonmoving_blocks

The blocks counted by nonmoving_blocks are already counted via
gen_blocks.

- - - - -
5f773235 by Ben Gamari at 2019-04-16T13:40:38Z
XXX

- - - - -


5 changed files:

- rts/sm/GC.c
- rts/sm/NonMoving.c
- rts/sm/NonMoving.h
- rts/sm/NonMovingMark.c
- rts/sm/Sanity.c


Changes:

=====================================
rts/sm/GC.c
=====================================
@@ -1713,7 +1713,7 @@ resize_generations (void)
 {
     uint32_t g;
 
-    if (major_gc && RtsFlags.GcFlags.generations > 1) {
+    if (major_gc && RtsFlags.GcFlags.generations > 1 && ! RtsFlags.GcFlags.useNonmoving) {
         W_ live, size, min_alloc, words;
         const W_ max  = RtsFlags.GcFlags.maxHeapSize;
         const W_ gens = RtsFlags.GcFlags.generations;


=====================================
rts/sm/NonMoving.c
=====================================
@@ -75,6 +75,8 @@ Mutex concurrent_coll_finished_lock;
  *
  */
 
+W_ nonmoving_live_words = 0;
+
 #if defined(THREADED_RTS)
 static void* nonmovingConcurrentMark(void *mark_queue);
 #endif
@@ -440,6 +442,7 @@ static void nonmovingPrepareMark(void)
     oldest_gen->large_objects = NULL;
     oldest_gen->n_large_words = 0;
     oldest_gen->n_large_blocks = 0;
+    nonmoving_live_words = 0;
 
 #if defined(DEBUG)
     debug_caf_list_snapshot = debug_caf_list;
@@ -604,8 +607,22 @@ static void appendWeakList( StgWeak **w1, StgWeak *w2 )
 }
 #endif
 
+static void set_target_size(int mul)
+{
+    W_ live = (nonmoving_live_words + BLOCK_SIZE_W - 1) / BLOCK_SIZE_W +
+        oldest_gen->n_large_blocks +
+        oldest_gen->n_compact_blocks;
+    W_ size = stg_max(live * RtsFlags.GcFlags.oldGenFactor,
+                      RtsFlags.GcFlags.minOldGenSize);
+    size *= mul;
+    for (unsigned int g = 0; g < RtsFlags.GcFlags.generations; g++) {
+        generations[g].max_blocks = size;
+    }
+}
+
 static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO **resurrected_threads)
 {
+    set_target_size(4);
     ACQUIRE_LOCK(&nonmoving_collection_mutex);
     debugTrace(DEBUG_nonmoving_gc, "Starting mark...");
 
@@ -754,15 +771,9 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO *
                oldest_gen->n_blocks, oldest_gen->n_large_blocks, oldest_gen->n_compact_blocks);
     debugBelch("nonmoving: max_blocks: %lu -> %lu\n", oldest_gen->max_blocks, oldest_gen->n_blocks);
 #endif
-    W_ live = oldest_gen->n_blocks +
-        oldest_gen->n_large_blocks +
-        oldest_gen->n_compact_blocks;
-    W_ size = stg_max(live * RtsFlags.GcFlags.oldGenFactor,
-                      RtsFlags.GcFlags.minOldGenSize);
-    //size /= 4;
-    for (unsigned int g = 0; g < RtsFlags.GcFlags.generations; g++) {
-        generations[g].max_blocks = size;
-    }
+    oldest_gen->n_words = nonmoving_live_words;
+    oldest_gen->n_old_blocks = 0;
+    set_target_size(1);
 
 #if defined(THREADED_RTS)
 finish:


=====================================
rts/sm/NonMoving.h
=====================================
@@ -91,6 +91,8 @@ struct NonmovingHeap {
 
 extern struct NonmovingHeap nonmovingHeap;
 
+extern uint64_t nonmoving_live_words;
+
 void nonmovingInit(void);
 void nonmovingExit(void);
 


=====================================
rts/sm/NonMovingMark.c
=====================================
@@ -1430,6 +1430,7 @@ mark_closure (MarkQueue *queue, StgClosure *p, StgClosure **origin)
         struct NonmovingSegment *seg = nonmovingGetSegment((StgPtr) p);
         nonmoving_block_idx block_idx = nonmovingGetBlockIdx((StgPtr) p);
         nonmovingSetMark(seg, block_idx);
+        nonmoving_live_words += nonmovingSegmentBlockSize(seg) / 8;
     }
 }
 


=====================================
rts/sm/Sanity.c
=====================================
@@ -1047,9 +1047,10 @@ memInventory (bool show)
   for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
       live_blocks += gen_blocks[g];
   }
+  // N.B. nonmoving_blocks has already been counted in gen_blocks
   live_blocks += nursery_blocks +
                + retainer_blocks + arena_blocks + exec_blocks + gc_free_blocks
-               + upd_rem_set_blocks + nonmoving_blocks;
+               + upd_rem_set_blocks;
 
 #define MB(n) (((double)(n) * BLOCK_SIZE_W) / ((1024*1024)/sizeof(W_)))
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/c61a65f6b43d6b1801dc594804d67e6fd447f7f5...5f773235f2b966e612743baea747fa6f0fc420d1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/c61a65f6b43d6b1801dc594804d67e6fd447f7f5...5f773235f2b966e612743baea747fa6f0fc420d1
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/20190416/18fe2bc1/attachment-0001.html>


More information about the ghc-commits mailing list