diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2019-08-14 16:32:12 +0000 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2019-11-07 19:11:26 +0000 |
| commit | 39e8cb0faac7785f89b21246a45e8cf8d5bc7d95 (patch) | |
| tree | 58eaa62ff08840a9c60f19ee6542cfe4ba7cb8af /src/runtime/mpagealloc_32bit.go | |
| parent | 05aa4a7b7447051d187e0a86e53eee99fe065851 (diff) | |
| download | go-39e8cb0faac7785f89b21246a45e8cf8d5bc7d95.tar.xz | |
runtime: add new page allocator core
This change adds a new bitmap-based allocator to the runtime with tests.
It does not yet integrate the page allocator into the runtime and thus
this change is almost purely additive.
Updates #35112.
Change-Id: Ic3d024c28abee8be8797d3918116a80f901cc2bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/190622
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mpagealloc_32bit.go')
| -rw-r--r-- | src/runtime/mpagealloc_32bit.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/runtime/mpagealloc_32bit.go b/src/runtime/mpagealloc_32bit.go index c91b2bbe3f..996228c046 100644 --- a/src/runtime/mpagealloc_32bit.go +++ b/src/runtime/mpagealloc_32bit.go @@ -17,7 +17,93 @@ package runtime +import "unsafe" + const ( // The number of levels in the radix tree. summaryLevels = 4 + + // Constants for testing. + pageAlloc32Bit = 1 + pageAlloc64Bit = 0 ) + +// See comment in mpagealloc_64bit.go. +var levelBits = [summaryLevels]uint{ + summaryL0Bits, + summaryLevelBits, + summaryLevelBits, + summaryLevelBits, +} + +// See comment in mpagealloc_64bit.go. +var levelShift = [summaryLevels]uint{ + heapAddrBits - summaryL0Bits, + heapAddrBits - summaryL0Bits - 1*summaryLevelBits, + heapAddrBits - summaryL0Bits - 2*summaryLevelBits, + heapAddrBits - summaryL0Bits - 3*summaryLevelBits, +} + +// See comment in mpagealloc_64bit.go. +var levelLogPages = [summaryLevels]uint{ + logPallocChunkPages + 3*summaryLevelBits, + logPallocChunkPages + 2*summaryLevelBits, + logPallocChunkPages + 1*summaryLevelBits, + logPallocChunkPages, +} + +// See mpagealloc_64bit.go for details. +func (s *pageAlloc) sysInit() { + // Calculate how much memory all our entries will take up. + // + // This should be around 12 KiB or less. + totalSize := uintptr(0) + for l := 0; l < summaryLevels; l++ { + totalSize += (uintptr(1) << (heapAddrBits - levelShift[l])) * pallocSumBytes + } + totalSize = alignUp(totalSize, physPageSize) + + // Reserve memory for all levels in one go. There shouldn't be much for 32-bit. + reservation := sysReserve(nil, totalSize) + if reservation == nil { + throw("failed to reserve page summary memory") + } + // There isn't much. Just map it and mark it as used immediately. + sysMap(reservation, totalSize, s.sysStat) + sysUsed(reservation, totalSize) + + // Iterate over the reservation and cut it up into slices. + // + // Maintain i as the byte offset from reservation where + // the new slice should start. + for l, shift := range levelShift { + entries := 1 << (heapAddrBits - shift) + + // Put this reservation into a slice. + sl := notInHeapSlice{(*notInHeap)(reservation), 0, entries} + s.summary[l] = *(*[]pallocSum)(unsafe.Pointer(&sl)) + + reservation = add(reservation, uintptr(entries)*pallocSumBytes) + } +} + +// See mpagealloc_64bit.go for details. +func (s *pageAlloc) sysGrow(base, limit uintptr) { + if base%pallocChunkBytes != 0 || limit%pallocChunkBytes != 0 { + print("runtime: base = ", hex(base), ", limit = ", hex(limit), "\n") + throw("sysGrow bounds not aligned to pallocChunkBytes") + } + + // Walk up the tree and update the summary slices. + for l := len(s.summary) - 1; l >= 0; l-- { + // Figure out what part of the summary array this new address space needs. + // Note that we need to align the ranges to the block width (1<<levelBits[l]) + // at this level because the full block is needed to compute the summary for + // the next level. + lo, hi := addrsToSummaryRange(l, base, limit) + _, hi = blockAlignSummaryRange(l, lo, hi) + if hi > len(s.summary[l]) { + s.summary[l] = s.summary[l][:hi] + } + } +} |
