diff --git a/rts/Schedule.c b/rts/Schedule.c index 7950785c4ffdd4f662d0418191bcd1923e8a342c..8002ac37dce20ff4bee58080eea8f3ab4413bd89 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 2d69eeed740e78b2ca1fa6564c10efa9cf32e33f..aaa44428b3dfa66f408615f1e2350b00650b6c00 100644 --- a/rts/sm/Storage.h +++ b/rts/sm/Storage.h @@ -24,17 +24,6 @@ void freeStorage(bool free_heap); // and initialises other storage-related things. 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 -------------------------------------------------------------------------- */ @@ -74,6 +63,17 @@ void resizeNurseriesFixed (void); 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