From 6358cf3d4781cbaa32502ffa9b090cec920c524d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 23 Dec 2019 23:16:11 +0200 Subject: [PATCH] app/vmselect/netstorage: move MustAdviseSequentialRead to lib/fs --- app/vmselect/netstorage/fadvise_darwin.go | 9 -------- app/vmselect/netstorage/fadvise_freebsd.go | 15 -------------- app/vmselect/netstorage/fadvise_linux.go | 15 -------------- app/vmselect/netstorage/tmp_blocks_file.go | 2 +- lib/fs/fadvise_darwin.go | 12 +++++++++++ lib/fs/fadvise_unix.go | 24 ++++++++++++++++++++++ 6 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 app/vmselect/netstorage/fadvise_darwin.go delete mode 100644 app/vmselect/netstorage/fadvise_freebsd.go delete mode 100644 app/vmselect/netstorage/fadvise_linux.go create mode 100644 lib/fs/fadvise_darwin.go create mode 100644 lib/fs/fadvise_unix.go 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) + } +}