]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: support MADV_DONTNEED on the BSDs and Solaris/Illumos
authorTobias Klauser <tklauser@distanz.ch>
Mon, 29 Aug 2022 11:29:43 +0000 (13:29 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 2 Sep 2022 17:48:16 +0000 (17:48 +0000)
Like on Linux, use GODEBUG=madvdontneed=1 to enable madvise with
MADV_DONTNEED instead of MADV_FREE.

Based on previous work by Marcelo Araujo in CL 181498.

Fixes #32519

Change-Id: Ib49faf05c42a65591b90e75f663146f213030529
Reviewed-on: https://go-review.googlesource.com/c/go/+/266937
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
22 files changed:
src/runtime/defs1_netbsd_386.go
src/runtime/defs1_netbsd_amd64.go
src/runtime/defs1_netbsd_arm.go
src/runtime/defs1_netbsd_arm64.go
src/runtime/defs1_solaris_amd64.go
src/runtime/defs_dragonfly.go
src/runtime/defs_dragonfly_amd64.go
src/runtime/defs_freebsd.go
src/runtime/defs_freebsd_386.go
src/runtime/defs_freebsd_amd64.go
src/runtime/defs_freebsd_arm.go
src/runtime/defs_freebsd_arm64.go
src/runtime/defs_netbsd.go
src/runtime/defs_openbsd.go
src/runtime/defs_openbsd_386.go
src/runtime/defs_openbsd_amd64.go
src/runtime/defs_openbsd_arm.go
src/runtime/defs_openbsd_arm64.go
src/runtime/defs_openbsd_mips64.go
src/runtime/defs_solaris.go
src/runtime/extern.go
src/runtime/mem_bsd.go

index b6e47a008d142176b6803f38edb55dc647b5fc4e..33ce63cd378e76b60dc54d67490d0c43340f5424 100644 (file)
@@ -20,7 +20,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index b8292fa3cce79425ca71c587553c90c86652d9e9..b87833be65cd970f3e53b638cc60e2b135ec9d28 100644 (file)
@@ -20,7 +20,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index d2cb4865b68b2443be53428f29c0d1de5b82c8b0..9cb680e360dcfa6e6cc6f0d0a0a0a906c1a8d657 100644 (file)
@@ -20,7 +20,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 7776fe1d99734ada8d463810ffa6321937e56d0b..1c05ce6ad8194bb222c25ed13eb98518626a7436 100644 (file)
@@ -20,7 +20,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 3c13f333315aa68fad6b151865d0502d116372d4..003cd1c42c00ba376fdee389b56a7edc0254e790 100644 (file)
@@ -23,7 +23,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x8
        _SA_RESTART = 0x4
index 952163b5558ee5421017dbaacf74eecb934c5fc4..f67835692c084c3d27248bd503e4ffe5458f8dba 100644 (file)
@@ -44,7 +44,8 @@ const (
        MAP_PRIVATE = C.MAP_PRIVATE
        MAP_FIXED   = C.MAP_FIXED
 
-       MADV_FREE = C.MADV_FREE
+       MADV_DONTNEED = C.MADV_DONTNEED
+       MADV_FREE     = C.MADV_FREE
 
        SA_SIGINFO = C.SA_SIGINFO
        SA_RESTART = C.SA_RESTART
index 4358c1e0c2beb927d1db07ddc1d31638ba432cd2..7ab5fecb9024422d8b9cdd3e02916bac053743e5 100644 (file)
@@ -23,7 +23,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 3fbd580ac51eea824945018975afbe217960dffa..c4204ae0e792d72dd4cbf3bb397047794f14db4d 100644 (file)
@@ -62,7 +62,8 @@ const (
        MAP_PRIVATE = C.MAP_PRIVATE
        MAP_FIXED   = C.MAP_FIXED
 
-       MADV_FREE = C.MADV_FREE
+       MADV_DONTNEED = C.MADV_DONTNEED
+       MADV_FREE     = C.MADV_FREE
 
        SA_SIGINFO = C.SA_SIGINFO
        SA_RESTART = C.SA_RESTART
index ff4dcfa5fe87cbcf3739d05a9d9b1af4fefb2928..35af133bdda99dfb79a16e5ebe912c5e155d8eed 100644 (file)
@@ -31,7 +31,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index f537c898e4277dad469177ca13db88f184d8a626..791c4d1d0317f603287af99e1ec45e25222eff1d 100644 (file)
@@ -31,7 +31,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 2e20ae7d78406825a4bc002a876a8b02bb6504db..9ab49c276ae0271444a4b06f3d2c587fea6f2457 100644 (file)
@@ -31,7 +31,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 1838108fdb31e8582f5717ba31cc251ee27421e3..9d8e2430746230813bc2cb6e83e2807658a38705 100644 (file)
@@ -31,7 +31,8 @@ const (
        _MAP_PRIVATE = 0x2
        _MAP_FIXED   = 0x10
 
-       _MADV_FREE = 0x5
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x5
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 6b084c06b57654f213052b1fb01705308240d902..865b94600069ebc85d13bd80a7c67e99fd5fc8ab 100644 (file)
@@ -46,7 +46,8 @@ const (
        MAP_PRIVATE = C.MAP_PRIVATE
        MAP_FIXED   = C.MAP_FIXED
 
-       MADV_FREE = C.MADV_FREE
+       MADV_DONTNEED = C.MADV_DONTNEED
+       MADV_FREE     = C.MADV_FREE
 
        SA_SIGINFO = C.SA_SIGINFO
        SA_RESTART = C.SA_RESTART
index cbf53eb9eff571465239f09b75eebe6a1d0f537c..4161e216db69830e8cd935ebba927c6283990b26 100644 (file)
@@ -48,7 +48,8 @@ const (
        MAP_FIXED   = C.MAP_FIXED
        MAP_STACK   = C.MAP_STACK
 
-       MADV_FREE = C.MADV_FREE
+       MADV_DONTNEED = C.MADV_DONTNEED
+       MADV_FREE     = C.MADV_FREE
 
        SA_SIGINFO = C.SA_SIGINFO
        SA_RESTART = C.SA_RESTART
index 35c559bb454a60563126eca738342d1d3a17031c..72a66ae084cec380760ff81a746270e008c25bd0 100644 (file)
@@ -23,7 +23,8 @@ const (
        _MAP_FIXED   = 0x10
        _MAP_STACK   = 0x4000
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index d7432daeddf13cd438731b4bc61f00c150713fc2..b1e8dca359db1d3d151d04a8535c4bf32dbdb215 100644 (file)
@@ -23,7 +23,8 @@ const (
        _MAP_FIXED   = 0x10
        _MAP_STACK   = 0x4000
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 471b3063fb18a692bc7cbf81b819040c23387304..ba6b2c17bfc6ddfa3a2567bea8e6311d0f1cde7a 100644 (file)
@@ -23,7 +23,8 @@ const (
        _MAP_FIXED   = 0x10
        _MAP_STACK   = 0x4000
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index 5300ab087c667964614677646df429467f95d24b..13d2e95a86b1727a7bd57aa74bcd77265868dff3 100644 (file)
@@ -24,7 +24,8 @@ const (
        _MAP_FIXED   = 0x10
        _MAP_STACK   = 0x4000
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index a8789ef451d4f3da7967fdf2b2728bd67ed0aed0..c0bc766d8ff7940a8715a2890c9ee38159322bac 100644 (file)
@@ -30,7 +30,8 @@ const (
        _MAP_FIXED   = 0x10
        _MAP_STACK   = 0x4000
 
-       _MADV_FREE = 0x6
+       _MADV_DONTNEED = 0x4
+       _MADV_FREE     = 0x6
 
        _SA_SIGINFO = 0x40
        _SA_RESTART = 0x2
index f626498525290b3c06680eda11d47aab9d6a65f5..bb89eec1bf53df967fb5218aba97cb3833a1f52e 100644 (file)
@@ -53,7 +53,8 @@ const (
        MAP_PRIVATE = C.MAP_PRIVATE
        MAP_FIXED   = C.MAP_FIXED
 
-       MADV_FREE = C.MADV_FREE
+       MADV_DONTNEED = C.MADV_DONTNEED
+       MADV_FREE     = C.MADV_FREE
 
        SA_SIGINFO = C.SA_SIGINFO
        SA_RESTART = C.SA_RESTART
index 531c07cf3d9887c6a958e8bf0c2c39e160505fac..3a48588aeca2fa727856a39c863e9c33f3a99927 100644 (file)
@@ -118,7 +118,10 @@ It is a comma-separated list of name=val pairs setting these named variables:
        madvdontneed: setting madvdontneed=0 will use MADV_FREE
        instead of MADV_DONTNEED on Linux when returning memory to the
        kernel. This is more efficient, but means RSS numbers will
-       drop only when the OS is under memory pressure.
+       drop only when the OS is under memory pressure. On the BSDs and
+       Illumos/Solaris, setting madvdontneed=1 will use MADV_DONTNEED instead
+       of MADV_FREE. 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
index 782465ae26284e67a919ccca03292fc55553b7d9..6c5edb17c232ee4014948f8cb16d256ae904af76 100644 (file)
@@ -23,7 +23,11 @@ func sysAllocOS(n uintptr) unsafe.Pointer {
 }
 
 func sysUnusedOS(v unsafe.Pointer, n uintptr) {
-       madvise(v, n, _MADV_FREE)
+       if debug.madvdontneed != 0 {
+               madvise(v, n, _MADV_DONTNEED)
+       } else {
+               madvise(v, n, _MADV_FREE)
+       }
 }
 
 func sysUsedOS(v unsafe.Pointer, n uintptr) {