}
memstats.heapStats.release()
- // Update gcController.heapLive with the same assumption.
- usedBytes := uintptr(s.allocCount) * s.elemsize
- atomic.Xadd64(&gcController.heapLive, int64(s.npages*pageSize)-int64(usedBytes))
-
+ // Update heapLive with the same assumption.
// While we're here, flush scanAlloc, since we have to call
// revise anyway.
- atomic.Xadd64(&gcController.heapScan, int64(c.scanAlloc))
+ usedBytes := uintptr(s.allocCount) * s.elemsize
+ gcController.update(int64(s.npages*pageSize)-int64(usedBytes), int64(c.scanAlloc))
c.scanAlloc = 0
- if trace.enabled {
- // gcController.heapLive changed.
- traceHeapAlloc()
- }
- if gcBlackenEnabled != 0 {
- // gcController.heapLive and heapScan changed.
- gcController.revise()
- }
-
c.alloc[spc] = s
}
atomic.Xadduintptr(&stats.largeAllocCount, 1)
memstats.heapStats.release()
- // Update gcController.heapLive and revise pacing if needed.
- atomic.Xadd64(&gcController.heapLive, int64(npages*pageSize))
- if trace.enabled {
- // Trace that a heap alloc occurred because gcController.heapLive changed.
- traceHeapAlloc()
- }
- if gcBlackenEnabled != 0 {
- gcController.revise()
- }
+ // Update heapLive.
+ gcController.update(int64(s.npages*pageSize), 0)
// Put the large span in the mcentral swept list so that it's
// visible to the background sweeper.
func (c *mcache) releaseAll() {
// Take this opportunity to flush scanAlloc.
- atomic.Xadd64(&gcController.heapScan, int64(c.scanAlloc))
+ scanAlloc := int64(c.scanAlloc)
c.scanAlloc = 0
sg := mheap_.sweepgen
+ dHeapLive := int64(0)
for i := range c.alloc {
s := c.alloc[i]
if s != &emptymspan {
// gcController.heapLive was totally recomputed since
// caching this span, so we don't do this for
// stale spans.
- atomic.Xadd64(&gcController.heapLive, -int64(n)*int64(s.elemsize))
+ dHeapLive -= int64(n) * int64(s.elemsize)
}
// Release the span to the mcentral.
mheap_.central[i].mcentral.uncacheSpan(s)
c.tinyAllocs = 0
memstats.heapStats.release()
- // Updated heapScan and possible gcController.heapLive.
- if gcBlackenEnabled != 0 {
- gcController.revise()
- }
+ // Updated heapScan and heapLive.
+ gcController.update(dHeapLive, scanAlloc)
}
// prepareForSweep flushes c if the system has entered a new sweep phase
}
}
+func (c *gcControllerState) update(dHeapLive, dHeapScan int64) {
+ if dHeapLive != 0 {
+ atomic.Xadd64(&gcController.heapLive, dHeapLive)
+ if trace.enabled {
+ // gcController.heapLive changed.
+ traceHeapAlloc()
+ }
+ }
+ if dHeapScan != 0 {
+ atomic.Xadd64(&gcController.heapScan, dHeapScan)
+ }
+ if gcBlackenEnabled != 0 {
+ // gcController.heapLive and heapScan changed.
+ c.revise()
+ }
+}
+
// commit sets the trigger ratio and updates everything
// derived from it: the absolute trigger, the heap goal, mark pacing,
// and sweep pacing.