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

Prespawn all worker threads.

Speedup 15% (lenovo T60, 2 CPUs, 2 stat threads)
parent b6256e6f
...@@ -130,7 +130,6 @@ func NewMountState(fs RawFileSystem) *MountState { ...@@ -130,7 +130,6 @@ func NewMountState(fs RawFileSystem) *MountState {
me.fileSystem = fs me.fileSystem = fs
me.buffers = NewBufferPool() me.buffers = NewBufferPool()
return me return me
} }
func (me *MountState) Latencies() map[string]float64 { func (me *MountState) Latencies() map[string]float64 {
...@@ -186,13 +185,25 @@ func (me *MountState) discardRequest(req *request) { ...@@ -186,13 +185,25 @@ func (me *MountState) discardRequest(req *request) {
// Normally, callers should run Loop() and wait for FUSE to exit, but // Normally, callers should run Loop() and wait for FUSE to exit, but
// tests will want to run this in a goroutine. // tests will want to run this in a goroutine.
// //
// If threaded is set, each filesystem operation executes in a // If threaded is given, each filesystem operation executes in a
// separate goroutine. // separate goroutine.
func (me *MountState) Loop(threaded bool) { func (me *MountState) Loop(threaded bool) {
// To limit scheduling overhead, we spawn multiple read loops.
// This means that the request once read does not need to be
// assigned to another thread, so it avoids a context switch.
if threaded {
for i := 0; i < _BACKGROUND_TASKS; i++ {
go me.loop()
}
}
me.loop()
me.mountFile.Close()
}
func (me *MountState) loop() {
// See fuse_kern_chan_receive() // See fuse_kern_chan_receive()
for { for {
req := me.newRequest() req := me.newRequest()
err := me.readRequest(req) err := me.readRequest(req)
if err != nil { if err != nil {
errNo := OsErrorToErrno(err) errNo := OsErrorToErrno(err)
...@@ -216,14 +227,8 @@ func (me *MountState) Loop(threaded bool) { ...@@ -216,14 +227,8 @@ func (me *MountState) Loop(threaded bool) {
log.Printf("Failed to read from fuse conn: %v", err) log.Printf("Failed to read from fuse conn: %v", err)
break break
} }
me.handle(req)
if threaded {
go me.handle(req)
} else {
me.handle(req)
}
} }
me.mountFile.Close()
} }
......
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