Source File
mcache.go
Belonging Package
runtime
package runtime
import (
)
nextSample uintptr // trigger heap sample after allocating this many bytes
scanAlloc uintptr // bytes of scannable heap allocated
alloc [numSpanClasses]*mspan // spans to allocate from, indexed by spanClass
stackcache [_NumStackOrders]stackfreelist
var emptymspan mspan
func () *mcache {
var *mcache
systemstack(func() {
lock(&mheap_.lock)
= (*mcache)(mheap_.cachealloc.alloc())
.flushGen = mheap_.sweepgen
unlock(&mheap_.lock)
})
for := range .alloc {
.alloc[] = &emptymspan
}
.nextSample = nextSample()
return
}
func ( *mcache) {
systemstack(func() {
.releaseAll()
stackcache_clear()
:= .alloc[]
if uintptr(.allocCount) != .nelems {
throw("refill of span with free space remaining")
}
:= memstats.heapStats.acquire()
atomic.Xadduintptr(&.smallAllocCount[.sizeclass()], uintptr(.nelems)-uintptr(.allocCount))
memstats.heapStats.release()
if == tinySpanClass {
atomic.Xadd64(&memstats.tinyallocs, int64(.tinyAllocs))
.tinyAllocs = 0
}
traceHeapAlloc()
}
gcController.revise()
}
.alloc[] =
}
deductSweepCredit(*_PageSize, )
:= makeSpanClass(0, )
:= mheap_.alloc(, , )
if == nil {
throw("out of memory")
}
:= memstats.heapStats.acquire()
atomic.Xadduintptr(&.largeAlloc, *pageSize)
atomic.Xadduintptr(&.largeAllocCount, 1)
memstats.heapStats.release()
traceHeapAlloc()
}
if gcBlackenEnabled != 0 {
gcController.revise()
}
:= uintptr(.nelems) - uintptr(.allocCount)
:= memstats.heapStats.acquire()
atomic.Xadduintptr(&.smallAllocCount[spanClass().sizeclass()], -)
memstats.heapStats.release()
mheap_.central[].mcentral.uncacheSpan()
.alloc[] = &emptymspan
}
.tiny = 0
.tinyoffset = 0
atomic.Xadd64(&memstats.tinyallocs, int64(.tinyAllocs))
.tinyAllocs = 0
if gcBlackenEnabled != 0 {
gcController.revise()
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |