[Git][ghc/ghc][wip/gc/test] 13 commits: rts: Implement concurrent collection in the nonmoving collector

Ben Gamari gitlab at gitlab.haskell.org
Wed Jun 19 15:28:51 UTC 2019



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


Commits:
395ab8d5 by Ben Gamari at 2019-06-19T15:23:46Z
rts: Implement concurrent collection in the nonmoving collector

This extends the non-moving collector to allow concurrent collection.

The full design of the collector implemented here is described in detail
in a technical note

    B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell
    Compiler" (2018)

This extension involves the introduction of a capability-local
remembered set, known as the /update remembered set/, which tracks
objects which may no longer be visible to the collector due to mutation.
To maintain this remembered set we introduce a write barrier on
mutations which is enabled while a concurrent mark is underway.

The update remembered set representation is similar to that of the
nonmoving mark queue, being a chunked array of `MarkEntry`s. Each
`Capability` maintains a single accumulator chunk, which it flushed
when it (a) is filled, or (b) when the nonmoving collector enters its
post-mark synchronization phase.

While the write barrier touches a significant amount of code it is
conceptually straightforward: the mutator must ensure that the referee
of any pointer it overwrites is added to the update remembered set.
However, there are a few details:

 * In the case of objects with a dirty flag (e.g. `MVar`s) we can
   exploit the fact that only the *first* mutation requires a write
   barrier.

 * Weak references, as usual, complicate things. In particular, we must
   ensure that the referee of a weak object is marked if dereferenced by
   the mutator. For this we (unfortunately) must introduce a read
   barrier, as described in Note [Concurrent read barrier on deRefWeak#]
   (in `NonMovingMark.c`).

 * Stable names are also a bit tricky as described in Note [Sweeping
   stable names in the concurrent collector] (`NonMovingSweep.c`).

We take quite some pains to ensure that the high thread count often seen
in parallel Haskell applications doesn't affect pause times. To this end
we allow thread stacks to be marked either by the thread itself (when it
is executed or stack-underflows) or the concurrent mark thread (if the
thread owning the stack is never scheduled). There is a non-trivial
handshake to ensure that this happens without racing which is described
in Note [StgStack dirtiness flags and concurrent marking].

Co-Authored-by: Ömer Sinan Ağacan <omer at well-typed.com>

- - - - -
59894c90 by Ben Gamari at 2019-06-19T15:23:46Z
Nonmoving: Disable memory inventory with concurrent collection

- - - - -
69900691 by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Add nonmoving_thr way

- - - - -
8da04fa3 by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Add nonmoving_thr_ghc way

This uses the nonmoving collector when compiling the testcases.

- - - - -
1e59c6cb by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Don't run T15892 in nonmoving ways

The nonmoving GC doesn't support `+RTS -G1`, which this test insists on.

- - - - -
bcff1d84 by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Nonmoving collector doesn't support -G1

- - - - -
6327adf2 by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Ensure that threaded tests are run in nonmoving_thr

- - - - -
d7690aef by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: bug1010 requires -c, which isn't supported by nonmoving

- - - - -
1d0c58bc by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Skip T15892 in nonmoving_thr_ghc

- - - - -
17a5c359 by Ben Gamari at 2019-06-19T15:26:14Z
ghc-heap: Skip heap_all test with debugged RTS

The debugged RTS initializes the heap with 0xaa, which breaks the
(admittedly rather fragile) assumption that uninitialized fields are set
to 0x00:
```
Wrong exit code for heap_all(nonmoving)(expected 0 , actual 1 )
Stderr ( heap_all ):
heap_all: user error (assertClosuresEq: Closures do not match
Expected: FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 0, code = Nothing}, ptrArgs = [], dataArgs = [0]}
Actual:   FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 1032832, code = Nothing}, ptrArgs = [], dataArgs = [12297829382473034410]}

CallStack (from HasCallStack):
  assertClosuresEq, called at heap_all.hs:230:9 in main:Main
)
```

- - - - -
fba07d85 by Ben Gamari at 2019-06-19T15:26:14Z
Skip ghc_heap_all test in nonmoving ways

- - - - -
5f6cb8ed by Ben Gamari at 2019-06-19T15:26:14Z
testsuite: Don't run T9630 in nonmoving ways

The nonmoving collector doesn't support -G1

- - - - -
d60bdf28 by Ben Gamari at 2019-06-19T15:26:15Z
testsuite: Don't run T7160 in nonmoving_thr ways

The nonmoving way finalizes things in a different order.

- - - - -


30 changed files:

- compiler/cmm/CLabel.hs
- compiler/codeGen/StgCmmBind.hs
- compiler/codeGen/StgCmmPrim.hs
- compiler/codeGen/StgCmmUtils.hs
- includes/Cmm.h
- includes/Rts.h
- + includes/rts/NonMoving.h
- includes/rts/storage/ClosureMacros.h
- includes/rts/storage/GC.h
- includes/rts/storage/TSO.h
- includes/stg/MiscClosures.h
- libraries/ghc-heap/tests/all.T
- rts/Apply.cmm
- rts/Capability.c
- rts/Capability.h
- rts/Exception.cmm
- rts/Messages.c
- rts/PrimOps.cmm
- rts/RaiseAsync.c
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/STM.c
- rts/Schedule.c
- rts/StableName.c
- rts/ThreadPaused.c
- rts/Threads.c
- rts/Updates.h
- rts/sm/NonMoving.c
- rts/sm/NonMoving.h
- rts/sm/NonMovingMark.c


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/da9e3ef2f0eb9943159444953d14d2fd4b6bff5e...d60bdf28b901eb59500ec43e8a8010a86c602053

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/da9e3ef2f0eb9943159444953d14d2fd4b6bff5e...d60bdf28b901eb59500ec43e8a8010a86c602053
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/20190619/3a4c5faa/attachment.html>


More information about the ghc-commits mailing list