Min closure payload size?

Ömer Sinan Ağacan omeragacan at gmail.com
Wed Sep 11 08:24:25 UTC 2019


https://gitlab.haskell.org/ghc/ghc/merge_requests/1701

Ömer

Ömer Sinan Ağacan <omeragacan at gmail.com>, 10 Eyl 2019 Sal, 15:14
tarihinde şunu yazdı:
>
> It took 7 months to figure this one out. The compacting GC (which is enabled by
> default when heap residency is above 30%) needs two bits per closure: one for
> the actual "liveness" mark bit, another one for whether the object's new
> location (computed during two scans in compacting GC) is in the next block in
> the heap chain, instead of the current block (which the "free" pointer points
> to).
>
> This bit is important becuase in the second pass we get info pointer of an
> object and update any references to it (so that they point to its new location)
> in one pass (the "unthreading" business), and we can't compute the size of the
> object being moved (to see whether we can move the object to the current free
> location or we have to move to the next block in the heap) before we get the
> info table. So if we want to avoid this second mark bit we'd need to do one pass
> to get the info table, compute the size, see if it fits in the current block
> etc. and then do another pass to actually "unthread" (i.e. update references to
> the object with the new location).
>
> However I was able to lift this restriction by just bumping the bitmap size, to
> allocate two bits per word in the heap (instead of one). It seems to work fine
> (passes the test suite), I'll test this a little bit more and then submit a MR.
> This reduces closure sizes of objects with no payload, e.g.:
>
>     {-# LANGUAGE MagicHash #-}
>
>     import GHC.Int
>     import GHC.Prim
>
>     main = print (I# (closureSize# True))
>
> This now prints 1 instead of 2 as before.
>
> Ömer
>
> Ömer Sinan Ağacan <omeragacan at gmail.com>, 4 Şub 2019 Pzt, 16:23
> tarihinde şunu yazdı:
> >
> > Hi,
> >
> > I was trying to understand why some info tables that have no ptrs and nptrs like
> > GCD_CAF end up with 1 nptrs in the generated info table and found this code in
> > Constants.h:
> >
> >     /* -----------------------------------------------------------------------------
> >        Minimum closure sizes
> >
> >        This is the minimum number of words in the payload of a
> >        heap-allocated closure, so that the closure has enough room to be
> >        overwritten with a forwarding pointer during garbage collection.
> >        --------------------------------------------------------------------------
> > */
> >
> >     #define MIN_PAYLOAD_SIZE 1
> >
> > We use this in a few places in the compiler and add at least one word space in
> > the payload. However the comment is actually wrong, forwarding pointers are made
> > by tagging the info ptr field so we don't need a word in the payload for
> > forwarding pointers. I tried updating this as 0 but that caused a lot of test
> > failures (mostly in GHCi). I'm wondering if I'm missing anything or is it just
> > some code assuming min payload size 1 without using this macro.
> >
> > Any ideas?
> >
> > Ömer


More information about the ghc-devs mailing list