// bookkeeping will use a large amount of each stack.
firstStackBarrierOffset = 1024
debugStackBarrier = false
+
+ // sweepMinHeapDistance is a lower bound on the heap distance
+ // (in bytes) reserved for concurrent sweeping between GC
+ // cycles. This will be scaled by gcpercent/100.
+ sweepMinHeapDistance = 1024 * 1024
)
// heapminimum is the minimum heap size at which to trigger GC.
memstats.heap_marked = work.bytesMarked
memstats.heap_scan = uint64(gcController.scanWork)
+ minNextGC := memstats.heap_live + sweepMinHeapDistance*uint64(gcpercent)/100
+ if memstats.next_gc < minNextGC {
+ // The allocated heap is already past the trigger.
+ // This can happen if the triggerRatio is very low and
+ // the reachable heap estimate is less than the live
+ // heap size.
+ //
+ // Concurrent sweep happens in the heap growth from
+ // heap_live to next_gc, so bump next_gc up to ensure
+ // that concurrent sweep has some heap growth in which
+ // to perform sweeping before we start the next GC
+ // cycle.
+ memstats.next_gc = minNextGC
+ }
+
if trace.enabled {
traceHeapAlloc()
traceNextGC()