]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: add GODEBUG=madvdontneed=1
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 2 Jan 2019 18:47:06 +0000 (18:47 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 2 Jan 2019 20:55:53 +0000 (20:55 +0000)
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>
src/runtime/extern.go
src/runtime/mem_linux.go
src/runtime/runtime1.go

index 5e11eadb92a842b26c1279a804124a47eb2ddf3a..af858a331f63cbd8a41a82191d82f9f53d919f8b 100644 (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.
index 845f72ded2c1634f3a6eb4b1779a8569a5541ee2..1e45ed6301568f5a0b3d5a7b7c6d69d121557911 100644 (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.
index 8b8f4dcb1e98066269c4ce0dff642a3c45bf6b82..c5667e73adc4d739bb2a3db684409ccd37da05f1 100644 (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},