diff --git a/cmd/flags.go b/cmd/flags.go index 36068af6dd17..64c04d14cda9 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -181,6 +181,10 @@ func dataCacheFlags() []cli.Flag { Name: "max-readahead", Usage: "max buffering for read ahead in MiB per read session", }, + &cli.IntFlag{ + Name: "multi-block", + Usage: "number of blocks for random read ahead", + }, &cli.IntFlag{ Name: "prefetch", Value: 1, diff --git a/cmd/mount.go b/cmd/mount.go index 68bb5936e0d7..bd4952a05176 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -339,6 +339,7 @@ func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config { GetTimeout: utils.Duration(c.String("get-timeout")), PutTimeout: utils.Duration(c.String("put-timeout")), + MultiBlock: c.Int("multi-block"), MaxUpload: c.Int("max-uploads"), MaxStageWrite: c.Int("max-stage-write"), MaxRetries: c.Int("io-retries"), diff --git a/pkg/chunk/cached_store.go b/pkg/chunk/cached_store.go index 70edac800bb5..c4d7cfc01c21 100644 --- a/pkg/chunk/cached_store.go +++ b/pkg/chunk/cached_store.go @@ -561,6 +561,7 @@ type Config struct { FreeSpace float32 AutoCreate bool Compress string + MultiBlock int MaxUpload int MaxStageWrite int MaxRetries int diff --git a/pkg/vfs/reader.go b/pkg/vfs/reader.go index e8a858b50f1a..9de991c3da9b 100644 --- a/pkg/vfs/reader.go +++ b/pkg/vfs/reader.go @@ -365,11 +365,19 @@ func (f *fileReader) release() { } } +func (f *fileReader) readMargin(ahead, blklen uint64) uint64 { + if f.r.multiBlock == 0 || + blklen * f.r.multiBlock > ahead + f.r.blockSize { + return ahead + f.r.blockSize + } + return blklen * f.r.multiBlock +} + func (f *fileReader) guessSession(block *frange) int { idx := -1 var closestOff uint64 for i, ses := range f.sessions { - if ses.lastOffset > closestOff && ses.lastOffset <= block.off && block.off <= ses.lastOffset+ses.readahead+f.r.blockSize { + if ses.lastOffset > closestOff && ses.lastOffset <= block.off && block.off <= ses.lastOffset+f.readMargin(ses.readahead, block.len) { idx = i closestOff = ses.lastOffset } @@ -694,6 +702,7 @@ type dataReader struct { m meta.Meta store chunk.ChunkStore files map[Ino]*fileReader + multiBlock uint64 blockSize uint64 bufferSize int64 readAheadMax uint64 @@ -715,6 +724,7 @@ func NewDataReader(conf *Config, m meta.Meta, store chunk.ChunkStore) DataReader m: m, store: store, files: make(map[Ino]*fileReader), + multiBlock: uint64(conf.Chunk.MultiBlock), blockSize: uint64(conf.Chunk.BlockSize), bufferSize: int64(conf.Chunk.BufferSize), readAheadTotal: uint64(readAheadTotal),