diff --git a/app/vmselect/netstorage/fadvise_darwin.go b/app/vmselect/netstorage/fadvise_darwin.go deleted file mode 100644 index 799544b0bf..0000000000 --- a/app/vmselect/netstorage/fadvise_darwin.go +++ /dev/null @@ -1,9 +0,0 @@ -package netstorage - -import ( - "os" -) - -func mustFadviseSequentialRead(f *os.File) { - // Do nothing :) -} diff --git a/app/vmselect/netstorage/fadvise_freebsd.go b/app/vmselect/netstorage/fadvise_freebsd.go deleted file mode 100644 index a9de5e337f..0000000000 --- a/app/vmselect/netstorage/fadvise_freebsd.go +++ /dev/null @@ -1,15 +0,0 @@ -package netstorage - -import ( - "os" - - "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" - "golang.org/x/sys/unix" -) - -func mustFadviseSequentialRead(f *os.File) { - fd := int(f.Fd()) - if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_SEQUENTIAL|unix.FADV_WILLNEED); err != nil { - logger.Panicf("FATAL: error returned from unix.Fadvise(SEQUENTIAL|WILLNEED): %s", err) - } -} diff --git a/app/vmselect/netstorage/fadvise_linux.go b/app/vmselect/netstorage/fadvise_linux.go deleted file mode 100644 index a9de5e337f..0000000000 --- a/app/vmselect/netstorage/fadvise_linux.go +++ /dev/null @@ -1,15 +0,0 @@ -package netstorage - -import ( - "os" - - "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" - "golang.org/x/sys/unix" -) - -func mustFadviseSequentialRead(f *os.File) { - fd := int(f.Fd()) - if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_SEQUENTIAL|unix.FADV_WILLNEED); err != nil { - logger.Panicf("FATAL: error returned from unix.Fadvise(SEQUENTIAL|WILLNEED): %s", err) - } -} diff --git a/app/vmselect/netstorage/tmp_blocks_file.go b/app/vmselect/netstorage/tmp_blocks_file.go index 58d9eeb777..3667d12b43 100644 --- a/app/vmselect/netstorage/tmp_blocks_file.go +++ b/app/vmselect/netstorage/tmp_blocks_file.go @@ -128,7 +128,7 @@ func (tbf *tmpBlocksFile) Finalize() error { // Hint the OS that the file is read almost sequentiallly. // This should reduce the number of disk seeks, which is important // for HDDs. - mustFadviseSequentialRead(tbf.f) + fs.MustFadviseSequentialRead(tbf.f, true) return nil } diff --git a/lib/fs/fadvise_darwin.go b/lib/fs/fadvise_darwin.go new file mode 100644 index 0000000000..feeb8a721e --- /dev/null +++ b/lib/fs/fadvise_darwin.go @@ -0,0 +1,12 @@ +package fs + +import ( + "os" +) + +// MustFadviseSequentialRead hints the OS that f is read mostly sequentially. +// +// if prefetch is set, then the OS is hinted to prefetch f data. +func MustFadviseSequentialRead(f *os.File, prefetch bool) { + // TODO: implement this properly +} diff --git a/lib/fs/fadvise_unix.go b/lib/fs/fadvise_unix.go new file mode 100644 index 0000000000..480a45b2fa --- /dev/null +++ b/lib/fs/fadvise_unix.go @@ -0,0 +1,24 @@ +// +buid linux freebsd + +package fs + +import ( + "os" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" + "golang.org/x/sys/unix" +) + +// MustFadviseSequentialRead hints the OS that f is read mostly sequentially. +// +// if prefetch is set, then the OS is hinted to prefetch f data. +func MustFadviseSequentialRead(f *os.File, prefetch bool) { + fd := int(f.Fd()) + mode := unix.FADV_SEQUENTIAL + if prefetch { + mode |= unix.FADV_WILLNEED + } + if err := unix.Fadvise(int(fd), 0, 0, mode); err != nil { + logger.Panicf("FATAL: error returned from unix.Fadvise(%d): %s", mode, err) + } +}