advise_linux.go 449 B

12345678910111213141516171819202122232425
  1. //go:build linux && !appengine
  2. // +build linux,!appengine
  3. package msgp
  4. import (
  5. "os"
  6. "syscall"
  7. )
  8. func adviseRead(mem []byte) {
  9. syscall.Madvise(mem, syscall.MADV_SEQUENTIAL|syscall.MADV_WILLNEED)
  10. }
  11. func adviseWrite(mem []byte) {
  12. syscall.Madvise(mem, syscall.MADV_SEQUENTIAL)
  13. }
  14. func fallocate(f *os.File, sz int64) error {
  15. err := syscall.Fallocate(int(f.Fd()), 0, 0, sz)
  16. if err == syscall.ENOTSUP {
  17. return f.Truncate(sz)
  18. }
  19. return err
  20. }