Skip to content

Commit 945d07c

Browse files
authored
copr: add ballast mem to reduce the runtime overhead during execution (#53407) (#53429)
ref #52887
1 parent 9e5c591 commit 945d07c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/store/copr/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ go_library(
3535
"//pkg/util/logutil",
3636
"//pkg/util/memory",
3737
"//pkg/util/paging",
38+
"//pkg/util/size",
3839
"//pkg/util/tiflash",
3940
"//pkg/util/tiflashcompute",
4041
"//pkg/util/tracing",

pkg/store/copr/coprocessor.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"math"
2121
"net"
22+
"runtime"
2223
"strconv"
2324
"strings"
2425
"sync"
@@ -50,6 +51,7 @@ import (
5051
"github.com/pingcap/tidb/pkg/util/logutil"
5152
"github.com/pingcap/tidb/pkg/util/memory"
5253
"github.com/pingcap/tidb/pkg/util/paging"
54+
"github.com/pingcap/tidb/pkg/util/size"
5355
"github.com/pingcap/tidb/pkg/util/tracing"
5456
"github.com/pingcap/tidb/pkg/util/trxevents"
5557
"github.com/pingcap/tipb/go-tipb"
@@ -822,6 +824,10 @@ func (worker *copIteratorWorker) run(ctx context.Context) {
822824
})
823825
worker.wg.Done()
824826
}()
827+
// 16KB ballast helps grow the stack to the requirement of copIteratorWorker.
828+
// This reduces the `morestack` call during the execution of `handleTask`, thus improvement the efficiency of TiDB.
829+
// TODO: remove ballast after global pool is applied.
830+
ballast := make([]byte, 16*size.KB)
825831
for task := range worker.taskCh {
826832
respCh := worker.respChan
827833
if respCh == nil {
@@ -840,6 +846,7 @@ func (worker *copIteratorWorker) run(ctx context.Context) {
840846
return
841847
}
842848
}
849+
runtime.KeepAlive(ballast)
843850
}
844851

845852
// open starts workers and sender goroutines.

0 commit comments

Comments
 (0)