Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/internal/buffer"
"github.com/jacobsa/fuse/internal/freelist"
"github.com/jacobsa/fuse/internal/fusekernel"
)

Expand Down Expand Up @@ -77,9 +76,9 @@ type Connection struct {
// GUARDED_BY(mu)
cancelFuncs map[uint64]func()

// Freelists, serviced by freelists.go.
inMessages freelist.Freelist // GUARDED_BY(mu)
outMessages freelist.Freelist // GUARDED_BY(mu)
// Message pools.
inMessages sync.Pool
outMessages sync.Pool
}

// State that is maintained for each in-flight op. This is stuffed into the
Expand Down Expand Up @@ -119,6 +118,16 @@ func newConnection(
wireLogger: wireLogger,
dev: dev,
cancelFuncs: make(map[uint64]func()),
inMessages: sync.Pool{
New: func() any {
return buffer.NewInMessage()
},
},
outMessages: sync.Pool{
New: func() any {
return new(buffer.OutMessage)
},
},
}

// Initialize.
Expand Down
36 changes: 5 additions & 31 deletions freelists.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,30 @@
package fuse

import (
"unsafe"

"github.com/jacobsa/fuse/internal/buffer"
)

////////////////////////////////////////////////////////////////////////
// buffer.InMessage
////////////////////////////////////////////////////////////////////////

// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getInMessage() *buffer.InMessage {
c.mu.Lock()
x := (*buffer.InMessage)(c.inMessages.Get())
c.mu.Unlock()

if x == nil {
x = buffer.NewInMessage()
}

return x
return c.inMessages.Get().(*buffer.InMessage)
}

// LOCKS_EXCLUDED(c.mu)
func (c *Connection) putInMessage(x *buffer.InMessage) {
c.mu.Lock()
c.inMessages.Put(unsafe.Pointer(x))
c.mu.Unlock()
c.inMessages.Put(x)
}

////////////////////////////////////////////////////////////////////////
// buffer.OutMessage
////////////////////////////////////////////////////////////////////////

// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getOutMessage() *buffer.OutMessage {
c.mu.Lock()
x := (*buffer.OutMessage)(c.outMessages.Get())
c.mu.Unlock()

if x == nil {
x = new(buffer.OutMessage)
}
x.Reset()

return x
return c.outMessages.Get().(*buffer.OutMessage)
}

// LOCKS_EXCLUDED(c.mu)
func (c *Connection) putOutMessage(x *buffer.OutMessage) {
c.mu.Lock()
c.outMessages.Put(unsafe.Pointer(x))
c.mu.Unlock()
x.Reset()
c.outMessages.Put(x)
}
27 changes: 27 additions & 0 deletions freelists_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fuse

import (
"testing"
)

func BenchmarkGetPutInMessage(b *testing.B) {
c := &Connection{}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
msg := c.getInMessage()
c.putInMessage(msg)
}
})
}

func BenchmarkGetPutOutMessage(b *testing.B) {
c := &Connection{}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
msg := c.getOutMessage()
c.putOutMessage(msg)
}
})
}
Loading