aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/debug/garbage_test.go
AgeCommit message (Collapse)Author
2025-04-11all: use built-in min, max functionsMarcel Meyer
Change-Id: Ie76ebb556d635068342747f3f91dd7dc423df531 GitHub-Last-Rev: aea61fb3a054e6bd24f4684f90fb353d5682cd0b GitHub-Pull-Request: golang/go#73340 Reviewed-on: https://go-review.googlesource.com/c/go/+/664677 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-04-19runtime: manage huge pages explicitlyMichael Anthony Knyszek
This change makes it so that on Linux the Go runtime explicitly marks page heap memory as either available to be backed by hugepages or not using heuristics based on density. The motivation behind this change is twofold: 1. In default Linux configurations, khugepaged can recoalesce hugepages even after the scavenger breaks them up, resulting in significant overheads for small heaps when their heaps shrink. 2. The Go runtime already has some heuristics about this, but those heuristics appear to have bit-rotted and result in haphazard hugepage management. Unlucky (but otherwise fairly dense) regions of memory end up not backed by huge pages while sparse regions end up accidentally marked MADV_HUGEPAGE and are not later broken up by the scavenger, because it already got the memory it needed from more dense sections (this is more likely to happen with small heaps that go idle). In this change, the runtime uses a new policy: 1. Mark all new memory MADV_HUGEPAGE. 2. Track whether each page chunk (4 MiB) became dense during the GC cycle. Mark those MADV_HUGEPAGE, and hide them from the scavenger. 3. If a chunk is not dense for 1 full GC cycle, make it visible to the scavenger. 4. The scavenger marks a chunk MADV_NOHUGEPAGE before it scavenges it. This policy is intended to try and back memory that is a good candidate for huge pages (high occupancy) with huge pages, and give memory that is not (low occupancy) to the scavenger. Occupancy is defined not just by occupancy at any instant of time, but also occupancy in the near future. It's generally true that by the end of a GC cycle the heap gets quite dense (from the perspective of the page allocator). Because we want scavenging and huge page management to happen together (the right time to MADV_NOHUGEPAGE is just before scavenging in order to break up huge pages and keep them that way) and the cost of applying MADV_HUGEPAGE and MADV_NOHUGEPAGE is somewhat high, the scavenger avoids releasing memory in dense page chunks. All this together means the scavenger will now more generally release memory on a ~1 GC cycle delay. Notably this has implications for scavenging to maintain the memory limit and the runtime/debug.FreeOSMemory API. This change makes it so that in these cases all memory is visible to the scavenger regardless of sparseness and delays the page allocator in re-marking this memory with MADV_NOHUGEPAGE for around 1 GC cycle to mitigate churn. The end result of this change should be little-to-no performance difference for dense heaps (MADV_HUGEPAGE works a lot like the default unmarked state) but should allow the scavenger to more effectively take back fragments of huge pages. The main risk here is churn, because MADV_HUGEPAGE usually forces the kernel to immediately back memory with a huge page. That's the reason for the large amount of hysteresis (1 full GC cycle) and why the definition of high density is 96% occupancy. Fixes #55328. Change-Id: I8da7998f1a31b498a9cc9bc662c1ae1a6bf64630 Reviewed-on: https://go-review.googlesource.com/c/go/+/436395 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-11runtime/debug: make TestFreeOSMemory more robustMichael Anthony Knyszek
FreeOSMemory relies on the function FreeOSMemory increasing HeapReleased as opposed to the background scavenger, because it reads memory stats *after* the free of a large allocation. However, before that even happens, the background scavenger can swoop in and release all that memory, making it appear as if FreeOSMemory didn't do anything. This change modifies the test to just make sure that the large allocation's memory is returned to the OS *somehow*, by the end of the test. It doesn't really care which happens. It also increases the size of that large allocation to increase the likelihood that the test isn't relying 100% on the background scavenger, and that FreeOSMemory is doing some of the work. Fixes #49478. Change-Id: Ief1d839753720ebb88cbb616c46302293ee2d19c Reviewed-on: https://go-review.googlesource.com/c/go/+/363414 Reviewed-by: David Chase <drchase@google.com> Trust: Michael Knyszek <mknyszek@google.com>
2017-04-24runtime/debug: mark TestSetGCPercent as flakyBrad Fitzpatrick
Updates #20076 Change-Id: I4eb98abbb49174cc6433e5da2c3660893ef88fd1 Reviewed-on: https://go-review.googlesource.com/41615 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-21runtime/debug: increase threshold on TestSetGCPercentAustin Clements
Currently TestSetGCPercent checks that NextGC is within 10 MB of the expected value. For some reason it's much noisier on some of the builders. To get these passing again, raise the threshold to 20 MB. Change-Id: I14e64025660d782d81ff0421c1eb898f416e11fe Reviewed-on: https://go-review.googlesource.com/41374 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2017-04-21runtime/debug: don't trigger a GC on SetGCPercentAustin Clements
Currently SetGCPercent forces a GC in order to recompute GC pacing. Since we can now recompute pacing on the fly using gcSetTriggerRatio, change SetGCPercent (really runtime.setGCPercent) to go through gcSetTriggerRatio and not trigger a GC. Fixes #19076. Change-Id: Ib30d7ab1bb3b55219535b9f238108f3d45a1b522 Reviewed-on: https://go-review.googlesource.com/39835 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Rick Hudson <rlh@golang.org>
2017-04-21runtime/debug: expand SetGCPercent testAustin Clements
The current SetGCPercent test is, shall we say, minimal. Expand it to check that the GC target is actually computed and updated correctly. For #19076. Change-Id: I6e9b2ee0ef369f22f72e43b58d89e9f1e1b73b1b Reviewed-on: https://go-review.googlesource.com/39834 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rick Hudson <rlh@golang.org>
2016-11-13all: fix vet nitsJosh Bleecher Snyder
Fixes these vet complaints: net/error_test.go:254: unrecognized printf flag for verb 'T': '#' os/os_test.go:1067: arg mt for printf verb %d of wrong type: time.Time runtime/debug/garbage_test.go:83: arg dt for printf verb %d of wrong type: time.Time Change-Id: I0e986712a4b083b75fb111e687e424d06a85a47b Reviewed-on: https://go-review.googlesource.com/33167 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-20runtime/debug: avoid overflow in SetMaxThreadsAlberto Donizetti
Fixes #16076 Change-Id: I91fa87b642592ee4604537dd8c3197cd61ec8b31 Reviewed-on: https://go-review.googlesource.com/31516 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-06runtime/debug: enable TestFreeOSMemory on all archesAustin Clements
TestFreeOSMemory was disabled on many arches because of issue #9993. Since that's been fixed, enable the test everywhere. Change-Id: I298c38c3e04128d9c8a1f558980939d5699bea03 Reviewed-on: https://go-review.googlesource.com/27403 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-18testing: use debug.SetTraceback("all") to show all goroutines at test timeoutRuss Cox
Fixes #13681. Change-Id: I308930f4d9200fbe0f09cd08c38392ca1bb0db67 Reviewed-on: https://go-review.googlesource.com/18044 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2015-11-12runtime/debug: skip TestFreeOSMemory for mips64{,le}Yao Zhang
Change-Id: I419f3b8bf1bddffd4a775b0cd7b98f0239fe19cb Reviewed-on: https://go-review.googlesource.com/14458 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-28runtime: use 64k page rounding on arm64Russ Cox
Fixes #11886. Change-Id: I9392fd2ef5951173ae275b3ab42db4f8bd2e1d7a Reviewed-on: https://go-review.googlesource.com/12747 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-13runtime/debug: disable arm64 test for issue 9993David Crawshaw
Like other arm64 platforms, darwin/arm64 has a different physical page size to logical page size so it is running into issue 9993. I hope it can be fixed for Go 1.5, but for now it is demonstrating the same bug as the other skipped os+arch combinations. Change-Id: Iedaf9afe56d6954bb4391b6e843d81742a75a00c Reviewed-on: https://go-review.googlesource.com/8814 Reviewed-by: Minux Ma <minux@golang.org>
2015-02-26runtime/debug: fix nacl buildDave Cheney
Disable the test properly on nacl systems, tested on nacl/amd64p32. Change-Id: Iffe210be4f9c426bfc47f2dd3a8f0c6b5a398cc3 Reviewed-on: https://go-review.googlesource.com/6093 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-26runtime: disable scavenger on 64k page size kernelsDave Cheney
Update #9993 If the physical page size of the machine is larger than the logical heap size, for example 8k logical, 64k physical, then madvise(2) will round up the requested amount to a 64k boundary and may discard pages close to the page being madvised. This patch disables the scavenger in these situations, which at the moment is only ppc64 and ppc64le systems. NaCl also uses a 64k page size, but it's not clear if it is affected by this problem. Change-Id: Ib897f8d3df5bd915ddc0b510f2fd90a30ef329ca Reviewed-on: https://go-review.googlesource.com/6091 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2014-10-28runtime: add PauseEnd array to MemStats and GCStatsJens Frederich
Fixes #8787. LGTM=rsc R=rsc, dvyukov CC=golang-codereviews https://golang.org/cl/153670043
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.