Skip to content

Commit 50128a2

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent c370835 commit 50128a2

File tree

5 files changed

+693
-10
lines changed

5 files changed

+693
-10
lines changed

src/runtime/_mkmalloc/mkmalloc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ func inline(config generatorConfig) []byte {
254254
}
255255

256256
// Write out the package and import declarations.
257-
out.WriteString("// Code generated by mkmalloc.go; DO NOT EDIT.\n\n")
257+
out.WriteString("// Code generated by mkmalloc.go; DO NOT EDIT.\n")
258+
out.WriteString("// See overview in malloc_stubs.go.\n\n")
258259
out.WriteString("package " + f.Name.Name + "\n\n")
259260
for _, importDecl := range importDecls {
260261
out.Write(mustFormatNode(fset, importDecl))

src/runtime/malloc.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ const sizeSpecializedMallocEnabled = goexperiment.SizeSpecializedMalloc && GOOS
10941094
// implementation and the corresponding allocation-related changes: the experiment must be
10951095
// enabled, and none of the memory sanitizers should be enabled. We allow the race detector,
10961096
// in contrast to sizeSpecializedMallocEnabled.
1097+
// TODO(thepudds): it would be nice to check Valgrind integration, though there are some hints
1098+
// there might not be any canned tests in tree for Go's integration with Valgrind.
10971099
const runtimeFreegcEnabled = goexperiment.RuntimeFreegc && !asanenabled && !msanenabled && !valgrindenabled
10981100

10991101
// Allocate an object of size bytes.
@@ -1966,10 +1968,15 @@ const (
19661968
// or roughly when the liveness analysis of the compiler
19671969
// would otherwise have determined ptr's object is reclaimable by the GC.
19681970
func freegc(ptr unsafe.Pointer, size uintptr, noscan bool) bool {
1969-
if !runtimeFreegcEnabled || sizeSpecializedMallocEnabled || !reusableSize(size) {
1970-
// TODO(thepudds): temporarily disable freegc with SizeSpecializedMalloc until we finish integrating.
1971+
if !runtimeFreegcEnabled || !reusableSize(size) {
19711972
return false
19721973
}
1974+
if sizeSpecializedMallocEnabled && !noscan {
1975+
// TODO(thepudds): temporarily disable freegc with SizeSpecializedMalloc for pointer types
1976+
// until we finish integrating.
1977+
return false
1978+
}
1979+
19731980
if ptr == nil {
19741981
throw("freegc nil")
19751982
}

0 commit comments

Comments
 (0)