Commit 5bb5947a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Allow buffer pool to be specified in MountOptions.

parent ddad1bed
...@@ -232,6 +232,9 @@ type MountOptions struct { ...@@ -232,6 +232,9 @@ type MountOptions struct {
// file system implements extended attributes, and you are not // file system implements extended attributes, and you are not
// interested in security labels. // interested in security labels.
IgnoreSecurityLabels bool // ignoring labels should be provided as a fusermount mount option. IgnoreSecurityLabels bool // ignoring labels should be provided as a fusermount mount option.
// If given, use this buffer pool instead of the global one.
Buffers BufferPool
} }
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation. // DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
......
...@@ -32,9 +32,6 @@ type MountState struct { ...@@ -32,9 +32,6 @@ type MountState struct {
// Dump debug info onto stdout. // Dump debug info onto stdout.
Debug bool Debug bool
// For efficient reads and writes.
buffers *BufferPoolImpl
latencies *LatencyMap latencies *LatencyMap
opts *MountOptions opts *MountOptions
...@@ -66,6 +63,9 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -66,6 +63,9 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
} }
} }
o := *opts o := *opts
if o.Buffers == nil {
o.Buffers = defaultBufferPool
}
if o.MaxWrite < 0 { if o.MaxWrite < 0 {
o.MaxWrite = 0 o.MaxWrite = 0
} }
...@@ -136,7 +136,6 @@ func NewMountState(fs RawFileSystem) *MountState { ...@@ -136,7 +136,6 @@ func NewMountState(fs RawFileSystem) *MountState {
ms := new(MountState) ms := new(MountState)
ms.mountPoint = "" ms.mountPoint = ""
ms.fileSystem = fs ms.fileSystem = fs
ms.buffers = NewBufferPool()
return ms return ms
} }
...@@ -155,7 +154,7 @@ func (ms *MountState) OperationCounts() map[string]int { ...@@ -155,7 +154,7 @@ func (ms *MountState) OperationCounts() map[string]int {
} }
func (ms *MountState) BufferPoolStats() string { func (ms *MountState) BufferPoolStats() string {
s := ms.buffers.String() s := ms.opts.Buffers.String()
var r int var r int
ms.reqMu.Lock() ms.reqMu.Lock()
...@@ -230,7 +229,7 @@ func (ms *MountState) returnRequest(req *request) { ...@@ -230,7 +229,7 @@ func (ms *MountState) returnRequest(req *request) {
ms.recordStats(req) ms.recordStats(req)
if req.bufferPoolOutputBuf != nil { if req.bufferPoolOutputBuf != nil {
ms.buffers.FreeBuffer(req.bufferPoolOutputBuf) ms.opts.Buffers.FreeBuffer(req.bufferPoolOutputBuf)
req.bufferPoolOutputBuf = nil req.bufferPoolOutputBuf = nil
} }
...@@ -330,9 +329,9 @@ func (ms *MountState) AllocOut(req *request, size uint32) []byte { ...@@ -330,9 +329,9 @@ func (ms *MountState) AllocOut(req *request, size uint32) []byte {
return req.bufferPoolOutputBuf return req.bufferPoolOutputBuf
} }
if req.bufferPoolOutputBuf != nil { if req.bufferPoolOutputBuf != nil {
ms.buffers.FreeBuffer(req.bufferPoolOutputBuf) ms.opts.Buffers.FreeBuffer(req.bufferPoolOutputBuf)
} }
req.bufferPoolOutputBuf = ms.buffers.AllocBuffer(size) req.bufferPoolOutputBuf = ms.opts.Buffers.AllocBuffer(size)
return req.bufferPoolOutputBuf return req.bufferPoolOutputBuf
} }
...@@ -470,3 +469,8 @@ func (ms *MountState) writeEntryNotify(parent uint64, name string) Status { ...@@ -470,3 +469,8 @@ func (ms *MountState) writeEntryNotify(parent uint64, name string) Status {
} }
return result return result
} }
var defaultBufferPool BufferPool
func init() {
defaultBufferPool = NewBufferPool()
}
...@@ -33,7 +33,12 @@ func TestMemoryPressure(t *testing.T) { ...@@ -33,7 +33,12 @@ func TestMemoryPressure(t *testing.T) {
CheckSuccess(err) CheckSuccess(err)
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
o := &FileSystemOptions{PortableInodes: true} o := &FileSystemOptions{PortableInodes: true}
state, _, err := MountNodeFileSystem(dir, nfs, o)
conn := NewFileSystemConnector(nfs, o)
state := NewMountState(conn)
bufs := NewBufferPool()
err = state.Mount(dir, &MountOptions{Buffers: bufs})
if err != nil { if err != nil {
t.Fatalf("mount failed: %v", err) t.Fatalf("mount failed: %v", err)
} }
...@@ -58,7 +63,8 @@ func TestMemoryPressure(t *testing.T) { ...@@ -58,7 +63,8 @@ func TestMemoryPressure(t *testing.T) {
}(i) }(i)
} }
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
created := state.buffers.createdBuffers + state.outstandingReadBufs created := bufs.createdBuffers + state.outstandingReadBufs
t.Logf("Have %d read bufs", state.outstandingReadBufs) t.Logf("Have %d read bufs", state.outstandingReadBufs)
if created > 2*_MAX_READERS { if created > 2*_MAX_READERS {
t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS) t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS)
......
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