aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/malloc.go1
-rw-r--r--src/runtime/mgcsweep.go10
2 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 2ac504f9dc..438cd06161 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -696,6 +696,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
s = largeAlloc(size, needzero)
})
s.freeindex = 1
+ s.allocCount = 1
x = unsafe.Pointer(s.base())
size = s.elemsize
}
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index c9ef63547a..82537edaaa 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -272,8 +272,14 @@ func (s *mspan) sweep(preserve bool) bool {
s.needzero = 1
freeToHeap = true
}
+ nalloc := uint16(s.nelems) - uint16(nfree)
+ nfreed := s.allocCount - nalloc
+ if nalloc > s.allocCount {
+ print("runtime: nelems=", s.nelems, " nfree=", nfree, " nalloc=", nalloc, " previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n")
+ throw("sweep increased allocation count")
+ }
- s.allocCount = uint16(s.nelems) - uint16(nfree)
+ s.allocCount = nalloc
wasempty := s.nextFreeIndex() == s.nelems
s.freeindex = 0 // reset allocation index to start of span.
@@ -304,7 +310,7 @@ func (s *mspan) sweep(preserve bool) bool {
}
if nfree > 0 && cl != 0 {
- c.local_nsmallfree[cl] += uintptr(nfree)
+ c.local_nsmallfree[cl] += uintptr(nfreed)
res = mheap_.central[cl].mcentral.freeSpan(s, preserve, wasempty)
// MCentral_FreeSpan updates sweepgen
} else if freeToHeap {