Skip to content

Commit

Permalink
txnkv: introduce ballast object to batch-get worker (#1535)
Browse files Browse the repository at this point in the history
 

Signed-off-by: zyguan <[email protected]>
  • Loading branch information
zyguan authored Dec 25, 2024
1 parent f2266d6 commit e0415dc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions txnkv/txnsnapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"bytes"
"context"
"math"
"runtime"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -321,6 +322,14 @@ func appendBatchKeysBySize(b []batchKeys, region locate.RegionVerID, keys [][]by
return b
}

//go:noinline
func growStackForBatchGetWorker() {
// A batch get worker typically needs 8KB stack space. So we pre-allocate 4KB here to let the stack grow to 8KB
// directly (instead of 2KB to 4KB to 8KB).
var ballast [4096]byte
runtime.KeepAlive(ballast[:])
}

func (s *KVSnapshot) batchGetKeysByRegions(bo *retry.Backoffer, keys [][]byte, readTier int, collectF func(k, v []byte)) error {
defer func(start time.Time) {
if s.IsInternal() {
Expand Down Expand Up @@ -355,6 +364,7 @@ func (s *KVSnapshot) batchGetKeysByRegions(bo *retry.Backoffer, keys [][]byte, r
for _, batch1 := range batches {
batch := batch1
go func() {
growStackForBatchGetWorker()
backoffer, cancel := bo.Fork()
defer cancel()
ch <- s.batchGetSingleRegion(backoffer, batch, readTier, collectF)
Expand Down

0 comments on commit e0415dc

Please sign in to comment.