Commit 66ff48dd authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make max write tunable.

parent be2df608
...@@ -213,6 +213,10 @@ type MountOptions struct { ...@@ -213,6 +213,10 @@ type MountOptions struct {
// controls the allowed number of requests that relate to // controls the allowed number of requests that relate to
// async I/O. Concurrency for synchronous I/O is not limited. // async I/O. Concurrency for synchronous I/O is not limited.
MaxBackground int MaxBackground int
// Write size to use. If 0, use default. This number is
// capped at the kernel maximum.
MaxWrite int
} }
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation. // DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
......
...@@ -9,11 +9,8 @@ import ( ...@@ -9,11 +9,8 @@ import (
) )
const ( const (
// bufSize should be a power of two to minimize lossage in // The kernel caps writes at 128k.
// BufferPool. The minimum is 8k, but it doesn't cost anything to MAX_KERNEL_WRITE = 128 * 1024
// use a much larger buffer.
bufSize = (1 << 16)
maxRead = bufSize - PAGESIZE
) )
// MountState contains the logic for reading from the FUSE device and // MountState contains the logic for reading from the FUSE device and
...@@ -53,7 +50,18 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -53,7 +50,18 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error {
MaxBackground: _DEFAULT_BACKGROUND_TASKS, MaxBackground: _DEFAULT_BACKGROUND_TASKS,
} }
} }
me.opts = opts o := *opts
if o.MaxWrite < 0 {
o.MaxWrite = 0
}
if o.MaxWrite == 0 {
o.MaxWrite = 1 << 16
}
if o.MaxWrite > MAX_KERNEL_WRITE {
o.MaxWrite = MAX_KERNEL_WRITE
}
opts = &o
me.opts = &o
optStrs := opts.Options optStrs := opts.Options
if opts.AllowOther { if opts.AllowOther {
...@@ -120,7 +128,7 @@ func (me *MountState) BufferPoolStats() string { ...@@ -120,7 +128,7 @@ func (me *MountState) BufferPoolStats() string {
func (me *MountState) newRequest() *request { func (me *MountState) newRequest() *request {
return &request{ return &request{
status: OK, status: OK,
inputBuf: me.buffers.AllocBuffer(bufSize), inputBuf: me.buffers.AllocBuffer(uint32(me.opts.MaxWrite + 4096)),
} }
} }
......
...@@ -86,7 +86,7 @@ func doInit(state *MountState, req *request) { ...@@ -86,7 +86,7 @@ func doInit(state *MountState, req *request) {
Minor: FUSE_KERNEL_MINOR_VERSION, Minor: FUSE_KERNEL_MINOR_VERSION,
MaxReadAhead: input.MaxReadAhead, MaxReadAhead: input.MaxReadAhead,
Flags: state.kernelSettings.Flags, Flags: state.kernelSettings.Flags,
MaxWrite: maxRead, MaxWrite: uint32(state.opts.MaxWrite),
CongestionThreshold: uint16(state.opts.MaxBackground * 3 / 4), CongestionThreshold: uint16(state.opts.MaxBackground * 3 / 4),
MaxBackground: uint16(state.opts.MaxBackground), MaxBackground: uint16(state.opts.MaxBackground),
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment