Commit 9d459bc5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: use sync.Pool for the request pool.

parent 4d73e177
...@@ -39,8 +39,8 @@ type Server struct { ...@@ -39,8 +39,8 @@ type Server struct {
started chan struct{} started chan struct{}
reqPool sync.Pool
reqMu sync.Mutex reqMu sync.Mutex
reqPool []*request
readPool [][]byte readPool [][]byte
reqReaders int reqReaders int
outstandingReadBufs int outstandingReadBufs int
...@@ -139,7 +139,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -139,7 +139,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
started: make(chan struct{}), started: make(chan struct{}),
opts: &o, opts: &o,
} }
ms.reqPool.New = func() interface{} { return new(request) }
optStrs := opts.Options optStrs := opts.Options
if opts.AllowOther { if opts.AllowOther {
optStrs = append(optStrs, "allow_other") optStrs = append(optStrs, "allow_other")
...@@ -203,14 +203,8 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) { ...@@ -203,14 +203,8 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
ms.reqMu.Unlock() ms.reqMu.Unlock()
return nil, OK return nil, OK
} }
l := len(ms.reqPool) req = ms.reqPool.Get().(*request)
if l > 0 { l := len(ms.readPool)
req = ms.reqPool[l-1]
ms.reqPool = ms.reqPool[:l-1]
} else {
req = new(request)
}
l = len(ms.readPool)
if l > 0 { if l > 0 {
dest = ms.readPool[l-1] dest = ms.readPool[l-1]
ms.readPool = ms.readPool[:l-1] ms.readPool = ms.readPool[:l-1]
...@@ -224,8 +218,8 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) { ...@@ -224,8 +218,8 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
n, err := syscall.Read(ms.mountFd, dest) n, err := syscall.Read(ms.mountFd, dest)
if err != nil { if err != nil {
code = ToStatus(err) code = ToStatus(err)
ms.reqPool.Put(req)
ms.reqMu.Lock() ms.reqMu.Lock()
ms.reqPool = append(ms.reqPool, req)
ms.reqReaders-- ms.reqReaders--
ms.reqMu.Unlock() ms.reqMu.Unlock()
return nil, code return nil, code
...@@ -268,7 +262,7 @@ func (ms *Server) returnRequest(req *request) { ...@@ -268,7 +262,7 @@ func (ms *Server) returnRequest(req *request) {
ms.outstandingReadBufs-- ms.outstandingReadBufs--
req.bufferPoolInputBuf = nil req.bufferPoolInputBuf = nil
} }
ms.reqPool = append(ms.reqPool, req) ms.reqPool.Put(req)
ms.reqMu.Unlock() ms.reqMu.Unlock()
} }
......
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