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
83ba0346
Commit
83ba0346
authored
Mar 23, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Plug memory leak in bufferpool code: reused buffers should also be in
the handed-out table.
parent
2b9f0042
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
fuse/bufferpool.go
fuse/bufferpool.go
+20
-5
fuse/fuse.go
fuse/fuse.go
+2
-13
No files found.
fuse/bufferpool.go
View file @
83ba0346
...
...
@@ -4,8 +4,11 @@ import (
"sync"
"fmt"
"unsafe"
"log"
)
var
_
=
log
.
Println
// This implements a pool of buffers that returns slices with capacity
// (2^e * PAGESIZE) for e=0,1,... which have possibly been used, and
// may contain random contents.
...
...
@@ -17,6 +20,10 @@ type BufferPool struct {
// start of slice -> exponent.
outstandingBuffers
map
[
uintptr
]
uint
// Total count of created buffers. Handy for finding memory
// leaks.
createdBuffers
int
}
// Returns the smallest E such that 2^E >= Z.
...
...
@@ -71,6 +78,13 @@ func (me *BufferPool) addBuffer(slice []byte, exp uint) {
}
func
(
me
*
BufferPool
)
AllocCount
()
int
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
createdBuffers
}
func
(
me
*
BufferPool
)
AllocBuffer
(
size
uint32
)
[]
byte
{
sz
:=
int
(
size
)
if
sz
<
PAGESIZE
{
...
...
@@ -87,12 +101,13 @@ func (me *BufferPool) AllocBuffer(size uint32) []byte {
b
:=
me
.
getBuffer
(
exp
)
if
b
!=
nil
{
if
b
==
nil
{
me
.
createdBuffers
++
b
=
make
([]
byte
,
size
,
rounded
)
}
else
{
b
=
b
[
:
size
]
return
b
}
b
=
make
([]
byte
,
size
,
rounded
)
me
.
outstandingBuffers
[
uintptr
(
unsafe
.
Pointer
(
&
b
[
0
]))]
=
exp
return
b
}
...
...
fuse/fuse.go
View file @
83ba0346
...
...
@@ -3,7 +3,6 @@ package fuse
import
(
"bytes"
"encoding/binary"
"expvar"
"fmt"
"log"
"os"
...
...
@@ -240,18 +239,8 @@ func (me *MountState) OperationCounts() map[string]int64 {
}
func
(
me
*
MountState
)
Stats
()
string
{
var
lines
[]
string
// TODO - bufferpool should use expvar.
lines
=
append
(
lines
,
fmt
.
Sprintf
(
"buffers: %v"
,
me
.
buffers
.
String
()))
for
v
:=
range
expvar
.
Iter
()
{
if
strings
.
HasPrefix
(
v
.
Key
,
"mount"
)
{
lines
=
append
(
lines
,
fmt
.
Sprintf
(
"%v: %v
\n
"
,
v
.
Key
,
v
.
Value
))
}
}
return
strings
.
Join
(
lines
,
"
\n
"
)
return
fmt
.
Sprintf
(
"buffer alloc count %d
\n
buffers %v"
,
me
.
buffers
.
AllocCount
(),
me
.
buffers
.
String
())
}
////////////////////////////////////////////////////////////////
...
...
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