[commit: ghc] master: Fix a missing getNewNursery(), and related cleanup (12ae1fa)
git at git.haskell.org
git at git.haskell.org
Tue Jul 18 11:46:15 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/12ae1fa51b2f59e37d6100359b494bee2192ef0a/ghc
>---------------------------------------------------------------
commit 12ae1fa51b2f59e37d6100359b494bee2192ef0a
Author: Simon Marlow <marlowsd at gmail.com>
Date: Mon Jul 17 17:32:44 2017 +0100
Fix a missing getNewNursery(), and related cleanup
Summary:
When we use nursery chunks with +RTS -n<size>, when the current nursery
runs out we have to check whether there's another chunk available with
getNewNursery(). There was one place we weren't doing this: the ad-hoc
heap check in scheduleProcessInbox().
The impact of the bug was that we would GC too early when using nursery
chunks, especially in programs that used messages (throwTo between
capabilities could do this, also hs_try_putmvar()).
Test Plan: validate, also local testing in our application
Reviewers: bgamari, niteria, austin, erikd
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3749
>---------------------------------------------------------------
12ae1fa51b2f59e37d6100359b494bee2192ef0a
rts/Schedule.c | 19 +++----------------
rts/sm/Storage.h | 22 +++++++++++-----------
2 files changed, 14 insertions(+), 27 deletions(-)
diff --git a/rts/Schedule.c b/rts/Schedule.c
index 7950785..8002ac3 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -993,8 +993,8 @@ scheduleProcessInbox (Capability **pcap USED_IF_THREADS)
Capability *cap = *pcap;
while (!emptyInbox(cap)) {
- if (cap->r.rCurrentNursery->link == NULL ||
- g0->n_new_large_words >= large_alloc_lim) {
+ // Executing messages might use heap, so we should check for GC.
+ if (doYouWantToGC(cap)) {
scheduleDoGC(pcap, cap->running_task, false);
cap = *pcap;
}
@@ -1183,20 +1183,7 @@ scheduleHandleHeapOverflow( Capability *cap, StgTSO *t )
}
}
- // if we got here because we exceeded large_alloc_lim, then
- // proceed straight to GC.
- if (g0->n_new_large_words >= large_alloc_lim) {
- return true;
- }
-
- // Otherwise, we just ran out of space in the current nursery.
- // Grab another nursery if we can.
- if (getNewNursery(cap)) {
- debugTrace(DEBUG_sched, "thread %ld got a new nursery", t->id);
- return false;
- }
-
- return true;
+ return doYouWantToGC(cap);
/* actual GC is done at the end of the while loop in schedule() */
}
diff --git a/rts/sm/Storage.h b/rts/sm/Storage.h
index 2d69eee..aaa4442 100644
--- a/rts/sm/Storage.h
+++ b/rts/sm/Storage.h
@@ -25,17 +25,6 @@ void freeStorage(bool free_heap);
void storageAddCapabilities (uint32_t from, uint32_t to);
/* -----------------------------------------------------------------------------
- Should we GC?
- -------------------------------------------------------------------------- */
-
-INLINE_HEADER
-bool doYouWantToGC(Capability *cap)
-{
- return (cap->r.rCurrentNursery->link == NULL ||
- g0->n_new_large_words >= large_alloc_lim);
-}
-
-/* -----------------------------------------------------------------------------
The storage manager mutex
-------------------------------------------------------------------------- */
@@ -75,6 +64,17 @@ StgWord countNurseryBlocks (void);
bool getNewNursery (Capability *cap);
/* -----------------------------------------------------------------------------
+ Should we GC?
+ -------------------------------------------------------------------------- */
+
+INLINE_HEADER
+bool doYouWantToGC(Capability *cap)
+{
+ return ((cap->r.rCurrentNursery->link == NULL && !getNewNursery(cap)) ||
+ g0->n_new_large_words >= large_alloc_lim);
+}
+
+/* -----------------------------------------------------------------------------
Allocation accounting
See [Note allocation accounting] in Storage.c
More information about the ghc-commits
mailing list