From 4e9e1ca0f76f745862ba2dddcf939811a8467437 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 30 Sep 2019 00:11:01 +0300 Subject: [PATCH] app/vmselect/netstorage: hint the OS that tmpBlocksFile is read almost sequentially This became the case after b7ee2e7af265b86f7c40fdcd942fef4d93c53c40 . --- app/vmselect/netstorage/fadvise_darwin.go | 2 +- app/vmselect/netstorage/fadvise_freebsd.go | 6 +++--- app/vmselect/netstorage/fadvise_linux.go | 6 +++--- app/vmselect/netstorage/tmp_blocks_file.go | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/vmselect/netstorage/fadvise_darwin.go b/app/vmselect/netstorage/fadvise_darwin.go index d219d232b..799544b0b 100644 --- a/app/vmselect/netstorage/fadvise_darwin.go +++ b/app/vmselect/netstorage/fadvise_darwin.go @@ -4,6 +4,6 @@ import ( "os" ) -func mustFadviseRandomRead(f *os.File) { +func mustFadviseSequentialRead(f *os.File) { // Do nothing :) } diff --git a/app/vmselect/netstorage/fadvise_freebsd.go b/app/vmselect/netstorage/fadvise_freebsd.go index 4bbbf132a..a9de5e337 100644 --- a/app/vmselect/netstorage/fadvise_freebsd.go +++ b/app/vmselect/netstorage/fadvise_freebsd.go @@ -7,9 +7,9 @@ import ( "golang.org/x/sys/unix" ) -func mustFadviseRandomRead(f *os.File) { +func mustFadviseSequentialRead(f *os.File) { fd := int(f.Fd()) - if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_RANDOM|unix.FADV_WILLNEED); err != nil { - logger.Panicf("FATAL: error returned from unix.Fadvise(RANDOM|WILLNEED): %s", err) + 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 index 4bbbf132a..a9de5e337 100644 --- a/app/vmselect/netstorage/fadvise_linux.go +++ b/app/vmselect/netstorage/fadvise_linux.go @@ -7,9 +7,9 @@ import ( "golang.org/x/sys/unix" ) -func mustFadviseRandomRead(f *os.File) { +func mustFadviseSequentialRead(f *os.File) { fd := int(f.Fd()) - if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_RANDOM|unix.FADV_WILLNEED); err != nil { - logger.Panicf("FATAL: error returned from unix.Fadvise(RANDOM|WILLNEED): %s", err) + 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 4e23f03fc..58d9eeb77 100644 --- a/app/vmselect/netstorage/tmp_blocks_file.go +++ b/app/vmselect/netstorage/tmp_blocks_file.go @@ -125,7 +125,10 @@ func (tbf *tmpBlocksFile) Finalize() error { if _, err := tbf.f.Seek(0, 0); err != nil { logger.Panicf("FATAL: cannot seek to the start of file: %s", err) } - mustFadviseRandomRead(tbf.f) + // 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) return nil }