Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #162

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 0 additions & 8 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ func (w *buffer) alloc(size uintptr) unsafe.Pointer {
return unsafe.Pointer(&(*w)[l])
}

// reset clears out the contents of the buffer.
func (w *buffer) reset() {
for i := range (*w)[:cap(*w)] {
(*w)[i] = 0
}
*w = (*w)[:0]
}

func newBuffer(extra uintptr) buffer {
const hdrSize = unsafe.Sizeof(outHeader{})
buf := make(buffer, hdrSize, hdrSize+extra)
Expand Down
4 changes: 1 addition & 3 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ func stack() string {
return string(buf[:runtime.Stack(buf, false)])
}

func nop(msg interface{}) {}

// Debug is called to output debug messages, including protocol
// traces. The default behavior is to do nothing.
//
// The messages have human-friendly string representations and are
// safe to marshal to JSON.
//
// Implementations must not retain msg.
var Debug func(msg interface{}) = nop
var Debug func(msg interface{})
2 changes: 1 addition & 1 deletion examples/clockfs/clockfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"context"
"flag"
"fmt"
"log"
Expand All @@ -15,7 +16,6 @@ import (
"bazil.org/fuse/fs"
_ "bazil.org/fuse/fs/fstestutil"
"bazil.org/fuse/fuseutil"
"golang.org/x/net/context"
)

func usage() {
Expand Down
2 changes: 1 addition & 1 deletion examples/hellofs/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package main

import (
"context"
"flag"
"fmt"
"log"
Expand All @@ -10,7 +11,6 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
_ "bazil.org/fuse/fs/fstestutil"
"golang.org/x/net/context"
)

func usage() {
Expand Down
2 changes: 1 addition & 1 deletion fs/bench/bench_create_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package bench_test

import (
"context"
"fmt"
"os"
"testing"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"bazil.org/fuse/fs/fstestutil"
"golang.org/x/net/context"
)

type dummyFile struct {
Expand Down
3 changes: 1 addition & 2 deletions fs/bench/bench_lookup_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package bench_test

import (
"context"
"os"
"testing"

"golang.org/x/net/context"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"bazil.org/fuse/fs/fstestutil"
Expand Down
2 changes: 1 addition & 1 deletion fs/bench/bench_readwrite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bench_test

import (
"context"
"io"
"io/ioutil"
"os"
Expand All @@ -10,7 +11,6 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"bazil.org/fuse/fs/fstestutil"
"golang.org/x/net/context"
)

type benchConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion fs/fstestutil/record/record.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package record // import "bazil.org/fuse/fs/fstestutil/record"

import (
"context"
"sync"
"sync/atomic"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)

// Writes gathers data from FUSE Write calls.
Expand Down
2 changes: 1 addition & 1 deletion fs/fstestutil/record/wait.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package record

import (
"context"
"sync"
"time"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)

type nothing struct{}
Expand Down
2 changes: 1 addition & 1 deletion fs/fstestutil/testfs.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package fstestutil

import (
"context"
"os"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)

// SimpleFS is a trivial FS that just implements the Root method.
Expand Down
101 changes: 54 additions & 47 deletions fs/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package fs // import "bazil.org/fuse/fs"

import (
"context"
"encoding/binary"
"fmt"
"hash/fnv"
Expand All @@ -13,8 +14,6 @@ import (
"strings"
"sync"
"time"

"golang.org/x/net/context"
)

import (
Expand Down Expand Up @@ -346,7 +345,7 @@ type Config struct {
func New(conn *fuse.Conn, config *Config) *Server {
s := &Server{
conn: conn,
req: map[fuse.RequestID]*serveRequest{},
req: map[fuse.RequestID]func(){},
nodeRef: map[Node]fuse.NodeID{},
dynamicInode: GenerateDynamicInode,
}
Expand All @@ -372,7 +371,7 @@ type Server struct {

// state, protected by meta
meta sync.Mutex
req map[fuse.RequestID]*serveRequest
req map[fuse.RequestID]func() // map request to cancel functions
node []*serveNode
nodeRef map[Node]fuse.NodeID
handle []*serveHandle
Expand Down Expand Up @@ -437,11 +436,6 @@ func Serve(c *fuse.Conn, fs FS) error {

type nothing struct{}

type serveRequest struct {
Request fuse.Request
cancel func()
}

type serveNode struct {
inode uint64
generation uint64
Expand Down Expand Up @@ -538,15 +532,19 @@ func (c *Server) dropNode(id fuse.NodeID, n uint64) (forget bool) {
// this should only happen if refcounts kernel<->us disagree
// *and* two ForgetRequests for the same node race each other;
// this indicates a bug somewhere
c.debug(nodeRefcountDropBug{N: n, Node: id})
if c.debug != nil {
c.debug(nodeRefcountDropBug{N: n, Node: id})
}

// we may end up triggering Forget twice, but that's better
// than not even once, and that's the best we can do
return true
}

if n > snode.refs {
c.debug(nodeRefcountDropBug{N: n, Refs: snode.refs, Node: id})
if c.debug != nil {
c.debug(nodeRefcountDropBug{N: n, Refs: snode.refs, Node: id})
}
n = snode.refs
}

Expand Down Expand Up @@ -585,10 +583,12 @@ func (c *Server) getHandle(id fuse.HandleID) (shandle *serveHandle) {
shandle = c.handle[uint(id)]
}
if shandle == nil {
c.debug(missingHandle{
Handle: id,
MaxHandle: fuse.HandleID(len(c.handle)),
})
if c.debug != nil {
c.debug(missingHandle{
Handle: id,
MaxHandle: fuse.HandleID(len(c.handle)),
})
}
}
return
}
Expand Down Expand Up @@ -774,13 +774,13 @@ func (c *Server) serve(r fuse.Request) {
ctx = c.context(ctx, r)
}

req := &serveRequest{Request: r, cancel: cancel}

c.debug(request{
Op: opName(r),
Request: r.Hdr(),
In: r,
})
if c.debug != nil {
c.debug(request{
Op: opName(r),
Request: r.Hdr(),
In: r,
})
}
var node Node
var snode *serveNode
c.meta.Lock()
Expand All @@ -791,17 +791,19 @@ func (c *Server) serve(r fuse.Request) {
}
if snode == nil {
c.meta.Unlock()
c.debug(response{
Op: opName(r),
Request: logResponseHeader{ID: hdr.ID},
Error: fuse.ESTALE.ErrnoName(),
// this is the only place that sets both Error and
// Out; not sure if i want to do that; might get rid
// of len(c.node) things altogether
Out: logMissingNode{
MaxNode: fuse.NodeID(len(c.node)),
},
})
if c.debug != nil {
c.debug(response{
Op: opName(r),
Request: logResponseHeader{ID: hdr.ID},
Error: fuse.ESTALE.ErrnoName(),
// this is the only place that sets both Error and
// Out; not sure if i want to do that; might get rid
// of len(c.node) things altogether
Out: logMissingNode{
MaxNode: fuse.NodeID(len(c.node)),
},
})
}
r.RespondError(fuse.ESTALE)
return
}
Expand All @@ -814,7 +816,7 @@ func (c *Server) serve(r fuse.Request) {
//
// TODO this might have been because of missing done() calls
} else {
c.req[hdr.ID] = req
c.req[hdr.ID] = cancel
}
c.meta.Unlock()

Expand Down Expand Up @@ -842,7 +844,9 @@ func (c *Server) serve(r fuse.Request) {
} else {
msg.Out = resp
}
c.debug(msg)
if c.debug != nil {
c.debug(msg)
}

c.meta.Lock()
delete(c.req, hdr.ID)
Expand Down Expand Up @@ -997,10 +1001,12 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode,
}
c.meta.Unlock()
if oldNode == nil {
c.debug(logLinkRequestOldNodeNotFound{
Request: r.Hdr(),
In: r,
})
if c.debug != nil {
c.debug(logLinkRequestOldNodeNotFound{
Request: r.Hdr(),
In: r,
})
}
return fuse.EIO
}
n2, err := n.Link(ctx, r, oldNode.node)
Expand Down Expand Up @@ -1322,10 +1328,12 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode,
}
c.meta.Unlock()
if newDirNode == nil {
c.debug(renameNewDirNodeNotFound{
Request: r.Hdr(),
In: r,
})
if c.debug != nil {
c.debug(renameNewDirNodeNotFound{
Request: r.Hdr(),
In: r,
})
}
return fuse.EIO
}
n, ok := node.(NodeRenamer)
Expand Down Expand Up @@ -1373,10 +1381,9 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode,

case *fuse.InterruptRequest:
c.meta.Lock()
ireq := c.req[r.IntrID]
if ireq != nil && ireq.cancel != nil {
ireq.cancel()
ireq.cancel = nil
if cancel := c.req[r.IntrID]; cancel != nil {
cancel()
delete(c.req, r.IntrID)
}
c.meta.Unlock()
done(nil)
Expand Down
2 changes: 1 addition & 1 deletion fs/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fs_test

import (
"bytes"
"context"
"errors"
"io"
"io/ioutil"
Expand All @@ -22,7 +23,6 @@ import (
"bazil.org/fuse/fs/fstestutil/record"
"bazil.org/fuse/fuseutil"
"bazil.org/fuse/syscallx"
"golang.org/x/net/context"
)

// TO TEST:
Expand Down
3 changes: 1 addition & 2 deletions fs/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
package fs

import (
"context"
"os"
pathpkg "path"
"strings"

"golang.org/x/net/context"
)

import (
Expand Down
Loading