mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Remove fadvise
This commit removes the use of FADV_DONTNEED, which also purges active cached pages for other processes.
This commit is contained in:
parent
b1ed74eb43
commit
b56bde3f61
@ -157,11 +157,6 @@ func writeToTempfile(tempdir string, p []byte) (filename string, err error) {
|
||||
return "", errors.Wrap(err, "Syncn")
|
||||
}
|
||||
|
||||
err = fs.ClearCache(tmpfile)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "ClearCache")
|
||||
}
|
||||
|
||||
err = tmpfile.Close()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Close")
|
||||
|
@ -125,6 +125,11 @@ func Create(name string) (*os.File, error) {
|
||||
return os.Create(fixpath(name))
|
||||
}
|
||||
|
||||
// Open opens a file for reading.
|
||||
func Open(name string) (File, error) {
|
||||
return os.Open(fixpath(name))
|
||||
}
|
||||
|
||||
// OpenFile is the generalized open call; most users will use Open
|
||||
// or Create instead. It opens the named file with specified flag
|
||||
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
|
||||
|
@ -1,59 +0,0 @@
|
||||
// +build linux,go1.4
|
||||
|
||||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"restic/errors"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Open opens a file for reading, without updating the atime and without caching data on read.
|
||||
func Open(name string) (File, error) {
|
||||
file, err := os.OpenFile(name, os.O_RDONLY|syscall.O_NOATIME, 0)
|
||||
if os.IsPermission(errors.Cause(err)) {
|
||||
file, err = os.OpenFile(name, os.O_RDONLY, 0)
|
||||
}
|
||||
return &nonCachingFile{File: file}, err
|
||||
}
|
||||
|
||||
// nonCachingFile wraps an *os.File and calls fadvise() to instantly forget
|
||||
// data that has been read or written.
|
||||
type nonCachingFile struct {
|
||||
*os.File
|
||||
readOffset int64
|
||||
}
|
||||
|
||||
func (f *nonCachingFile) Read(p []byte) (int, error) {
|
||||
n, err := f.File.Read(p)
|
||||
|
||||
if n > 0 {
|
||||
ferr := unix.Fadvise(int(f.File.Fd()), f.readOffset, int64(n), unix.FADV_DONTNEED)
|
||||
|
||||
f.readOffset += int64(n)
|
||||
|
||||
if err == nil {
|
||||
err = ferr
|
||||
}
|
||||
}
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
// ClearCache syncs and then removes the file's content from the OS cache.
|
||||
func ClearCache(file File) error {
|
||||
f, ok := file.(*os.File)
|
||||
if !ok {
|
||||
panic("ClearCache called for file not *os.File")
|
||||
}
|
||||
|
||||
err := f.Sync()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return unix.Fadvise(int(f.Fd()), 0, 0, unix.FADV_DONTNEED)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// +build !linux !go1.4
|
||||
|
||||
package fs
|
||||
|
||||
import "os"
|
||||
|
||||
// Open opens a file for reading.
|
||||
func Open(name string) (File, error) {
|
||||
return os.OpenFile(fixpath(name), os.O_RDONLY, 0)
|
||||
}
|
||||
|
||||
// ClearCache syncs and then removes the file's content from the OS cache.
|
||||
func ClearCache(f File) error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user