Commit 22738f07 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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: 's avatarAustin Clements <austin@google.com>
parent 8e639611
......@@ -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.
......
......@@ -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.
......
......@@ -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},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment