diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2019-09-25 15:55:29 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2019-11-07 17:45:15 +0000 |
commit | cec01395c5df103f8e359027fd80c8070ce41506 (patch) | |
tree | ee6e3513ff492734057ffe5ed66d9f3c395bf379 /src/runtime/export_test.go | |
parent | b3a361337c5ea48fb4de832b9883f19e172e1bb5 (diff) | |
download | go-cec01395c5df103f8e359027fd80c8070ce41506.tar.gz go-cec01395c5df103f8e359027fd80c8070ce41506.zip |
runtime: add packed bitmap summaries
This change adds the concept of summaries and of summarizing a set of
pallocBits, a core concept in the new page allocator. These summaries
are really just three integers packed into a uint64. This change also
adds tests and a benchmark for generating these summaries.
Updates #35112.
Change-Id: I69686316086c820c792b7a54235859c2105e5fee
Reviewed-on: https://go-review.googlesource.com/c/go/+/190621
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/export_test.go')
-rw-r--r-- | src/runtime/export_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 27692791107..c00180c9fc9 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -735,6 +735,14 @@ const ( PallocChunkPages = pallocChunkPages ) +// Expose pallocSum for testing. +type PallocSum pallocSum + +func PackPallocSum(start, max, end uint) PallocSum { return PallocSum(packPallocSum(start, max, end)) } +func (m PallocSum) Start() uint { return pallocSum(m).start() } +func (m PallocSum) Max() uint { return pallocSum(m).max() } +func (m PallocSum) End() uint { return pallocSum(m).end() } + // Expose pallocBits for testing. type PallocBits pallocBits @@ -743,6 +751,33 @@ func (b *PallocBits) Find(npages uintptr, searchIdx uint) (uint, uint) { } func (b *PallocBits) AllocRange(i, n uint) { (*pallocBits)(b).allocRange(i, n) } func (b *PallocBits) Free(i, n uint) { (*pallocBits)(b).free(i, n) } +func (b *PallocBits) Summarize() PallocSum { return PallocSum((*pallocBits)(b).summarize()) } + +// SummarizeSlow is a slow but more obviously correct implementation +// of (*pallocBits).summarize. Used for testing. +func SummarizeSlow(b *PallocBits) PallocSum { + var start, max, end uint + + const N = uint(len(b)) * 64 + for start < N && (*pageBits)(b).get(start) == 0 { + start++ + } + for end < N && (*pageBits)(b).get(N-end-1) == 0 { + end++ + } + run := uint(0) + for i := uint(0); i < N; i++ { + if (*pageBits)(b).get(i) == 0 { + run++ + } else { + run = 0 + } + if run > max { + max = run + } + } + return PackPallocSum(start, max, end) +} // Expose non-trivial helpers for testing. func FindBitRange64(c uint64, n uint) uint { return findBitRange64(c, n) } |