Per-thread allocation counters and limits
authorSimon Marlow <marlowsd@gmail.com>
Mon, 28 Apr 2014 15:55:47 +0000 (16:55 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 2 May 2014 13:49:22 +0000 (14:49 +0100)
commitb0534f78a73f972e279eed4447a5687bd6a8308e
tree02d52756620bf27b9df9db45c57dacf55f190842
parent34db5ccf52ec2a1b5e953c282d0c52a7fc82c02a
Per-thread allocation counters and limits

This tracks the amount of memory allocation by each thread in a
counter stored in the TSO.  Optionally, when the counter drops below
zero (it counts down), the thread can be sent an asynchronous
exception: AllocationLimitExceeded.  When this happens, given a small
additional limit so that it can handle the exception.  See
documentation in GHC.Conc for more details.

Allocation limits are similar to timeouts, but

  - timeouts use real time, not CPU time.  Allocation limits do not
    count anything while the thread is blocked or in foreign code.

  - timeouts don't re-trigger if the thread catches the exception,
    allocation limits do.

  - timeouts can catch non-allocating loops, if you use
    -fno-omit-yields.  This doesn't work for allocation limits.

I couldn't measure any impact on benchmarks with these changes, even
for nofib/smp.
32 files changed:
compiler/cmm/CmmLayoutStack.hs
compiler/codeGen/StgCmmForeign.hs
includes/CodeGen.Platform.hs
includes/rts/Constants.h
includes/rts/Flags.h
includes/rts/Threads.h
includes/rts/storage/TSO.h
libraries/base/Control/Exception.hs
libraries/base/Control/Exception/Base.hs
libraries/base/GHC/Conc.lhs
libraries/base/GHC/Conc/Sync.lhs
libraries/base/GHC/IO/Exception.hs
rts/HeapStackCheck.cmm
rts/Linker.c
rts/Prelude.h
rts/RaiseAsync.c
rts/RaiseAsync.h
rts/RtsFlags.c
rts/RtsStartup.c
rts/Schedule.c
rts/Threads.c
rts/package.conf.in
rts/sm/Storage.c
testsuite/tests/concurrent/should_run/all.T
testsuite/tests/concurrent/should_run/allocLimit1.hs [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit1.stderr [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit2.hs [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit3.hs [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit3.stderr [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit3.stdout [new file with mode: 0644]
testsuite/tests/concurrent/should_run/allocLimit4.hs [new file with mode: 0644]
utils/deriveConstants/DeriveConstants.hs