mirror of
https://github.com/restic/restic.git
synced 2026-05-23 10:35:23 +00:00
Set O_NOATIME flag on Linux
Citing Kerrisk, The Linux Programming Interface:
The O_NOATIME flag is intended for use by indexing and backup
programs. Its use can significantly reduce the amount of disk
activity, because repeated disk seeks back and forth across the
disk are not required to read the contents of a file and to update
the last access time in the file’s i-node[.]
restic used to do this, but the functionality was removed along with the
fadvise call in #670.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// SetFlags tries to set the O_NOATIME flag on f, which prevents the kernel
|
||||
// from updating the atime on a read call.
|
||||
//
|
||||
// The call fails when we're not the owner of the file or root. The caller
|
||||
// should ignore the error, which is returned for testing only.
|
||||
func setFlags(f *os.File) error {
|
||||
fd := f.Fd()
|
||||
flags, err := unix.FcntlInt(fd, unix.F_GETFL, 0)
|
||||
if err == nil {
|
||||
_, err = unix.FcntlInt(fd, unix.F_SETFL, flags|unix.O_NOATIME)
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user