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