diff --git a/pkg/store/copr/BUILD.bazel b/pkg/store/copr/BUILD.bazel index 35a3ea4c8adab..e342644c14a12 100644 --- a/pkg/store/copr/BUILD.bazel +++ b/pkg/store/copr/BUILD.bazel @@ -35,6 +35,7 @@ go_library( "//pkg/util/logutil", "//pkg/util/memory", "//pkg/util/paging", + "//pkg/util/size", "//pkg/util/tiflash", "//pkg/util/tiflashcompute", "//pkg/util/tracing", diff --git a/pkg/store/copr/coprocessor.go b/pkg/store/copr/coprocessor.go index ff8770cc8d7f1..8896394bdeefa 100644 --- a/pkg/store/copr/coprocessor.go +++ b/pkg/store/copr/coprocessor.go @@ -19,6 +19,7 @@ import ( "fmt" "math" "net" + "runtime" "strconv" "strings" "sync" @@ -50,6 +51,7 @@ import ( "github.com/pingcap/tidb/pkg/util/logutil" "github.com/pingcap/tidb/pkg/util/memory" "github.com/pingcap/tidb/pkg/util/paging" + "github.com/pingcap/tidb/pkg/util/size" "github.com/pingcap/tidb/pkg/util/tracing" "github.com/pingcap/tidb/pkg/util/trxevents" "github.com/pingcap/tipb/go-tipb" @@ -822,6 +824,10 @@ func (worker *copIteratorWorker) run(ctx context.Context) { }) worker.wg.Done() }() + // 16KB ballast helps grow the stack to the requirement of copIteratorWorker. + // This reduces the `morestack` call during the execution of `handleTask`, thus improvement the efficiency of TiDB. + // TODO: remove ballast after global pool is applied. + ballast := make([]byte, 16*size.KB) for task := range worker.taskCh { respCh := worker.respChan if respCh == nil { @@ -840,6 +846,7 @@ func (worker *copIteratorWorker) run(ctx context.Context) { return } } + runtime.KeepAlive(ballast) } // open starts workers and sender goroutines.