Skip to content

Commit

Permalink
Allow to use "zero-copy" write
Browse files Browse the repository at this point in the history
It can provide substantial performance benefit like 300->600 MB/s write (LOL),
but it also leads to significant performance degradation caused by inefficient
operations with the []FileBuffer inode.buffers list that grows over time.
  • Loading branch information
vitalif committed Aug 31, 2021
1 parent 66b334e commit 08f9ba4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (inode *Inode) ResizeUnlocked(newSize uint64) {
inode.Attributes.Size = newSize
}

func (fh *FileHandle) WriteFile(offset int64, data []byte) (err error) {
func (fh *FileHandle) WriteFile(offset int64, data []byte, copyData bool) (err error) {
fh.inode.logFuse("WriteFile", offset, len(data))

end := uint64(offset)+uint64(len(data))
Expand All @@ -351,7 +351,7 @@ func (fh *FileHandle) WriteFile(offset int64, data []byte) (err error) {
fh.inode.ResizeUnlocked(end)
}

allocated := fh.inode.addBuffer(uint64(offset), data, BUF_DIRTY, true)
allocated := fh.inode.addBuffer(uint64(offset), data, BUF_DIRTY, copyData)

fh.inode.lastWriteEnd = end
if fh.inode.CacheState == ST_CACHED {
Expand Down
6 changes: 5 additions & 1 deletion internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,12 @@ func (fs *Goofys) WriteFile(
}
fs.mu.RUnlock()

err = fh.WriteFile(op.Offset, op.Data)
// fuse binding leaves extra room for header, so we
// account for it when we decide whether to do "zero-copy" write
copyData := len(op.Data) < cap(op.Data)-4096
err = fh.WriteFile(op.Offset, op.Data, copyData)
err = mapAwsError(err)
op.SuppressReuse = !copyData

return
}
Expand Down

0 comments on commit 08f9ba4

Please sign in to comment.