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.
vfs: Add prefetchFile, use it for reading ahead data blocks
For sequential-like IO workload where we read data blocks one after the other in quick succession, signalling the OS to asynchronously bring them to cache in advance can deliver significant savings in IOPS dispatched. In IOPS-bound workloads such as backup on an EBS disk, this delivers a 3x speedup. Presumably aggregate queries and compactions will be faster as well, though this hasn't been benchmarked in practice yet. This change maintains a counter for the number of data block reads performed in a singleLevelIterator, and when that count exceeds 2, a readahead system call is made on Linux. RocksDB has almost the exact same behaviour, including the same min/max readahead sizes and read count thresholds. Will address cockroachdb/cockroach#49710 when it lands in cockraoch.
- Loading branch information
Showing
5 changed files
with
120 additions
and
14 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
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,35 @@ | ||
// Copyright 2020 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. | ||
|
||
package vfs | ||
|
||
type prefetchFile struct { | ||
File | ||
fd uintptr | ||
} | ||
|
||
// Prefetch is an interface for a file that supports prefetching/readahead. | ||
type Prefetch interface { | ||
Prefetch(offset uint64, size uint64) error | ||
} | ||
|
||
// NewPrefetchFile wraps a readable file and adds a Prefetch() method on | ||
// supported platforms. | ||
func NewPrefetchFile(f File) File { | ||
if f == nil { | ||
return nil | ||
} | ||
|
||
s := &prefetchFile{ | ||
File: f, | ||
} | ||
|
||
type fd interface { | ||
Fd() uintptr | ||
} | ||
if d, ok := f.(fd); ok { | ||
s.fd = d.Fd() | ||
} | ||
return s | ||
} |
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,15 @@ | ||
// Copyright 2020 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. | ||
|
||
// +build !linux | ||
|
||
package vfs | ||
|
||
// Prefetch, on supported platforms, signals the OS to fetch the next size | ||
// bytes after offset into cache. Any subsequent reads in that range will | ||
// not issue disk IO. | ||
func (p *prefetchFile) Prefetch(offset uint64, size uint64) error { | ||
// No-op. | ||
return nil | ||
} |
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,17 @@ | ||
// Copyright 2020 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. | ||
|
||
// +build linux | ||
|
||
package vfs | ||
|
||
import "syscall" | ||
|
||
// Prefetch, on supported platforms, signals the OS to fetch the next size | ||
// bytes after offset into cache. Any subsequent reads in that range will | ||
// not issue disk IO. | ||
func (p *prefetchFile) Prefetch(offset uint64, size uint64) error { | ||
_, _, err := syscall.Syscall(syscall.SYS_READAHEAD, uintptr(p.fd), uintptr(offset), uintptr(size)) | ||
return err | ||
} |