1
0
mirror of https://github.com/golang/go synced 2024-11-12 02:20:23 -07:00

runtime: add GODEBUG=madvdontneed=1

Fixes #28466

Change-Id: I05b2e0da09394d111913963b60f2ec865c9b4744
Reviewed-on: https://go-review.googlesource.com/c/155931
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Brad Fitzpatrick 2019-01-02 18:47:06 +00:00
parent 8e6396115e
commit 22738f07c8
3 changed files with 13 additions and 1 deletions

View File

@ -89,6 +89,11 @@ It is a comma-separated list of name=val pairs setting these named variables:
released: # MB released to the system
consumed: # MB allocated from the system
madvdontneed: setting madvdontneed=1 will use MADV_DONTNEED
instead of MADV_FREE on Linux when returning memory to the
kernel. This is less efficient, but causes RSS numbers to drop
more quickly.
memprofilerate: setting memprofilerate=X will update the value of runtime.MemProfileRate.
When set to 0 memory profiling is disabled. Refer to the description of
MemProfileRate for the default value.

View File

@ -105,7 +105,12 @@ func sysUnused(v unsafe.Pointer, n uintptr) {
throw("unaligned sysUnused")
}
advise := atomic.Load(&adviseUnused)
var advise uint32
if debug.madvdontneed != 0 {
advise = _MADV_DONTNEED
} else {
advise = atomic.Load(&adviseUnused)
}
if errno := madvise(v, n, int32(advise)); advise == _MADV_FREE && errno != 0 {
// MADV_FREE was added in Linux 4.5. Fall back to MADV_DONTNEED if it is
// not supported.

View File

@ -308,6 +308,7 @@ var debug struct {
gcstoptheworld int32
gctrace int32
invalidptr int32
madvdontneed int32 // for Linux; issue 28466
sbrk int32
scavenge int32
scheddetail int32
@ -325,6 +326,7 @@ var dbgvars = []dbgVar{
{"gcstoptheworld", &debug.gcstoptheworld},
{"gctrace", &debug.gctrace},
{"invalidptr", &debug.invalidptr},
{"madvdontneed", &debug.madvdontneed},
{"sbrk", &debug.sbrk},
{"scavenge", &debug.scavenge},
{"scheddetail", &debug.scheddetail},