aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-04-07 13:49:51 -0400
committerAustin Clements <austin@google.com>2017-04-11 01:35:47 +0000
commit6c6f455f880ea560707348fcea9d4188782706e8 (patch)
tree7da41710b708f3f7b4b36ec7aefe51aed882456f /src/runtime/malloc.go
parent075ee299b19f6c7e9cc506f1c6420b4c71a61d12 (diff)
downloadgo-6c6f455f880ea560707348fcea9d4188782706e8.tar.xz
runtime: consolidate changes to arena_used
Changing mheap_.arena_used requires several steps that are currently repeated multiple times in mheap_.sysAlloc. Consolidate these into a single function. In the future, this will also make it easier to add other auxiliary VM structures. Change-Id: Ie68837d2612e1f4ba4904acb1b6b832b15431d56 Reviewed-on: https://go-review.googlesource.com/40151 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 188b0453df..7517f1284e 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -397,16 +397,22 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
return nil
}
if p == h.arena_end {
+ // The new reservation is contiguous
+ // with the old reservation.
h.arena_end = new_end
h.arena_reserved = reserved
} else if h.arena_start <= p && p+p_size-h.arena_start-1 <= _MaxMem {
+ // We were able to reserve more memory
+ // within the arena space, but it's
+ // not contiguous with our previous
+ // reservation. Skip over the unused
+ // address space.
+ //
// Keep everything page-aligned.
// Our pages are bigger than hardware pages.
h.arena_end = p + p_size
used := p + (-p & (_PageSize - 1))
- h.mapBits(used)
- h.mapSpans(used)
- h.arena_used = used
+ h.setArenaUsed(used, false)
h.arena_reserved = reserved
} else {
// We haven't added this allocation to
@@ -422,12 +428,7 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
// Keep taking from our reservation.
p := h.arena_used
sysMap(unsafe.Pointer(p), n, h.arena_reserved, &memstats.heap_sys)
- h.mapBits(p + n)
- h.mapSpans(p + n)
- h.arena_used = p + n
- if raceenabled {
- racemapshadow(unsafe.Pointer(p), n)
- }
+ h.setArenaUsed(p+n, true)
if p&(_PageSize-1) != 0 {
throw("misrounded allocation in MHeap_SysAlloc")
@@ -460,15 +461,10 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
p_end := p + p_size
p += -p & (_PageSize - 1)
if p+n > h.arena_used {
- h.mapBits(p + n)
- h.mapSpans(p + n)
- h.arena_used = p + n
+ h.setArenaUsed(p+n, true)
if p_end > h.arena_end {
h.arena_end = p_end
}
- if raceenabled {
- racemapshadow(unsafe.Pointer(p), n)
- }
}
if p&(_PageSize-1) != 0 {