aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mpallocbits.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2019-09-10 18:53:51 +0000
committerMichael Knyszek <mknyszek@google.com>2019-11-07 19:14:38 +0000
commite1ddf0507c6d6dcbe1a2ebe54b8728498edf0995 (patch)
tree266bcd52947c4b4d79625e85a6f690f78c7059db /src/runtime/mpallocbits.go
parent73317080e12234defb59f84e2b5b15f69650b5d5 (diff)
downloadgo-e1ddf0507c6d6dcbe1a2ebe54b8728498edf0995.tar.xz
runtime: count scavenged bits for new allocation for new page allocator
This change makes it so that the new page allocator returns the number of pages that are scavenged in a new allocation so that mheap can update memstats appropriately. The accounting could be embedded into pageAlloc, but that would make the new allocator more difficult to test. Updates #35112. Change-Id: I0f94f563d7af2458e6d534f589d2e7dd6af26d12 Reviewed-on: https://go-review.googlesource.com/c/go/+/195698 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mpallocbits.go')
-rw-r--r--src/runtime/mpallocbits.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/runtime/mpallocbits.go b/src/runtime/mpallocbits.go
index a3cbc53a1b..b460c032bf 100644
--- a/src/runtime/mpallocbits.go
+++ b/src/runtime/mpallocbits.go
@@ -88,6 +88,26 @@ func (b *pageBits) clearAll() {
}
}
+// popcntRange counts the number of set bits in the
+// range [i, i+n).
+func (b *pageBits) popcntRange(i, n uint) (s uint) {
+ if n == 1 {
+ return uint((b[i/64] >> (i % 64)) & 1)
+ }
+ _ = b[i/64]
+ j := i + n - 1
+ if i/64 == j/64 {
+ return uint(bits.OnesCount64((b[i/64] >> (i % 64)) & ((1 << n) - 1)))
+ }
+ _ = b[j/64]
+ s += uint(bits.OnesCount64(b[i/64] >> (i % 64)))
+ for k := i/64 + 1; k < j/64; k++ {
+ s += uint(bits.OnesCount64(b[k]))
+ }
+ s += uint(bits.OnesCount64(b[j/64] & ((1 << (j%64 + 1)) - 1)))
+ return
+}
+
// pallocBits is a bitmap that tracks page allocations for at most one
// palloc chunk.
//