From a07d376fb111944cdd74521446caa6f3ba43b0d4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 28 Jul 2022 18:14:04 +0100 Subject: [PATCH] vfs: reduce memory usage by re-ordering commonly used structures --- vfs/file.go | 8 ++++---- vfs/read.go | 10 +++++----- vfs/vfscache/item.go | 2 +- vfs/write.go | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vfs/file.go b/vfs/file.go index 2d3199f13..4431c6cc5 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -39,19 +39,19 @@ type File struct { inode uint64 // inode number - read only size int64 // size of file - read and written with atomic int64 - must be 64 bit aligned + muRW sync.Mutex // synchronize RWFileHandle.openPending(), RWFileHandle.close() and File.Remove + mu sync.RWMutex // protects the following d *Dir // parent directory dPath string // path of parent directory. NB dir rename means all Files are flushed o fs.Object // NB o may be nil if file is being written leaf string // leaf name of the object writers []Handle // writers for this file - nwriters int32 // len(writers) which is read/updated with atomic pendingModTime time.Time // will be applied once o becomes available, i.e. after file was written pendingRenameFun func(ctx context.Context) error // will be run/renamed after all writers close - appendMode bool // file was opened with O_APPEND sys atomic.Value // user defined info to be attached here - - muRW sync.Mutex // synchronize RWFileHandle.openPending(), RWFileHandle.close() and File.Remove + nwriters int32 // len(writers) which is read/updated with atomic + appendMode bool // file was opened with O_APPEND } // newFile creates a new File diff --git a/vfs/read.go b/vfs/read.go index 4a5658ead..bfe4b2d5c 100644 --- a/vfs/read.go +++ b/vfs/read.go @@ -21,18 +21,18 @@ type ReadFileHandle struct { done func(ctx context.Context, err error) mu sync.Mutex cond sync.Cond // cond lock for out of sequence reads - closed bool // set if handle has been closed r *accounting.Account - readCalled bool // set if read has been called size int64 // size of the object (0 for unknown length) offset int64 // offset of read of o roffset int64 // offset of Read() calls - noSeek bool - sizeUnknown bool // set if size of source is not known file *File hash *hash.MultiHasher - opened bool remote string + closed bool // set if handle has been closed + readCalled bool // set if read has been called + noSeek bool + sizeUnknown bool // set if size of source is not known + opened bool } // Check interfaces diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.go index 883bc9bde..5d606f21e 100644 --- a/vfs/vfscache/item.go +++ b/vfs/vfscache/item.go @@ -63,10 +63,10 @@ type Item struct { downloaders *downloaders.Downloaders // a record of the downloaders in action - may be nil o fs.Object // object we are caching - may be nil fd *os.File // handle we are using to read and write to the file - modified bool // set if the file has been modified since the last Open info Info // info about the file to persist to backing store writeBackID writeback.Handle // id of any writebacks in progress pendingAccesses int // number of threads - cache reset not allowed if not zero + modified bool // set if the file has been modified since the last Open beingReset bool // cache cleaner is resetting the cache file, access not allowed } diff --git a/vfs/write.go b/vfs/write.go index 25fa4fbf6..4556ebe3e 100644 --- a/vfs/write.go +++ b/vfs/write.go @@ -16,16 +16,16 @@ type WriteFileHandle struct { baseHandle mu sync.Mutex cond sync.Cond // cond lock for out of sequence writes - closed bool // set if handle has been closed remote string pipeWriter *io.PipeWriter o fs.Object result chan error file *File - writeCalled bool // set the first time Write() is called offset int64 - opened bool flags int + closed bool // set if handle has been closed + writeCalled bool // set the first time Write() is called + opened bool truncated bool }