From 3a375b23054bbbf4346a95d4c6d122eb79557b75 Mon Sep 17 00:00:00 2001 From: maobaolong <307499405@qq.com> Date: Fri, 10 Jul 2020 17:04:33 +0800 Subject: [PATCH 1/2] Make ReadAhead related const into optional arguments. --- api/common/config.go | 4 ++++ internal/file.go | 13 +++++-------- internal/flags.go | 16 ++++++++++++++++ internal/goofys_test.go | 2 ++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/api/common/config.go b/api/common/config.go index e4f23ad5..bf76c5ad 100644 --- a/api/common/config.go +++ b/api/common/config.go @@ -55,6 +55,10 @@ type FlagStorage struct { DebugFuse bool DebugS3 bool Foreground bool + + // Readahead + MaxReadAhead uint32 + ReadAheadChunk uint32 } func (flags *FlagStorage) GetMimeType(fileName string) (retMime *string) { diff --git a/internal/file.go b/internal/file.go index a2ccbaa7..6ab0f6b0 100644 --- a/internal/file.go +++ b/internal/file.go @@ -66,9 +66,6 @@ type FileHandle struct { keepPageCache bool // the same value we returned to OpenFile } -const MAX_READAHEAD = uint32(400 * 1024 * 1024) -const READAHEAD_CHUNK = uint32(20 * 1024 * 1024) - // NewFileHandle returns a new file handle for the given `inode` triggered by fuse // operation with the given `opMetadata` func NewFileHandle(inode *Inode, opMetadata fuseops.OpMetadata) *FileHandle { @@ -426,14 +423,14 @@ func (fh *FileHandle) readAhead(offset uint64, needAtLeast int) (err error) { existingReadahead += b.size } - readAheadAmount := MAX_READAHEAD + readAheadAmount := fh.inode.fs.flags.MaxReadAhead - for readAheadAmount-existingReadahead >= READAHEAD_CHUNK { + for readAheadAmount-existingReadahead >= fh.inode.fs.flags.ReadAheadChunk { off := offset + uint64(existingReadahead) remaining := fh.inode.Attributes.Size - off // only read up to readahead chunk each time - size := MinUInt32(readAheadAmount-existingReadahead, READAHEAD_CHUNK) + size := MinUInt32(readAheadAmount-existingReadahead, fh.inode.fs.flags.ReadAheadChunk) // but don't read past the file size = uint32(MinUInt64(uint64(size), remaining)) @@ -456,7 +453,7 @@ func (fh *FileHandle) readAhead(offset uint64, needAtLeast int) (err error) { } } - if size != READAHEAD_CHUNK { + if size != fh.inode.fs.flags.ReadAheadChunk { // that was the last remaining chunk to readahead break } @@ -543,7 +540,7 @@ func (fh *FileHandle) readFile(offset int64, buf []byte) (bytesRead int, err err fh.buffers = nil } - if !fs.flags.Cheap && fh.seqReadAmount >= uint64(READAHEAD_CHUNK) && fh.numOOORead < 3 { + if !fs.flags.Cheap && fh.seqReadAmount >= uint64(fh.inode.fs.flags.ReadAheadChunk) && fh.numOOORead < 3 { if fh.reader != nil { fh.inode.logFuse("cutover to the parallel algorithm") fh.reader.Close() diff --git a/internal/flags.go b/internal/flags.go index f18633a8..5ed859f2 100644 --- a/internal/flags.go +++ b/internal/flags.go @@ -138,6 +138,18 @@ func NewApp() (app *cli.App) { Usage: "GID owner of all inodes.", }, + cli.IntFlag{ + Name: "max-readahead", + Value: 400 * 1024 * 1024, + Usage: "max readahead size.", + }, + + cli.IntFlag{ + Name: "readahead-chunk", + Value: 20 * 1024 * 1024, + Usage: "readahead chunk size.", + }, + ///////////////////////// // S3 ///////////////////////// @@ -341,6 +353,10 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) { DebugFuse: c.Bool("debug_fuse"), DebugS3: c.Bool("debug_s3"), Foreground: c.Bool("f"), + + // ReadAhead + MaxReadAhead: uint32(c.Int("max-readahead")), + ReadAheadChunk: uint32(c.Int("readahead-chunk")), } // S3 diff --git a/internal/goofys_test.go b/internal/goofys_test.go index a51bbeb1..bbf738bb 100644 --- a/internal/goofys_test.go +++ b/internal/goofys_test.go @@ -61,6 +61,8 @@ import ( "runtime/debug" ) +const READAHEAD_CHUNK = uint32(5 * 1024 * 1024) + // so I don't get complains about unused imports var ignored = logrus.DebugLevel From b50ef2d29ddf1802e9151b406e9a5fe85258c6ea Mon Sep 17 00:00:00 2001 From: maobaolong <307499405@qq.com> Date: Fri, 17 Jul 2020 11:08:21 +0800 Subject: [PATCH 2/2] Update goofys_test.go --- internal/goofys_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/goofys_test.go b/internal/goofys_test.go index bbf738bb..776d4771 100644 --- a/internal/goofys_test.go +++ b/internal/goofys_test.go @@ -61,7 +61,7 @@ import ( "runtime/debug" ) -const READAHEAD_CHUNK = uint32(5 * 1024 * 1024) +const READAHEAD_CHUNK = uint32(20 * 1024 * 1024) // so I don't get complains about unused imports var ignored = logrus.DebugLevel