mirror of
https://github.com/golang/go
synced 2024-11-18 14:04:45 -07:00
runtime: simplify sweep allocation counting
Currently sweep counts the number of allocated objects, computes the number of free objects from that, then re-computes the number of allocated objects from that. Simplify and clean this up by skipping these intermediate steps. Change-Id: I3ed98e371eb54bbcab7c8530466c4ab5fde35f0a Reviewed-on: https://go-review.googlesource.com/34935 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com> Reviewed-by: Rick Hudson <rlh@golang.org>
This commit is contained in:
parent
f1ba75f8c5
commit
b50b728587
@ -823,10 +823,10 @@ var oneBitCount = [256]uint8{
|
|||||||
4, 5, 5, 6, 5, 6, 6, 7,
|
4, 5, 5, 6, 5, 6, 6, 7,
|
||||||
5, 6, 6, 7, 6, 7, 7, 8}
|
5, 6, 6, 7, 6, 7, 7, 8}
|
||||||
|
|
||||||
// countFree runs through the mark bits in a span and counts the number of free objects
|
// countAlloc returns the number of objects allocated in span s by
|
||||||
// in the span.
|
// scanning the allocation bitmap.
|
||||||
// TODO:(rlh) Use popcount intrinsic.
|
// TODO:(rlh) Use popcount intrinsic.
|
||||||
func (s *mspan) countFree() int {
|
func (s *mspan) countAlloc() int {
|
||||||
count := 0
|
count := 0
|
||||||
maxIndex := s.nelems / 8
|
maxIndex := s.nelems / 8
|
||||||
for i := uintptr(0); i < maxIndex; i++ {
|
for i := uintptr(0); i < maxIndex; i++ {
|
||||||
@ -839,7 +839,7 @@ func (s *mspan) countFree() int {
|
|||||||
bits := mrkBits & mask
|
bits := mrkBits & mask
|
||||||
count += int(oneBitCount[bits])
|
count += int(oneBitCount[bits])
|
||||||
}
|
}
|
||||||
return int(s.nelems) - count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
// heapBitsSetType records that the new allocation [x, x+size)
|
// heapBitsSetType records that the new allocation [x, x+size)
|
||||||
|
@ -186,7 +186,6 @@ func (s *mspan) sweep(preserve bool) bool {
|
|||||||
cl := s.sizeclass
|
cl := s.sizeclass
|
||||||
size := s.elemsize
|
size := s.elemsize
|
||||||
res := false
|
res := false
|
||||||
nfree := 0
|
|
||||||
|
|
||||||
c := _g_.m.mcache
|
c := _g_.m.mcache
|
||||||
freeToHeap := false
|
freeToHeap := false
|
||||||
@ -276,15 +275,14 @@ func (s *mspan) sweep(preserve bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count the number of free objects in this span.
|
// Count the number of free objects in this span.
|
||||||
nfree = s.countFree()
|
nalloc := uint16(s.countAlloc())
|
||||||
if cl == 0 && nfree != 0 {
|
if cl == 0 && nalloc == 0 {
|
||||||
s.needzero = 1
|
s.needzero = 1
|
||||||
freeToHeap = true
|
freeToHeap = true
|
||||||
}
|
}
|
||||||
nalloc := uint16(s.nelems) - uint16(nfree)
|
|
||||||
nfreed := s.allocCount - nalloc
|
nfreed := s.allocCount - nalloc
|
||||||
if nalloc > s.allocCount {
|
if nalloc > s.allocCount {
|
||||||
print("runtime: nelems=", s.nelems, " nfree=", nfree, " nalloc=", nalloc, " previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n")
|
print("runtime: nelems=", s.nelems, " nalloc=", nalloc, " previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n")
|
||||||
throw("sweep increased allocation count")
|
throw("sweep increased allocation count")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user