diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2019-11-15 23:30:30 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2019-12-11 19:37:19 +0000 |
commit | 9d78e75a0a55fd5ff3d68b4cba2f0395c4b5dc88 (patch) | |
tree | ce3494c184835c66c8c280b15d2b2ce9b6a0a7ae /src/runtime/export_test.go | |
parent | ef3ef8fcdfcd5e8a70b4a8feb2f91a82fee1f603 (diff) | |
download | go-9d78e75a0a55fd5ff3d68b4cba2f0395c4b5dc88.tar.gz go-9d78e75a0a55fd5ff3d68b4cba2f0395c4b5dc88.zip |
runtime: track ranges of address space which are owned by the heap
This change adds a new inUse field to the allocator which tracks ranges
of addresses that are owned by the heap. It is updated on each heap
growth.
These ranges are tracked in an array which is kept sorted. In practice
this array shouldn't exceed its initial allocation except in rare cases
and thus should be small (ideally exactly 1 element in size).
In a hypothetical worst-case scenario wherein we have a 1 TiB heap and 4
MiB arenas (note that the address ranges will never be at a smaller
granularity than an arena, since arenas are always allocated
contiguously), inUse would use at most 4 MiB of memory if the heap
mappings were completely discontiguous (highly unlikely) with an
additional 2 MiB leaked from previous allocations. Furthermore, the
copies that are done to keep the inUse array sorted will copy at most 4
MiB of memory in such a scenario, which, assuming a conservative copying
rate of 5 GiB/s, amounts to about 800µs.
However, note that in practice:
1) Most 64-bit platforms have 64 MiB arenas.
2) The copies should incur little-to-no page faults, meaning a copy rate
closer to 25-50 GiB/s is expected.
3) Go heaps are almost always mostly contiguous.
Updates #35514.
Change-Id: I3ad07f1c2b5b9340acf59ecc3b9ae09e884814fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/207757
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/export_test.go')
-rw-r--r-- | src/runtime/export_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 5206fa0109..d8cf2acad8 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -734,6 +734,16 @@ func (p *PageAlloc) Scavenge(nbytes uintptr, locked bool) (r uintptr) { }) return } +func (p *PageAlloc) InUse() []AddrRange { + ranges := make([]AddrRange, 0, len(p.inUse.ranges)) + for _, r := range p.inUse.ranges { + ranges = append(ranges, AddrRange{ + Base: r.base, + Limit: r.limit, + }) + } + return ranges +} // Returns nil if the PallocData's L2 is missing. func (p *PageAlloc) PallocData(i ChunkIdx) *PallocData { @@ -745,6 +755,12 @@ func (p *PageAlloc) PallocData(i ChunkIdx) *PallocData { return (*PallocData)(&l2[ci.l2()]) } +// AddrRange represents a range over addresses. +// Specifically, it represents the range [Base, Limit). +type AddrRange struct { + Base, Limit uintptr +} + // BitRange represents a range over a bitmap. type BitRange struct { I, N uint // bit index and length in bits |