Skip to content

Commit

Permalink
Merge #115585
Browse files Browse the repository at this point in the history
115585: build: expose knob to disable GC assist r=nvanbenschoten a=nvanbenschoten

Fixes #115584.

This commit updates our patched Go runtime to expose a knob to disable the runtime's GC assist mechanism. The knob is exposed under the `GODEBUG` environment variable, and can be accessed with `GODEBUG=gcnoassist=1`.

For now, this is just meant for experimentation purposes. It will assist us as we look to reduce the impact the GC has on tail latency.

Release note: None

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
  • Loading branch information
craig[bot] and nvanbenschoten committed Dec 6, 2023
2 parents 7a85aa8 + 06bc890 commit d8f6bfd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
16 changes: 8 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ load(
go_download_sdk(
name = "go_sdk",
sdks = {
"darwin_amd64": ("go1.21.3.darwin-amd64.tar.gz", "253d8d4b32a1d7731dff1245f009362858a0c685af8f52b671dd906b2c67d78d"),
"darwin_arm64": ("go1.21.3.darwin-arm64.tar.gz", "877543c11149341e4954cb2e625deb7974e94c3c77f5f71a24d35e54cb54fb05"),
"linux_amd64": ("go1.21.3.linux-amd64.tar.gz", "3b0307b4e91d6b34870ed1d29366aba77cb864dc93b7098cdfb5d4619cb58566"),
"linux_arm64": ("go1.21.3.linux-arm64.tar.gz", "c0d2da5e1b9ff93d0e4262189e59586cc0c17c207578429f716de2d5799ba36a"),
"windows_amd64": ("go1.21.3.windows-amd64.tar.gz", "c0e2957014e72056ed1c2c080d772d7c8e96a3143f228f6b511231fc31c07593"),
"darwin_amd64": ("go1.21.3.darwin-amd64.tar.gz", "85a9bce961b9bd45d6d67e306c79052f739ea9bda99f234ef7a716129315bfc8"),
"darwin_arm64": ("go1.21.3.darwin-arm64.tar.gz", "52d8a95622bf29bb73aa49af0ff73955e034969dba46c7f439399af7adafc787"),
"linux_amd64": ("go1.21.3.linux-amd64.tar.gz", "3ff4a24c4e64b46a3ade80abdcf34b8c26704799ec2763814e68edd81142df68"),
"linux_arm64": ("go1.21.3.linux-arm64.tar.gz", "29b53edd23dbcc27fc421e9cc83a0cd81f1d5e2bf9d061da6907e8be66fff48f"),
"windows_amd64": ("go1.21.3.windows-amd64.tar.gz", "d025882e7d846d722a90ca66204b561c6650e127e338fdc22e39964995253224"),
},
urls = ["https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/{}"],
urls = ["https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/{}"],
version = "1.21.3",
)

Expand Down Expand Up @@ -641,9 +641,9 @@ distdir_repositories()
go_download_sdk(
name = "go_sdk_fips",
sdks = {
"linux_amd64": ("go1.21.3fips.linux-amd64.tar.gz", "216acc2939bf16748ec240ffe1752b442ec098bd9ac5e12ecd44db4ff77e0ab9"),
"linux_amd64": ("go1.21.3fips.linux-amd64.tar.gz", "03a3494f7b9d8a63750f72afd4f398baa723509a3c14dbff888a857ca01f0b5c"),
},
urls = ["https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/{}"],
urls = ["https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/{}"],
version = "1.21.3fips",
# In the golang-fips toolchain, FIPS-ready crypto packages are used by default, regardless of build tags.
# The boringcrypto experiment does almost nothing in this toolchain, but it does enable the use of the
Expand Down
12 changes: 6 additions & 6 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1189,12 +1189,12 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/public-bazel-artifacts/c-deps/20230718-202534/libproj_foreign.macos.20230718-202534.tar.gz": "96771a33542beb72067afcafaeb790134014e56798fa4cbe291894c4ebf8b68d",
"https://storage.googleapis.com/public-bazel-artifacts/c-deps/20230718-202534/libproj_foreign.macosarm.20230718-202534.tar.gz": "b2c60ffe1f50c6e81ba906f773b95d3a6699538d57e71749579552f4211a1e3e",
"https://storage.googleapis.com/public-bazel-artifacts/c-deps/20230718-202534/libproj_foreign.windows.20230718-202534.tar.gz": "16de1e76ee8de4bd144dc57bfde05385d086943ca1b64cc246055c8b0cd71c65",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3.darwin-amd64.tar.gz": "253d8d4b32a1d7731dff1245f009362858a0c685af8f52b671dd906b2c67d78d",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3.darwin-arm64.tar.gz": "877543c11149341e4954cb2e625deb7974e94c3c77f5f71a24d35e54cb54fb05",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3.linux-amd64.tar.gz": "3b0307b4e91d6b34870ed1d29366aba77cb864dc93b7098cdfb5d4619cb58566",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3.linux-arm64.tar.gz": "c0d2da5e1b9ff93d0e4262189e59586cc0c17c207578429f716de2d5799ba36a",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3.windows-amd64.tar.gz": "c0e2957014e72056ed1c2c080d772d7c8e96a3143f228f6b511231fc31c07593",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231019-214851/go1.21.3fips.linux-amd64.tar.gz": "216acc2939bf16748ec240ffe1752b442ec098bd9ac5e12ecd44db4ff77e0ab9",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3.darwin-amd64.tar.gz": "85a9bce961b9bd45d6d67e306c79052f739ea9bda99f234ef7a716129315bfc8",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3.darwin-arm64.tar.gz": "52d8a95622bf29bb73aa49af0ff73955e034969dba46c7f439399af7adafc787",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3.linux-amd64.tar.gz": "3ff4a24c4e64b46a3ade80abdcf34b8c26704799ec2763814e68edd81142df68",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3.linux-arm64.tar.gz": "29b53edd23dbcc27fc421e9cc83a0cd81f1d5e2bf9d061da6907e8be66fff48f",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3.windows-amd64.tar.gz": "d025882e7d846d722a90ca66204b561c6650e127e338fdc22e39964995253224",
"https://storage.googleapis.com/public-bazel-artifacts/go/20231205-160258/go1.21.3fips.linux-amd64.tar.gz": "03a3494f7b9d8a63750f72afd4f398baa723509a3c14dbff888a857ca01f0b5c",
"https://storage.googleapis.com/public-bazel-artifacts/java/railroad/rr-1.63-java8.zip": "d2791cd7a44ea5be862f33f5a9b3d40aaad9858455828ebade7007ad7113fb41",
"https://storage.googleapis.com/public-bazel-artifacts/js/rules_jest-v0.18.4.tar.gz": "d3bb833f74b8ad054e6bff5e41606ff10a62880cc99e4d480f4bdfa70add1ba7",
"https://storage.googleapis.com/public-bazel-artifacts/js/rules_js-v1.26.1.tar.gz": "08061ba5e5e7f4b1074538323576dac819f9337a0c7d75aee43afc8ae7cb6e18",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
diff --git a/src/runtime/extern.go b/src/runtime/extern.go
index 26dcf0bd52..75865d2868 100644
--- a/src/runtime/extern.go
+++ b/src/runtime/extern.go
@@ -85,6 +85,10 @@ It is a comma-separated list of name=val pairs setting these named variables:
making every garbage collection a stop-the-world event. Setting gcstoptheworld=2
also disables concurrent sweeping after the garbage collection finishes.

+ gcnoassist: setting gcnoassist=1 disables garbage collection assist, minimizing
+ garbage collection overhead for user goroutines at the expense of a higher risk
+ of out-of-memory failures with high allocation rates.
+
gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard
error at each collection, summarizing the amount of memory collected and the
length of the pause. The format of this line is subject to change. Included in
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 44479cc2be..a24ce64a24 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -1270,7 +1270,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
// Returns the G for which the assist credit was accounted.
func deductAssistCredit(size uintptr) *g {
var assistG *g
- if gcBlackenEnabled != 0 {
+ if debug.gcnoassist == 0 && gcBlackenEnabled != 0 {
// Charge the current user G for this allocation.
assistG = getg()
if assistG.m.curg != nil {
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 554a60d747..8d64ee31c8 100644
--- a/src/runtime/proc.go
Expand Down Expand Up @@ -74,6 +102,26 @@ index 554a60d747..8d64ee31c8 100644

if gcBlackenEnabled != 0 && gp.gcAssistBytes > 0 {
// Flush assist credit to the global pool. This gives
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 92a7e021ee..2796baf922 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -315,6 +315,7 @@ var debug struct {
gcpacertrace int32
gcshrinkstackoff int32
gcstoptheworld int32
+ gcnoassist int32
gctrace int32
invalidptr int32
madvdontneed int32 // for Linux; issue 28466
@@ -348,6 +349,7 @@ var dbgvars = []*dbgVar{
{name: "gcpacertrace", value: &debug.gcpacertrace},
{name: "gcshrinkstackoff", value: &debug.gcshrinkstackoff},
{name: "gcstoptheworld", value: &debug.gcstoptheworld},
+ {name: "gcnoassist", value: &debug.gcnoassist},
{name: "gctrace", value: &debug.gctrace},
{name: "invalidptr", value: &debug.invalidptr},
{name: "madvdontneed", value: &debug.madvdontneed},
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index f4c76abd1c..57672bd8c5 100644
--- a/src/runtime/runtime2.go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ GOVERS=$(go/bin/go env GOVERSION)
GOOS=$(go/bin/go env GOOS)
GOARCH=$(go/bin/go env GOARCH)
tar cf - go | gzip -9 > /artifacts/$GOVERS.$GOOS-$GOARCH.tar.gz

sha256sum /artifacts/$GOVERS.$GOOS-$GOARCH.tar.gz

0 comments on commit d8f6bfd

Please sign in to comment.