diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2019-08-21 00:24:25 +0000 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2019-11-07 19:14:27 +0000 |
| commit | 73317080e12234defb59f84e2b5b15f69650b5d5 (patch) | |
| tree | 299810e966e35857625c1323fe0da5d3c6cd4c88 /src/runtime/mpallocbits.go | |
| parent | 39e8cb0faac7785f89b21246a45e8cf8d5bc7d95 (diff) | |
| download | go-73317080e12234defb59f84e2b5b15f69650b5d5.tar.xz | |
runtime: add scavenging code for new page allocator
This change adds a scavenger for the new page allocator along with
tests. The scavenger walks over the heap backwards once per GC, looking
for memory to scavenge. It walks across the heap without any lock held,
searching optimistically. If it finds what appears to be a scavenging
candidate it acquires the heap lock and attempts to verify it. Upon
verification it then scavenges.
Notably, unlike the old scavenger, it doesn't show any preference for
huge pages and instead follows a more strict last-page-first policy.
Updates #35112.
Change-Id: I0621ef73c999a471843eab2d1307ae5679dd18d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/195697
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mpallocbits.go')
| -rw-r--r-- | src/runtime/mpallocbits.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/runtime/mpallocbits.go b/src/runtime/mpallocbits.go index 117a59bb3d..a3cbc53a1b 100644 --- a/src/runtime/mpallocbits.go +++ b/src/runtime/mpallocbits.go @@ -131,7 +131,7 @@ var consec8tab = [256]uint{ 4, 3, 2, 2, 2, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 0, } -// summarize returns a packed summary of the bitmap in mallocBits. +// summarize returns a packed summary of the bitmap in pallocBits. func (b *pallocBits) summarize() pallocSum { // TODO(mknyszek): There may be something more clever to be done // here to make the summarize operation more efficient. For example, @@ -332,3 +332,28 @@ func findBitRange64(c uint64, n uint) uint { } return i } + +// pallocData encapsulates pallocBits and a bitmap for +// whether or not a given page is scavenged in a single +// structure. It's effectively a pallocBits with +// additional functionality. +type pallocData struct { + pallocBits + scavenged pageBits +} + +// allocRange sets bits [i, i+n) in the bitmap to 1 and +// updates the scavenged bits appropriately. +func (m *pallocData) allocRange(i, n uint) { + // Clear the scavenged bits when we alloc the range. + m.pallocBits.allocRange(i, n) + m.scavenged.clearRange(i, n) +} + +// allocAll sets every bit in the bitmap to 1 and updates +// the scavenged bits appropriately. +func (m *pallocData) allocAll() { + // Clear the scavenged bits when we alloc the range. + m.pallocBits.allocAll() + m.scavenged.clearAll() +} |
