From 9feb2b8eb21c27e9ec1ab2bd45a59b7dec451d3a Mon Sep 17 00:00:00 2001 From: jinye Date: Tue, 5 Aug 2025 20:26:54 +0800 Subject: [PATCH] runtime:add kunpeng malloc optimize --- src/internal/goexperiment/exp_prefetchmalloc_off.go | 8 ++++++++ src/internal/goexperiment/exp_prefetchmalloc_on.go | 8 ++++++++ src/internal/goexperiment/flags.go | 3 +++ src/runtime/malloc.go | 6 ++++++ 4 files changed, 25 insertions(+) create mode 100644 src/internal/goexperiment/exp_prefetchmalloc_off.go create mode 100644 src/internal/goexperiment/exp_prefetchmalloc_on.go diff --git a/src/internal/goexperiment/exp_prefetchmalloc_off.go b/src/internal/goexperiment/exp_prefetchmalloc_off.go new file mode 100644 index 00000000..c0b645ff --- /dev/null +++ b/src/internal/goexperiment/exp_prefetchmalloc_off.go @@ -0,0 +1,8 @@ +// Code generated by mkconsts.go. DO NOT EDIT. + +//go:build !goexperiment.prefetchmalloc + +package goexperiment + +const PrefetchMalloc = false +const PrefetchMallocInt = 0 diff --git a/src/internal/goexperiment/exp_prefetchmalloc_on.go b/src/internal/goexperiment/exp_prefetchmalloc_on.go new file mode 100644 index 00000000..c6a08728 --- /dev/null +++ b/src/internal/goexperiment/exp_prefetchmalloc_on.go @@ -0,0 +1,8 @@ +// Code generated by mkconsts.go. DO NOT EDIT. + +//go:build experiment.prefetchmalloc + +package goexperiment + +const PrefetchMalloc = true +const PrefetchMallocInt = 1 diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go index 948ed5c8..04ea20a9 100644 --- a/src/internal/goexperiment/flags.go +++ b/src/internal/goexperiment/flags.go @@ -128,4 +128,7 @@ type Flags struct { // Synctest enables the testing/synctest package. Synctest bool + + // Kunpeng malloc prefetch optimization. + PrefetchMalloc bool } diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 73d663f7..a8cac5b0 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -102,6 +102,7 @@ package runtime import ( "internal/goarch" + "internal/goexperiment" "internal/goos" "internal/runtime/atomic" "internal/runtime/math" @@ -1092,6 +1093,11 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer { if debug.malloc { postMallocgcDebug(x, elemsize, typ) } + + if goexperiment.PrefetchMalloc { + sys.Prefetch(uintptr(unsafe.Add(x, size))) + } + return x } -- 2.33.0