From 1ca8bba538bee177eca7d4eaf2e11e385e9d7fce Mon Sep 17 00:00:00 2001 From: ddrid Date: Sat, 12 Oct 2024 19:53:21 +0800 Subject: [PATCH] cmd/mount: add `max-readahead` option to set the max buffer of each readahead (#5225) --- cmd/flags.go | 4 ++++ cmd/mount.go | 1 + pkg/vfs/reader.go | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/flags.go b/cmd/flags.go index cd2773045364..3856fd816c59 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -172,6 +172,10 @@ func dataCacheFlags() []cli.Flag { Value: "300M", Usage: "total read/write buffering in MiB", }, + &cli.StringFlag{ + Name: "max-readahead", + Usage: "max buffering for read ahead in MiB", + }, &cli.IntFlag{ Name: "prefetch", Value: 1, diff --git a/cmd/mount.go b/cmd/mount.go index 9d669441b847..0a502db9a6df 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -341,6 +341,7 @@ func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config { Writeback: c.Bool("writeback"), Prefetch: c.Int("prefetch"), BufferSize: utils.ParseBytes(c, "buffer-size", 'M'), + Readahead: int(utils.ParseBytes(c, "max-readahead", 'M')), UploadLimit: utils.ParseMbps(c, "upload-limit") * 1e6 / 8, DownloadLimit: utils.ParseMbps(c, "download-limit") * 1e6 / 8, UploadDelay: utils.Duration(c.String("upload-delay")), diff --git a/pkg/vfs/reader.go b/pkg/vfs/reader.go index fcc66f989fdc..832bcda09d3f 100644 --- a/pkg/vfs/reader.go +++ b/pkg/vfs/reader.go @@ -702,7 +702,7 @@ func NewDataReader(conf *Config, m meta.Meta, store chunk.ChunkStore) DataReader readAheadTotal = int(conf.Chunk.BufferSize / 10 * 8) // 80% of total buffer } if conf.Chunk.Readahead > 0 { - readAheadMax = conf.Chunk.Readahead + readAheadMax = utils.Min(conf.Chunk.Readahead, readAheadTotal) } r := &dataReader{ m: m,