aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_bsd.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2019-01-23 17:33:35 +0000
committerMichael Knyszek <mknyszek@google.com>2019-03-04 18:28:52 +0000
commitabf8e355a8fe4b77009cb55f6bef11f74e6ade03 (patch)
tree736d0403899bd587f45e753d9adcbd3fcbb34e5f /src/runtime/mem_bsd.go
parent0c7cdb49d89b34baf1f407135b64fd38876823e2 (diff)
downloadgo-abf8e355a8fe4b77009cb55f6bef11f74e6ade03.tar.gz
go-abf8e355a8fe4b77009cb55f6bef11f74e6ade03.zip
runtime: use MADV_FREE_REUSABLE on darwin
Currently on darwin we use MADV_FREE, which unfortunately doesn't result in a change in the process's RSS until pages actually get kicked out, which the OS is free to do lazily (e.g. until it finds itself under memory pressure). To remedy this, we instead use MADV_FREE_REUSABLE which has similar semantics, except that it also sets a reusable bit on each page so the process's RSS gets reported more accurately. The one caveat is for every time we call MADV_FREE_REUSABLE on a region we must call MADV_FREE_REUSE to keep the kernel's accounting updated. Also, because this change requires adding new constants that only exist on darwin, it splits mem_bsd.go into mem_bsd.go and mem_darwin.go. Fixes #29844. Change-Id: Idb6421698511138a430807bcbbd1516cd57557c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/159117 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/mem_bsd.go')
-rw-r--r--src/runtime/mem_bsd.go16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/runtime/mem_bsd.go b/src/runtime/mem_bsd.go
index 796bb44223..cc70e806ea 100644
--- a/src/runtime/mem_bsd.go
+++ b/src/runtime/mem_bsd.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd nacl netbsd openbsd solaris
+// +build dragonfly freebsd nacl netbsd openbsd solaris
package runtime
@@ -42,19 +42,7 @@ func sysFault(v unsafe.Pointer, n uintptr) {
}
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
- flags := int32(_MAP_ANON | _MAP_PRIVATE)
- if raceenabled && GOOS == "darwin" {
- // Currently the race detector expects memory to live within a certain
- // range, and on Darwin 10.10 mmap is prone to ignoring hints, more so
- // than later versions and other BSDs (#26475). So, even though it's
- // potentially dangerous to MAP_FIXED, we do it in the race detection
- // case because it'll help maintain the race detector's invariants.
- //
- // TODO(mknyszek): Drop this once support for Darwin 10.10 is dropped,
- // and reconsider this when #24133 is addressed.
- flags |= _MAP_FIXED
- }
- p, err := mmap(v, n, _PROT_NONE, flags, -1, 0)
+ p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if err != 0 {
return nil
}