From c011d627084ba593a3aca5cdabfcd39ce37dbc6a Mon Sep 17 00:00:00 2001 From: Changxin Miao Date: Mon, 14 Oct 2024 11:23:28 +0800 Subject: [PATCH] Allow user to disable readahead by setting `max-readahead` smaller than blocksize (#5229) Signed-off-by: Changxin Miao --- cmd/flags.go | 2 +- pkg/vfs/reader.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/flags.go b/cmd/flags.go index 3856fd816c59..27d1752f9de2 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -174,7 +174,7 @@ func dataCacheFlags() []cli.Flag { }, &cli.StringFlag{ Name: "max-readahead", - Usage: "max buffering for read ahead in MiB", + Usage: "max buffering for read ahead in MiB per read session", }, &cli.IntFlag{ Name: "prefetch", diff --git a/pkg/vfs/reader.go b/pkg/vfs/reader.go index 832bcda09d3f..9c89731952e0 100644 --- a/pkg/vfs/reader.go +++ b/pkg/vfs/reader.go @@ -418,7 +418,7 @@ func (f *fileReader) checkReadahead(block *frange) int { seqdata := ses.total readahead := ses.readahead used := uint64(atomic.LoadInt64(&readBufferUsed)) - if readahead == 0 && (block.off == 0 || seqdata > block.len) { // begin with read-ahead turned on + if readahead == 0 && f.r.blockSize <= f.r.readAheadMax && (block.off == 0 || seqdata > block.len) { // begin with read-ahead turned on ses.readahead = f.r.blockSize } else if readahead < f.r.readAheadMax && seqdata >= readahead && f.r.readAheadTotal-used > readahead*4 { ses.readahead *= 2