summaryrefslogtreecommitdiff
path: root/8003-runtime-add-kunpeng-malloc-optimize.patch
blob: da16ef7b38fd20c517ebf81f43c73a37145ddd08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 9feb2b8eb21c27e9ec1ab2bd45a59b7dec451d3a Mon Sep 17 00:00:00 2001
From: jinye <jinye10@huawei.com>
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