Skip to content

Commit

Permalink
local: preallocate files on linux with fallocate(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed Sep 19, 2018
1 parent f29c604 commit 9fa8c95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/local/preallocate_other.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !windows
//+build !windows,!linux

package local

Expand Down
22 changes: 22 additions & 0 deletions backend/local/preallocate_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//+build linux

package local

import (
"os"

"golang.org/x/sys/unix"
)

// preAllocate the file for performance reasons
func preAllocate(size int64, out *os.File) error {
if size <= 0 {
return nil
}
err := unix.Fallocate(int(out.Fd()), unix.FALLOC_FL_KEEP_SIZE, 0, size)
// FIXME could be doing something here
// if err == unix.ENOSPC {
// log.Printf("No space")
// }
return err
}

0 comments on commit 9fa8c95

Please sign in to comment.