Commit 3cd084d7 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Reuse request memory from the last done request.

This saves a normal and a BufferPool allocation, ie. two mutex locks.
parent 95dc9dab
...@@ -147,11 +147,21 @@ func (me *MountState) BufferPoolStats() string { ...@@ -147,11 +147,21 @@ func (me *MountState) BufferPoolStats() string {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Logic for the control loop. // Logic for the control loop.
func (me *MountState) newRequest() *request { func (me *MountState) newRequest(oldReq *request) *request {
req := new(request) if oldReq != nil {
req.status = OK me.buffers.FreeBuffer(oldReq.flatData)
req.inputBuf = me.buffers.AllocBuffer(bufSize)
return req *oldReq = request{
status: OK,
inputBuf: oldReq.inputBuf[0:bufSize],
}
return oldReq
}
return &request{
status: OK,
inputBuf: me.buffers.AllocBuffer(bufSize),
}
} }
func (me *MountState) readRequest(req *request) os.Error { func (me *MountState) readRequest(req *request) os.Error {
...@@ -177,9 +187,6 @@ func (me *MountState) discardRequest(req *request) { ...@@ -177,9 +187,6 @@ func (me *MountState) discardRequest(req *request) {
{opname + "-dispatch", "", req.dispatchNs - req.startNs}, {opname + "-dispatch", "", req.dispatchNs - req.startNs},
{opname + "-write", "", endNs - req.preWriteNs}}) {opname + "-write", "", endNs - req.preWriteNs}})
} }
me.buffers.FreeBuffer(req.inputBuf)
me.buffers.FreeBuffer(req.flatData)
} }
// Normally, callers should run Loop() and wait for FUSE to exit, but // Normally, callers should run Loop() and wait for FUSE to exit, but
...@@ -202,12 +209,14 @@ func (me *MountState) Loop(threaded bool) { ...@@ -202,12 +209,14 @@ func (me *MountState) Loop(threaded bool) {
func (me *MountState) loop() { func (me *MountState) loop() {
// See fuse_kern_chan_receive() // See fuse_kern_chan_receive()
var lastReq *request
for { for {
req := me.newRequest() req := me.newRequest(lastReq)
lastReq = req
err := me.readRequest(req) err := me.readRequest(req)
if err != nil { if err != nil {
errNo := OsErrorToErrno(err) errNo := OsErrorToErrno(err)
// Retry. // Retry.
if errNo == syscall.ENOENT { if errNo == syscall.ENOENT {
me.discardRequest(req) me.discardRequest(req)
......
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