Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.10.1 linux/amd64 go version go1.12.4 linux/amd64 go version go1.13.4 linux/amd64 go version go1.14 linux/amd64 go version go1.14.3 linux/amd64
Does this issue reproduce with the latest release?
yes,it still exists
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build216433097=/tmp/go-build -gno-record-gcc-switches"
What did you do?
What did you expect to see?
The same copy of golang code is compiled with go1.10 / go1.11, and the running memory is relatively stable. After the flow pressure is stabilized, the memory drops slightly, and after compiling with go1.12 / go1.13 / go1.14, the process memory is after the sudden burst of traffic pressure, it has been going up. If you do this repeatedly, it will lead to the process because of OOM is killed, compared with the golang version, it is found that MADV_FREE was introduced after go1.12, so use GODEBUG = madvdontneed = 1 ./bin way to start the program, multiple tests still did not alleviate this problem.
What did you see instead?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
davecheney commentedon May 28, 2020
The
GODEBUG
variable is easy to get wrong, there is little validation provided so the exact invocation is critical. Can you pleasesxfworks commentedon May 28, 2020
1.I mainly control the start, stop and restart specific service file contents of the program through systemctl as follows:
[Unit]
Description=exam
After=network.target
[Service]
User=exam
Group=exam
Type=simple
ExecStartPre="ulimit -c unlimited"
Envirment="GODEBUG=madvdontneed=1"
ExecStart=/opt/bin/binary_name
PrivateTmp=true
Restart=always
[Install]





WantedBy=multi-user.target
2.I determine the memory usage rate, currently mainly through the following means:
(1) VIRT and RES in top. In the version of go1.12+, VIRT and RES are always going up and not going down
(2) Print some content in runtime.MemStats to metrics for display, the specific display is as follows:
(3) Memory monitoring of the whole system
mdlayher commentedon May 28, 2020
I see a typo in your systemd config. What happens if you fix this?
sxfworks commentedon May 28, 2020
When I use go1.12 + or higher for stress testing, the golang heap does not return to the system. Repeated stress testing will lead to OOM. I have consulted that by setting GODEBUG = madvdontneed = 1, the GC can be adjusted to return the memory To the operating system, so this environment variable is set
sxfworks commentedon May 28, 2020
When I use go1.10 / go1.11, the golang heap will be returned to the operating system, and will not be killed by the Linux system because of OOM
mdlayher commentedon May 28, 2020
I'm not sure you understand my point: "Envirment" is a misspelling of "Environment" in your systemd unit. You should fix the typo in the unit, reload the configuration, and then report back if the issue persists.
gopherbot commentedon Nov 2, 2020
Change https://golang.org/cl/267100 mentions this issue:
runtime: default to MADV_DONTNEED on Linux
runtime: default to MADV_DONTNEED on Linux
doudouwyh commentedon Nov 21, 2020
Hi, every one!
i use this to run my server, but rss still very high
GODEBUG=madvdontneed=1 ./my_server
pls tell me why, and how to use madvdontneed, thx!
go version is 1.14.2
centos7
amd64
mdlayher commentedon Nov 21, 2020
Please see https://github.com/golang/go/wiki/Questions.