diff options
| author | Srdjan Petrovic <spetrovic@google.com> | 2015-04-16 14:32:18 -0700 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2015-04-24 16:53:26 +0000 |
| commit | 6ad33be2d9d6b24aa741b3007a4bcd52db222c41 (patch) | |
| tree | 904764e1cb4fcf37f7bd4022c43eae35d45b6bfb /src/runtime/malloc.go | |
| parent | 8566979972d51236c37b2823d2c0d52c6efe5406 (diff) | |
| download | go-6ad33be2d9d6b24aa741b3007a4bcd52db222c41.tar.xz | |
runtime: implement xadduintptr and update system mstats using it
The motivation is that sysAlloc/Free() currently aren't safe to be
called without a valid G, because arm's xadd64() uses locks that require
a valid G.
The solution here was proposed by Dmitry Vyukov: use xadduintptr()
instead of xadd64(), until arm can support xadd64 on all of its
architectures (not a trivial task for arm).
Change-Id: I250252079357ea2e4360e1235958b1c22051498f
Reviewed-on: https://go-review.googlesource.com/9002
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
| -rw-r--r-- | src/runtime/malloc.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 4a2d3e3cac..5896e74e91 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -790,7 +790,7 @@ var globalAlloc struct { // There is no associated free operation. // Intended for things like function/type/debug-related persistent data. // If align is 0, uses default align (currently 8). -func persistentalloc(size, align uintptr, stat *uint64) unsafe.Pointer { +func persistentalloc(size, align uintptr, sysStat *uint64) unsafe.Pointer { const ( chunk = 256 << 10 maxBlock = 64 << 10 // VM reservation granularity is 64K on windows @@ -811,7 +811,7 @@ func persistentalloc(size, align uintptr, stat *uint64) unsafe.Pointer { } if size >= maxBlock { - return sysAlloc(size, stat) + return sysAlloc(size, sysStat) } mp := acquirem() @@ -840,9 +840,9 @@ func persistentalloc(size, align uintptr, stat *uint64) unsafe.Pointer { unlock(&globalAlloc.mutex) } - if stat != &memstats.other_sys { - xadd64(stat, int64(size)) - xadd64(&memstats.other_sys, -int64(size)) + if sysStat != &memstats.other_sys { + mSysStatInc(sysStat, size) + mSysStatDec(&memstats.other_sys, size) } return p } |
