Skip to content

Commit

Permalink
storage: discard memory in pebbleMVCCScanner before putting in pool
Browse files Browse the repository at this point in the history
Previously we would clear fields that can consume significant
memory, like pebbleResults, after getting from the pool. Now this
is done before the put, so that we don't retain memory
unnecessarily.

Informs cockroachdb#64906

Release note: None
  • Loading branch information
sumeerbhola committed May 18, 2021
1 parent 2840908 commit de0cc5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/storage/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func mvccGet(
}

mvccScanner := pebbleMVCCScannerPool.Get().(*pebbleMVCCScanner)
defer pebbleMVCCScannerPool.Put(mvccScanner)
defer mvccScanner.release()

// MVCCGet is implemented as an MVCCScan where we retrieve a single key. We
// specify an empty key for the end key which will ensure we don't retrieve a
Expand Down Expand Up @@ -2381,7 +2381,7 @@ func mvccScanToBytes(
}

mvccScanner := pebbleMVCCScannerPool.Get().(*pebbleMVCCScanner)
defer pebbleMVCCScannerPool.Put(mvccScanner)
defer mvccScanner.release()

*mvccScanner = pebbleMVCCScanner{
parent: iter,
Expand Down
8 changes: 8 additions & 0 deletions pkg/storage/pebble_mvcc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ var pebbleMVCCScannerPool = sync.Pool{
},
}

func (p *pebbleMVCCScanner) release() {
// Discard most memory references before placing in pool.
*p = pebbleMVCCScanner{
keyBuf: p.keyBuf,
}
pebbleMVCCScannerPool.Put(p)
}

// init sets bounds on the underlying pebble iterator, and initializes other
// fields not set by the calling method.
func (p *pebbleMVCCScanner) init(txn *roachpb.Transaction) {
Expand Down

0 comments on commit de0cc5c

Please sign in to comment.