Skip to content

GODEBUG = madvdontneed = 1 does not seem to take effect #39295

Closed
@sxfworks

Description

@sxfworks

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?

Activity

davecheney

davecheney commented on May 28, 2020

@davecheney
Contributor

The GODEBUG variable is easy to get wrong, there is little validation provided so the exact invocation is critical. Can you please

  1. Provide the exact steps you used so that someone without access to your environment can reproduce them. At a minimum a screenshot, or preferably the text of the commands that you used, should be provided.
  2. How are you determining memory usage. Please be as specific as possible.
added
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on May 28, 2020
sxfworks

sxfworks commented on May 28, 2020

@sxfworks
Author

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:
image
image
image
image
⁣(3) Memory monitoring of the whole system
image

mdlayher

mdlayher commented on May 28, 2020

@mdlayher
Member

Envirment=

I see a typo in your systemd config. What happens if you fix this?

sxfworks

sxfworks commented on May 28, 2020

@sxfworks
Author

Envirment=

I see a typo in your systemd config. What happens if you fix this?

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

sxfworks commented on May 28, 2020

@sxfworks
Author

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

mdlayher commented on May 28, 2020

@mdlayher
Member

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

gopherbot commented on Nov 2, 2020

@gopherbot
Contributor

Change https://golang.org/cl/267100 mentions this issue: runtime: default to MADV_DONTNEED on Linux

doudouwyh

doudouwyh commented on Nov 21, 2020

@doudouwyh

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

mdlayher commented on Nov 21, 2020

@mdlayher
Member
locked as resolved and limited conversation to collaborators on Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @davecheney@mdlayher@gopherbot@doudouwyh@sxfworks

        Issue actions

          GODEBUG = madvdontneed = 1 does not seem to take effect · Issue #39295 · golang/go