[Haskell-cafe] How does the RTS pin ByteArray# objects during FFI calls?

Reiner Pope reiner.pope at gmail.com
Wed Jan 3 02:51:40 UTC 2018


Hi Haskell-Cafe,

I understand from
https://mail.haskell.org/pipermail/haskell-cafe/2014-June/114763.html that
it is safe to pass ByteArray# objects to FFI calls, using the
UnliftedFFITypes language extension. As I understand it, the implicit
guarantee is that the RTS will pin the ByteArray#'s address in memory for
the duration of the FFI call -- even if the ByteArray# wasn't allocated
pinned.

I'm curious: how does the RTS achieve this "retroactive" pinning? The
documentation at
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC/Pinned suggests
that *all* ByteArrays are allocated pinned to account for the possibility
that they will in future be passed to the FFI. Is this really the case?
This seems like it forces an unreasonably slow allocator on small (say,
~10-byte) ByteArray allocations where the GC's usual bump-pointer allocator
might otherwise be preferable.

Regards,
Reiner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180103/eb704dbb/attachment.html>


More information about the Haskell-Cafe mailing list