diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 865804470d..fc6fbd5768 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -180,11 +180,6 @@ func setGCPercent(in int32) (out int32) { return out } -// Trigger the concurrent GC when 1/triggerratio memory is available to allocate. -// Adjust this ratio as part of a scheme to ensure that mutators have enough -// memory to allocate in durring a concurrent GC cycle. -var triggerratio = int64(8) - // Determine whether to initiate a GC. // If the GC is already working no need to trigger another one. // This should establish a feedback loop where if the GC does not @@ -195,7 +190,7 @@ var triggerratio = int64(8) // A false negative simple does not start a GC, a false positive // will start a GC needlessly. Neither have correctness issues. func shouldtriggergc() bool { - return triggerratio*(int64(memstats.next_gc)-int64(memstats.heap_live)) <= int64(memstats.next_gc) && atomicloaduint(&bggc.working) == 0 + return memstats.heap_live >= memstats.next_gc && atomicloaduint(&bggc.working) == 0 } var work struct { @@ -591,9 +586,10 @@ func gcMark(start_time int64) { cachestats() - // compute next_gc + // Trigger the next GC cycle when the allocated heap has + // reached 7/8ths of the growth allowed by gcpercent. memstats.heap_live = work.bytesMarked - memstats.next_gc = memstats.heap_live + memstats.heap_live*uint64(gcpercent)/100 + memstats.next_gc = memstats.heap_live + (memstats.heap_live*uint64(gcpercent)/100)*7/8 if memstats.next_gc < heapminimum { memstats.next_gc = heapminimum }