mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: add pallocbits and tests
This change adds a per-chunk bitmap for page allocation called pallocBits with algorithms for allocating and freeing pages out of the bitmap. This change also adds tests for pallocBits, but does not yet integrate it into the runtime. Updates #35112. Change-Id: I479006ed9f1609c80eedfff0580d5426b064b0ff Reviewed-on: https://go-review.googlesource.com/c/go/+/190620 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
6b1d5471b9
commit
b3a361337c
4 changed files with 615 additions and 2 deletions
|
|
@ -730,3 +730,66 @@ func RunGetgThreadSwitchTest() {
|
|||
panic("g1 != g3")
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
PallocChunkPages = pallocChunkPages
|
||||
)
|
||||
|
||||
// Expose pallocBits for testing.
|
||||
type PallocBits pallocBits
|
||||
|
||||
func (b *PallocBits) Find(npages uintptr, searchIdx uint) (uint, uint) {
|
||||
return (*pallocBits)(b).find(npages, searchIdx)
|
||||
}
|
||||
func (b *PallocBits) AllocRange(i, n uint) { (*pallocBits)(b).allocRange(i, n) }
|
||||
func (b *PallocBits) Free(i, n uint) { (*pallocBits)(b).free(i, n) }
|
||||
|
||||
// Expose non-trivial helpers for testing.
|
||||
func FindBitRange64(c uint64, n uint) uint { return findBitRange64(c, n) }
|
||||
|
||||
// Given two PallocBits, returns a set of bit ranges where
|
||||
// they differ.
|
||||
func DiffPallocBits(a, b *PallocBits) []BitRange {
|
||||
ba := (*pageBits)(a)
|
||||
bb := (*pageBits)(b)
|
||||
|
||||
var d []BitRange
|
||||
base, size := uint(0), uint(0)
|
||||
for i := uint(0); i < uint(len(ba))*64; i++ {
|
||||
if ba.get(i) != bb.get(i) {
|
||||
if size == 0 {
|
||||
base = i
|
||||
}
|
||||
size++
|
||||
} else {
|
||||
if size != 0 {
|
||||
d = append(d, BitRange{base, size})
|
||||
}
|
||||
size = 0
|
||||
}
|
||||
}
|
||||
if size != 0 {
|
||||
d = append(d, BitRange{base, size})
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// StringifyPallocBits gets the bits in the bit range r from b,
|
||||
// and returns a string containing the bits as ASCII 0 and 1
|
||||
// characters.
|
||||
func StringifyPallocBits(b *PallocBits, r BitRange) string {
|
||||
str := ""
|
||||
for j := r.I; j < r.I+r.N; j++ {
|
||||
if (*pageBits)(b).get(j) != 0 {
|
||||
str += "1"
|
||||
} else {
|
||||
str += "0"
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
// BitRange represents a range over a bitmap.
|
||||
type BitRange struct {
|
||||
I, N uint // bit index and length in bits
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue