Commit 453cdbfc authored by Simon Marlow's avatar Simon Marlow Committed by Austin Seipp

base: export allocation counter/limit API from System.Mem

Previously it was only available from GHC.Conc, but it makes sense for it to be
available from a more official place where people might find it.

While I was here, I improved the docs a little.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D1272
parent 73921df2
......@@ -324,6 +324,18 @@
(see Trac #9516).
</para>
</listitem>
<listitem>
<para>
Per-thread allocation counters
(<literal>setAllocationCounter</literal> and
<literal>getAllocationCounter</literal>) and limits
(<literal>enableAllocationLimit</literal>,
<literal>disableAllocationLimit</literal> are now
available from <literal>System.Mem</literal>.
Previously this functionality was only available
from <literal>GHC.Conc</literal>.
</para>
</listitem>
</itemizedlist>
</sect3>
......
......@@ -213,7 +213,9 @@ getAllocationCounter = do
-- to 100K, but tunable with the @+RTS -xq@ option) so that it can handle
-- the exception and perform any necessary clean up. If it exhausts
-- this additional allowance, another 'AllocationLimitExceeded' exception
-- is sent, and so forth.
-- is sent, and so forth. Like other asynchronous exceptions, the
-- 'AllocationLimitExceeded' exception is deferred while the thread is inside
-- 'mask' or an exception handler in 'catch'.
--
-- Note that memory allocation is unrelated to /live memory/, also
-- known as /heap residency/. A thread can allocate a large amount of
......
......@@ -98,8 +98,8 @@ instance Show Deadlock where
-----
-- |This thread has exceeded its allocation limit. See
-- 'GHC.Conc.setAllocationCounter' and
-- 'GHC.Conc.enableAllocationLimit'.
-- 'System.Mem.setAllocationCounter' and
-- 'System.Mem.enableAllocationLimit'.
--
-- @since 4.8.0.0
data AllocationLimitExceeded = AllocationLimitExceeded
......
{-# LANGUAGE Safe #-}
-----------------------------------------------------------------------------
-- |
-- Module : System.Mem
......@@ -14,17 +12,30 @@
--
-----------------------------------------------------------------------------
{-# LANGUAGE Trustworthy #-}
-- allocation counter stuff is safe, but GHC.Conc.Sync is Unsafe
module System.Mem
( performGC
(
-- * Garbage collection
performGC
, performMajorGC
, performMinorGC
-- * Allocation counter and limits
, setAllocationCounter
, getAllocationCounter
, enableAllocationLimit
, disableAllocationLimit
) where
-- | Triggers an immediate garbage collection.
import GHC.Conc.Sync
-- | Triggers an immediate major garbage collection.
performGC :: IO ()
performGC = performMajorGC
-- | Triggers an immediate garbage collection.
-- | Triggers an immediate major garbage collection.
--
-- @since 4.7.0.0
foreign import ccall "performMajorGC" performMajorGC :: IO ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment