2021-07-26 13:09:12 +02:00
|
|
|
//go:build linux || freebsd
|
2019-12-24 19:59:02 +01:00
|
|
|
// +build linux freebsd
|
2019-12-23 22:16:11 +01:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-01-30 14:03:24 +01:00
|
|
|
"fmt"
|
2019-12-23 22:16:11 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2020-01-30 14:03:24 +01:00
|
|
|
func fadviseSequentialRead(f *os.File, prefetch bool) error {
|
2019-12-23 22:16:11 +01:00
|
|
|
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 {
|
2020-06-30 21:58:18 +02:00
|
|
|
return fmt.Errorf("error returned from unix.Fadvise(%d): %w", mode, err)
|
2019-12-23 22:16:11 +01:00
|
|
|
}
|
2020-01-30 14:03:24 +01:00
|
|
|
return nil
|
2019-12-23 22:16:11 +01:00
|
|
|
}
|