Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txnkv: introduce ballast object to batch-get worker #1535

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions txnkv/txnsnapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"context"
"fmt"
"math"
"runtime"
"sync"
"sync/atomic"
"time"
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
Loading