aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorthepudds <thepudds1460@gmail.com>2025-11-09 09:24:22 -0500
committert hepudds <thepudds1460@gmail.com>2025-11-14 14:23:16 -0800
commit50128a21541e3fd712ad717a223aaa109cb86d43 (patch)
tree984e45288bdebd7dd2533a8ab62c4154cec244cf /src/runtime/malloc.go
parentc3708350a417a3149bf9191878c3ad945063d439 (diff)
downloadgo-50128a21541e3fd712ad717a223aaa109cb86d43.tar.xz
runtime: support runtime.freegc in size-specialized mallocs for noscan objects
This CL is part of a set of CLs that attempt to reduce how much work the GC must do. See the design in https://go.dev/design/74299-runtime-freegc This CL updates the smallNoScanStub stub in malloc_stubs.go to reuse heap objects that have been freed by runtime.freegc calls, and generates the corresponding size-specialized code in malloc_generated.go. This CL only adds support in the specialized mallocs for noscan heap objects (objects without pointers). A later CL handles objects with pointers. While we are here, we leave a couple of breadcrumbs in mkmalloc.go on how to do the generation. Updates #74299 Change-Id: I2657622601a27211554ee862fce057e101767a70 Reviewed-on: https://go-review.googlesource.com/c/go/+/715761 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 13f5fc3081..d49dacaf68 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -1094,6 +1094,8 @@ const sizeSpecializedMallocEnabled = goexperiment.SizeSpecializedMalloc && GOOS
// implementation and the corresponding allocation-related changes: the experiment must be
// enabled, and none of the memory sanitizers should be enabled. We allow the race detector,
// in contrast to sizeSpecializedMallocEnabled.
+// TODO(thepudds): it would be nice to check Valgrind integration, though there are some hints
+// there might not be any canned tests in tree for Go's integration with Valgrind.
const runtimeFreegcEnabled = goexperiment.RuntimeFreegc && !asanenabled && !msanenabled && !valgrindenabled
// Allocate an object of size bytes.
@@ -1966,10 +1968,15 @@ const (
// or roughly when the liveness analysis of the compiler
// would otherwise have determined ptr's object is reclaimable by the GC.
func freegc(ptr unsafe.Pointer, size uintptr, noscan bool) bool {
- if !runtimeFreegcEnabled || sizeSpecializedMallocEnabled || !reusableSize(size) {
- // TODO(thepudds): temporarily disable freegc with SizeSpecializedMalloc until we finish integrating.
+ if !runtimeFreegcEnabled || !reusableSize(size) {
return false
}
+ if sizeSpecializedMallocEnabled && !noscan {
+ // TODO(thepudds): temporarily disable freegc with SizeSpecializedMalloc for pointer types
+ // until we finish integrating.
+ return false
+ }
+
if ptr == nil {
throw("freegc nil")
}