1
0
mirror of https://github.com/golang/go synced 2024-11-23 19:40:08 -07:00
go/src
Michael Anthony Knyszek 5a90306344 runtime: overhaul TestPhysicalMemoryUtilization
Currently, this test allocates many objects and relies on heap-growth
scavenging to happen unconditionally on heap-growth. However with the
new pacing system for the scavenging, this is no longer true and the
test is flaky.

So, this change overhauls TestPhysicalMemoryUtilization to check the
same aspect of the runtime, but in a much more robust way.

Firstly, it sets up a much more constrained scenario: only 5 objects are
allocated total with a maximum worst-case (i.e. the test fails) memory
footprint of about 16 MiB. The test is now aware that scavenging will
only happen if the heap growth causes us to push way past our scavenge
goal, which is based on the heap goal. So, it makes the holes in the
test much bigger and the actual retained allocations much smaller to
keep the heap goal at the heap's minimum size. It does this twice to
create exactly two unscavenged holes. Because the ratio between the size
of the "saved" objects and the "condemned" object is so small, two holes
are sufficient to create a consistent test.

Then, the test allocates one enormous object (the size of the 4 other
objects allocated, combined) with the intent that heap-growth scavenging
should kick in and scavenge the holes. The heap goal will rise after
this object is allocated, so it's very important we do all the
scavenging in a single allocation that exceeds the heap goal because
otherwise the rising heap goal could foil our test.

Finally, we check memory use relative to HeapAlloc as before. Since the
runtime should scavenge the entirety of the remaining holes,
theoretically there should be no more free and unscavenged memory.
However due to other allocations that may happen during the test we may
still see unscavenged memory, so we need to have some threshold. We keep
the current 10% threshold which, while arbitrary, is very conservative
and should easily account for any other allocations the test makes.

Before, we also had to ensure the allocations we were making looked
large relative to the size of a heap arena since newly-mapped memory was
considered unscavenged, and so that could significantly skew the test.
However, thanks to the fix for #32012 we were able to reduce memory use
to 16 MiB in the worst case.

Fixes #32010.

Change-Id: Ia38130481e292f581da7fa3289c98c99dc5394ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/177237
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-20 16:26:57 +00:00
..
archive
bufio
builtin
bytes strings, bytes: add ToValidUTF8 2019-05-01 18:31:47 +00:00
cmd internal/envcmd: print GO111MODULE when executing "go env" 2019-05-20 15:38:52 +00:00
compress
container
context context: document CancelFunc to be safe for simultaneous use by multiple goroutines 2019-05-20 16:08:56 +00:00
crypto crypto/tls: fix TestVerifyHostnameResumed 2019-05-17 18:28:37 +00:00
database/sql database/sql: fix subject of unexported func comment 2019-05-14 15:51:48 +00:00
debug all: simplify code using "gofmt -s -w" 2019-05-06 22:19:22 +00:00
encoding encoding/gob: rename encBuffer.WriteByte to writeByte 2019-05-09 18:02:19 +00:00
errors errors: update As example to include else case 2019-05-17 16:21:05 +00:00
expvar
flag
fmt fmt: support %w 2019-05-15 19:53:28 +00:00
go crypto/tls: add support for Ed25519 certificates in TLS 1.2 and 1.3 2019-05-17 16:13:45 +00:00
hash
html html/template: add support for JavaScript modules 2019-05-06 17:06:16 +00:00
image image/png: fix palette extension to handle 255 color images 2019-05-08 01:49:03 +00:00
index/suffixarray index/suffixarray: index 3-10X faster in half the memory 2019-05-13 18:50:32 +00:00
internal internal/poll: avoid memory leak in Writev 2019-05-20 01:53:24 +00:00
io
log
math math/bits: make Add and Sub fallbacks constant time 2019-05-20 01:13:27 +00:00
mime mime: update .mjs MIME type from text/ to application/javascript 2019-05-13 17:01:25 +00:00
net net/http/httptest: update docs, remove old inaccurate sentence 2019-05-20 04:22:40 +00:00
os os: pass correct environment when creating Windows processes 2019-05-16 10:24:10 +00:00
path
plugin
reflect reflect: add a test for Calling a Method of a direct interface type 2019-05-08 13:56:52 +00:00
regexp regexp: optimize for provably too short inputs 2019-05-15 15:28:22 +00:00
runtime runtime: overhaul TestPhysicalMemoryUtilization 2019-05-20 16:26:57 +00:00
sort sort: simplify bootstrap 2019-05-02 20:30:31 +00:00
strconv strconv: Document ParseFloat's special cases 2019-04-29 11:07:31 +00:00
strings strings, bytes: add ToValidUTF8 2019-05-01 18:31:47 +00:00
sync sync: update comment 2019-04-19 16:15:36 +00:00
syscall syscall: implement rawVforkSyscall for linux/ppc64x and linux/s390x 2019-05-15 18:12:10 +00:00
testdata
testing testing: callerName only needs one PC in the traceback 2019-05-17 22:32:30 +00:00
text text/template: fix truth handling of typed interface nils in if and with 2019-05-14 00:50:42 +00:00
time time: fix a typo in comments 2019-05-13 14:06:50 +00:00
unicode all: update to Unicode 11 2019-04-25 20:33:22 +00:00
unsafe
vendor net/http: update vendored, bundled x/net/http2 2019-05-16 19:56:27 +00:00
all.bash
all.bat
all.rc
bootstrap.bash bootstrap.bash: preserve file times when copying 2019-04-27 14:36:00 +00:00
buildall.bash cmd/go: run full 'go vet' during 'go test' for packages in GOROOT 2019-05-16 03:24:56 +00:00
clean.bash
clean.bat
clean.rc
cmp.bash
go.mod net/http: update vendored, bundled x/net/http2 2019-05-16 19:56:27 +00:00
go.sum net/http: update vendored, bundled x/net/http2 2019-05-16 19:56:27 +00:00
iostest.bash
make.bash cmd/go: add env -w and env -u to set and unset default env vars 2019-04-23 00:58:08 +00:00
make.bat cmd/go: add env -w and env -u to set and unset default env vars 2019-04-23 00:58:08 +00:00
Make.dist
make.rc cmd/go: add env -w and env -u to set and unset default env vars 2019-04-23 00:58:08 +00:00
naclmake.bash
nacltest.bash
race.bash
race.bat
README.vendor all: document vendoring in the standard library 2019-05-09 17:11:16 +00:00
run.bash cmd/dist: allow builders to control granularity of test/ directory sharding 2019-05-06 23:02:29 +00:00
run.bat
run.rc

Vendoring in std and cmd
========================

The Go command maintains copies of external packages needed by the
standard library in the src/vendor and src/cmd/vendor directories.

In GOPATH mode, imports of vendored packages are resolved to these
directories following normal vendor directory logic
(see golang.org/s/go15vendor).

In module mode, std and cmd are modules (defined in src/go.mod and
src/cmd/go.mod). When a package outside std or cmd is imported
by a package inside std or cmd, the import path is interpreted
as if it had a "vendor/" prefix. For example, within "crypto/tls",
an import of "golang.org/x/crypto/cryptobyte" resolves to
"vendor/golang.org/x/crypto/cryptobyte". When a package with the
same path is imported from a package outside std or cmd, it will
be resolved normally. Consequently, a binary may be built with two
copies of a package at different versions if the package is
imported normally and vendored by the standard library.

Vendored packages are internally renamed with a "vendor/" prefix
to preserve the invariant that all packages have distinct paths.
This is necessary to avoid compiler and linker conflicts. Adding
a "vendor/" prefix also maintains the invariant that standard
library packages begin with a dotless path element.

The module requirements of std and cmd do not influence version
selection in other modules. They are only considered when running
module commands like 'go get' and 'go mod vendor' from a directory
in GOROOT/src.

Maintaining vendor directories
==============================

Before updating vendor directories, ensure that module mode is enabled.
Make sure GO111MODULE=off is not set ('on' or 'auto' should work).

Requirements may be added, updated, and removed with 'go get'.
The vendor directory may be updated with 'go mod vendor'.
A typical sequence might be:

    cd src
    go get -m golang.org/x/net@latest
    go mod tidy
    go mod vendor

Use caution when passing '-u' to 'go get'. The '-u' flag updates
modules providing all transitively imported packages, not just
the target module.

Note that 'go mod vendor' only copies packages that are transitively
imported by packages in the current module. If a new package is needed,
it should be imported before running 'go mod vendor'.