From f2b4d57068d13b6dc3de2ccc6550675d11d34cfa Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 1 Jul 2016 23:29:31 +0200 Subject: fusefrontend: coalesce grows in Truncate() We were growing the file block-by-block which was pretty inefficient. We now coalesce all the grows into a single Ftruncate. Also simplifies the code! Simplistic benchmark: Before: $ time truncate -s 1000M foo real 0m0.568s After: $ time truncate -s 1000M foo real 0m0.205s --- internal/fusefrontend/file_holes.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'internal/fusefrontend/file_holes.go') diff --git a/internal/fusefrontend/file_holes.go b/internal/fusefrontend/file_holes.go index 46a5865..1d9a5fb 100644 --- a/internal/fusefrontend/file_holes.go +++ b/internal/fusefrontend/file_holes.go @@ -22,6 +22,10 @@ func (f *file) createsHole(plainSize uint64, off int64) bool { func (f *file) zeroPad(plainSize uint64) fuse.Status { lastBlockLen := plainSize % f.contentEnc.PlainBS() missing := f.contentEnc.PlainBS() - lastBlockLen + if missing == 0 { + // Already block-aligned + return fuse.OK + } pad := make([]byte, missing) tlog.Debug.Printf("zeroPad: Writing %d bytes\n", missing) _, status := f.doWrite(pad, int64(plainSize)) -- cgit v1.2.3