Skip to content

Instantly share code, notes, and snippets.

@fd0

fd0/fadvise.go Secret

Created April 4, 2016 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fd0/6587a615cea63183676e2f2887d59d62 to your computer and use it in GitHub Desktop.
Save fd0/6587a615cea63183676e2f2887d59d62 to your computer and use it in GitHub Desktop.
// +build linux
package main
import (
"io"
"os"
"golang.org/x/sys/unix"
)
// POSIX_FADV_DONTNEED should be defined by the golang.org/x/sys/unix package, but isn't.
const POSIX_FADV_DONTNEED = 4
func main() {
filename := os.Args[1]
f, err := os.Create(filename)
if err != nil {
panic(err)
}
_, err = io.Copy(f, os.Stdin)
if err != nil {
panic(err)
}
err = f.Sync()
if err != nil {
panic(err)
}
err = unix.Fadvise(int(f.Fd()), 0, 0, POSIX_FADV_DONTNEED)
if err != nil {
panic(err)
}
err = f.Close()
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment