Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReadAhead related const into optional arguments. #535

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions internal/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Expand All @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
/////////////////////////
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/goofys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import (
"runtime/debug"
)

const READAHEAD_CHUNK = uint32(20 * 1024 * 1024)

// so I don't get complains about unused imports
var ignored = logrus.DebugLevel

Expand Down