Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Levin Zimmermann
go-fuse
Commits
b55cc8ad
Commit
b55cc8ad
authored
Jun 23, 2014
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fuse: use sync.Pool for the buffers that read from the kernel.
parent
9d459bc5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
17 deletions
+12
-17
fuse/server.go
fuse/server.go
+12
-17
No files found.
fuse/server.go
View file @
b55cc8ad
...
@@ -39,9 +39,12 @@ type Server struct {
...
@@ -39,9 +39,12 @@ type Server struct {
started
chan
struct
{}
started
chan
struct
{}
// Pool for request structs.
reqPool
sync
.
Pool
reqPool
sync
.
Pool
// Pool for raw requests data
readPool
sync
.
Pool
reqMu
sync
.
Mutex
reqMu
sync
.
Mutex
readPool
[][]
byte
reqReaders
int
reqReaders
int
outstandingReadBufs
int
outstandingReadBufs
int
kernelSettings
InitIn
kernelSettings
InitIn
...
@@ -140,6 +143,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
...
@@ -140,6 +143,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
opts
:
&
o
,
opts
:
&
o
,
}
}
ms
.
reqPool
.
New
=
func
()
interface
{}
{
return
new
(
request
)
}
ms
.
reqPool
.
New
=
func
()
interface
{}
{
return
new
(
request
)
}
ms
.
readPool
.
New
=
func
()
interface
{}
{
return
make
([]
byte
,
o
.
MaxWrite
+
PAGESIZE
)
}
optStrs
:=
opts
.
Options
optStrs
:=
opts
.
Options
if
opts
.
AllowOther
{
if
opts
.
AllowOther
{
optStrs
=
append
(
optStrs
,
"allow_other"
)
optStrs
=
append
(
optStrs
,
"allow_other"
)
...
@@ -182,11 +186,10 @@ func (ms *Server) DebugData() string {
...
@@ -182,11 +186,10 @@ func (ms *Server) DebugData() string {
var
r
int
var
r
int
ms
.
reqMu
.
Lock
()
ms
.
reqMu
.
Lock
()
r
=
len
(
ms
.
readPool
)
+
ms
.
reqReaders
r
=
ms
.
reqReaders
ms
.
reqMu
.
Unlock
()
ms
.
reqMu
.
Unlock
()
s
+=
fmt
.
Sprintf
(
" read buffers: %d (sz %d )"
,
s
+=
fmt
.
Sprintf
(
" readers: %d"
,
r
)
r
,
ms
.
opts
.
MaxWrite
/
PAGESIZE
+
1
)
return
s
return
s
}
}
...
@@ -196,21 +199,13 @@ const _MAX_READERS = 2
...
@@ -196,21 +199,13 @@ const _MAX_READERS = 2
// Returns a new request, or error. In case exitIdle is given, returns
// Returns a new request, or error. In case exitIdle is given, returns
// nil, OK if we have too many readers already.
// nil, OK if we have too many readers already.
func
(
ms
*
Server
)
readRequest
(
exitIdle
bool
)
(
req
*
request
,
code
Status
)
{
func
(
ms
*
Server
)
readRequest
(
exitIdle
bool
)
(
req
*
request
,
code
Status
)
{
var
dest
[]
byte
ms
.
reqMu
.
Lock
()
ms
.
reqMu
.
Lock
()
if
ms
.
reqReaders
>
_MAX_READERS
{
if
ms
.
reqReaders
>
_MAX_READERS
{
ms
.
reqMu
.
Unlock
()
ms
.
reqMu
.
Unlock
()
return
nil
,
OK
return
nil
,
OK
}
}
req
=
ms
.
reqPool
.
Get
()
.
(
*
request
)
req
=
ms
.
reqPool
.
Get
()
.
(
*
request
)
l
:=
len
(
ms
.
readPool
)
dest
:=
ms
.
readPool
.
Get
()
.
([]
byte
)
if
l
>
0
{
dest
=
ms
.
readPool
[
l
-
1
]
ms
.
readPool
=
ms
.
readPool
[
:
l
-
1
]
}
else
{
dest
=
make
([]
byte
,
ms
.
opts
.
MaxWrite
+
PAGESIZE
)
}
ms
.
outstandingReadBufs
++
ms
.
outstandingReadBufs
++
ms
.
reqReaders
++
ms
.
reqReaders
++
ms
.
reqMu
.
Unlock
()
ms
.
reqMu
.
Unlock
()
...
@@ -233,7 +228,7 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
...
@@ -233,7 +228,7 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
ms
.
reqMu
.
Lock
()
ms
.
reqMu
.
Lock
()
if
!
gobbled
{
if
!
gobbled
{
ms
.
outstandingReadBufs
--
ms
.
outstandingReadBufs
--
ms
.
readPool
=
append
(
ms
.
readPool
,
dest
)
ms
.
readPool
.
Put
(
dest
)
dest
=
nil
dest
=
nil
}
}
ms
.
reqReaders
--
ms
.
reqReaders
--
...
@@ -258,9 +253,9 @@ func (ms *Server) returnRequest(req *request) {
...
@@ -258,9 +253,9 @@ func (ms *Server) returnRequest(req *request) {
req
.
clear
()
req
.
clear
()
ms
.
reqMu
.
Lock
()
ms
.
reqMu
.
Lock
()
if
req
.
bufferPoolOutputBuf
!=
nil
{
if
req
.
bufferPoolOutputBuf
!=
nil
{
ms
.
readPool
=
append
(
ms
.
readPool
,
req
.
bufferPoolInputBuf
)
ms
.
readPool
.
Put
(
req
.
bufferPoolInputBuf
)
ms
.
outstandingReadBufs
--
req
.
bufferPoolInputBuf
=
nil
req
.
bufferPoolInputBuf
=
nil
ms
.
outstandingReadBufs
--
}
}
ms
.
reqPool
.
Put
(
req
)
ms
.
reqPool
.
Put
(
req
)
ms
.
reqMu
.
Unlock
()
ms
.
reqMu
.
Unlock
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment