From 8646fe31c8266d62828ba570a794b2bf5d20996a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Bu=CC=88nemann?= Date: Sun, 1 Mar 2020 05:49:53 +0100 Subject: [PATCH] Enable readahead by default The Linux kernel and FUSE default to a readahead size of 128 KB, but because there is no default value for conf.maxReadhead, it gets completely disabled leading to huge overhead due to many page sized FUSE read requests with only 4 KB. --- fuse.go | 10 +++++++++- fuse_darwin.go | 3 +++ fuse_freebsd.go | 3 +++ fuse_linux.go | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fuse.go b/fuse.go index b774a25c..4422d649 100644 --- a/fuse.go +++ b/fuse.go @@ -232,9 +232,17 @@ func initMount(c *Conn, conf *mountConfig) error { } c.proto = proto + maxReadahead := conf.maxReadahead + if maxReadahead == 0 { + maxReadahead = defaultReadahead + } + if maxReadahead > r.MaxReadahead { + maxReadahead = r.MaxReadahead + } + s := &InitResponse{ Library: proto, - MaxReadahead: conf.maxReadahead, + MaxReadahead: maxReadahead, MaxWrite: maxWrite, Flags: InitBigWrites | conf.initFlags, } diff --git a/fuse_darwin.go b/fuse_darwin.go index b58dca97..1a974716 100644 --- a/fuse_darwin.go +++ b/fuse_darwin.go @@ -7,3 +7,6 @@ package fuse // 16MB value. See TestSetxattr16MB and // https://github.com/bazil/fuse/issues/42 const maxWrite = 16 * 1024 * 1024 + +// Default kernel readahead. +const defaultReadahead = 128 * 1024 diff --git a/fuse_freebsd.go b/fuse_freebsd.go index 4aa83a0d..2ec8bf59 100644 --- a/fuse_freebsd.go +++ b/fuse_freebsd.go @@ -4,3 +4,6 @@ package fuse // // This number is just a guess. const maxWrite = 128 * 1024 + +// Default kernel readahead. +const defaultReadahead = 128 * 1024 diff --git a/fuse_linux.go b/fuse_linux.go index 5fb96f9a..c0ae567f 100644 --- a/fuse_linux.go +++ b/fuse_linux.go @@ -5,3 +5,6 @@ package fuse // Linux 4.2.0 has been observed to cap this value at 128kB // (FUSE_MAX_PAGES_PER_REQ=32, 4kB pages). const maxWrite = 128 * 1024 + +// Default kernel readahead. +const defaultReadahead = 128 * 1024