forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sstable: reduce block cache fragmentation
Previously, the sstable writer contained heuristics to flush sstable blocks when the size reached a certain threshold. In CRDB this is defined as 32KiB. However, when these blocks are loaded into memory additional metadata is allocated with the block causing the allocation to go beyond this threshold. Since CRDB uses jemalloc, these allocations use a 40KiB size class which leads to internal fragmentation and higher memory usage. This commit decrements the block size threshold to reduce internal memory fragmentation. Informs: cockroachdb#999.
- Loading branch information
1 parent
c34894c
commit 458a389
Showing
10 changed files
with
80 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use | ||
// of this source code is governed by a BSD-style license that can be found in | ||
// the LICENSE file. | ||
|
||
//go:build ((!invariants && !tracing) || race) && cgo | ||
// +build !invariants,!tracing race | ||
// +build cgo | ||
|
||
package cache | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/cockroachdb/pebble/internal/manual" | ||
) | ||
|
||
// ValueMetadataSize denotes the number of bytes of metadata allocated for a | ||
// cache entry. | ||
const ValueMetadataSize = int(unsafe.Sizeof(Value{})) | ||
|
||
func newValue(n int) *Value { | ||
if n == 0 { | ||
return nil | ||
} | ||
|
||
// When we're not performing leak detection, the lifetime of the returned | ||
// Value is exactly the lifetime of the backing buffer and we can manually | ||
// allocate both. | ||
b := manual.New(ValueMetadataSize + n) | ||
v := (*Value)(unsafe.Pointer(&b[0])) | ||
v.buf = b[ValueMetadataSize:] | ||
v.ref.init(1) | ||
return v | ||
} | ||
|
||
func (v *Value) free() { | ||
// When we're not performing leak detection, the Value and buffer were | ||
// allocated contiguously. | ||
n := ValueMetadataSize + cap(v.buf) | ||
buf := (*[manual.MaxArrayLen]byte)(unsafe.Pointer(v))[:n:n] | ||
v.buf = nil | ||
manual.Free(buf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters