"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: reduce memory use by embedding sync.Cond
Nick Craig-Woode749bc58f4e5
diff --git a/vfs/read.go b/vfs/read.goindex 88bcabfce..4a5658ead 100644--- a/vfs/read.go+++ b/vfs/read.go@@ -20,7 +20,7 @@ type ReadFileHandle struct {baseHandledone func(ctx context.Context, err error)mu sync.Mutex- cond *sync.Cond // cond lock for out of sequence reads+ cond sync.Cond // cond lock for out of sequence readsclosed bool // set if handle has been closedr *accounting.AccountreadCalled bool // set if read has been called@@ -63,7 +63,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {size: nonNegative(o.Size()),sizeUnknown: o.Size() < 0,}- fh.cond = sync.NewCond(&fh.mu)+ fh.cond = sync.Cond{L: &fh.mu}return fh, nil}@@ -267,7 +267,7 @@ func (fh *ReadFileHandle) readAt(p []byte, off int64) (n int, err error) {maxBuf = len(p)}if gap := off - fh.offset; gap > 0 && gap < int64(8*maxBuf) {- waitSequential("read", fh.remote, fh.cond, fh.file.VFS().Opt.ReadWait, &fh.offset, off)+ waitSequential("read", fh.remote, &fh.cond, fh.file.VFS().Opt.ReadWait, &fh.offset, off)}doSeek := off != fh.offsetif doSeek && fh.noSeek {diff --git a/vfs/vfscache/cache.go b/vfs/vfscache/cache.goindex 9c7feb646..8e5209a79 100644--- a/vfs/vfscache/cache.go+++ b/vfs/vfscache/cache.go@@ -52,7 +52,7 @@ type Cache struct {avFn AddVirtualFn // if set, can be called to add dir entriesmu sync.Mutex // protects the following variables- cond *sync.Cond // cond lock for synchronous cache cleaning+ cond sync.Cond // cond lock for synchronous cache cleaningitem map[string]*Item // files/directories in the cacheerrItems map[string]error // items in error stateused int64 // total size of files in the cache@@ -139,7 +139,7 @@ func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options, avFn AddVir// Create a channel for cleaner to be kicked upon out of space conc.kick = make(chan struct{}, 1)- c.cond = sync.NewCond(&c.mu)+ c.cond = sync.Cond{L: &c.mu}go c.cleaner(ctx)diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.goindex 2c8145870..883bc9bde 100644--- a/vfs/vfscache/item.go+++ b/vfs/vfscache/item.go@@ -57,7 +57,7 @@ type Item struct {// read onlyc *Cache // cache this is part ofmu sync.Mutex // protect the variables- cond *sync.Cond // synchronize with cache cleaner+ cond sync.Cond // synchronize with cache cleanername string // name in the VFSopens int // number of times file is opendownloaders *downloaders.Downloaders // a record of the downloaders in action - may be nil@@ -138,7 +138,7 @@ func newItem(c *Cache, name string) (item *Item) {ATime: now,},}- item.cond = sync.NewCond(&item.mu)+ item.cond = sync.Cond{L: &item.mu}// check the cache file existsosPath := c.toOSPath(name)fi, statErr := os.Stat(osPath)diff --git a/vfs/write.go b/vfs/write.goindex 24595e041..25fa4fbf6 100644--- a/vfs/write.go+++ b/vfs/write.go@@ -15,7 +15,7 @@ import (type WriteFileHandle struct {baseHandlemu sync.Mutex- cond *sync.Cond // cond lock for out of sequence writes+ cond sync.Cond // cond lock for out of sequence writesclosed bool // set if handle has been closedremote stringpipeWriter *io.PipeWriter@@ -43,7 +43,7 @@ func newWriteFileHandle(d *Dir, f *File, remote string, flags int) (*WriteFileHaresult: make(chan error, 1),file: f,}- fh.cond = sync.NewCond(&fh.mu)+ fh.cond = sync.Cond{L: &fh.mu}fh.file.addWriter(fh)return fh, nil}@@ -130,7 +130,7 @@ func (fh *WriteFileHandle) writeAt(p []byte, off int64) (n int, err error) {return 0, ECLOSED}if fh.offset != off {- waitSequential("write", fh.remote, fh.cond, fh.file.VFS().Opt.WriteWait, &fh.offset, off)+ waitSequential("write", fh.remote, &fh.cond, fh.file.VFS().Opt.WriteWait, &fh.offset, off)}if fh.offset != off {fs.Errorf(fh.remote, "WriteFileHandle.Write: can't seek in file without --vfs-cache-mode >= writes")