Commit 26b2eb35 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Softcode page size, remove fuse.PAGESIZE constant.

Fixes #160.
parent 5404bf0e
......@@ -5,6 +5,7 @@
package fuse
import (
"os"
"sync"
)
......@@ -46,7 +47,7 @@ type bufferPoolImpl struct {
}
// NewBufferPool returns a BufferPool implementation that that returns
// slices with capacity of a multiple of PAGESIZE, which have possibly
// slices with capacity of a multiple of page size, which have possibly
// been used, and may contain random contents. When using
// NewBufferPool, file system handlers may not hang on to passed-in
// buffers beyond the handler's return.
......@@ -55,6 +56,8 @@ func NewBufferPool() BufferPool {
return bp
}
var pageSize = os.Getpagesize()
func (p *bufferPoolImpl) getPool(pageCount int) *sync.Pool {
p.lock.Lock()
for len(p.buffersBySize) < pageCount+1 {
......@@ -62,7 +65,7 @@ func (p *bufferPoolImpl) getPool(pageCount int) *sync.Pool {
}
if p.buffersBySize[pageCount] == nil {
p.buffersBySize[pageCount] = &sync.Pool{
New: func() interface{} { return make([]byte, PAGESIZE*pageCount) },
New: func() interface{} { return make([]byte, pageSize*pageCount) },
}
}
pool := p.buffersBySize[pageCount]
......@@ -72,14 +75,14 @@ func (p *bufferPoolImpl) getPool(pageCount int) *sync.Pool {
func (p *bufferPoolImpl) AllocBuffer(size uint32) []byte {
sz := int(size)
if sz < PAGESIZE {
sz = PAGESIZE
if sz < pageSize {
sz = pageSize
}
if sz%PAGESIZE != 0 {
sz += PAGESIZE
if sz%pageSize != 0 {
sz += pageSize
}
pages := sz / PAGESIZE
pages := sz / pageSize
b := p.getPool(pages).Get().([]byte)
return b[:size]
......@@ -89,10 +92,10 @@ func (p *bufferPoolImpl) FreeBuffer(slice []byte) {
if slice == nil {
return
}
if cap(slice)%PAGESIZE != 0 || cap(slice) == 0 {
if cap(slice)%pageSize != 0 || cap(slice) == 0 {
return
}
pages := cap(slice) / PAGESIZE
pages := cap(slice) / pageSize
slice = slice[:cap(slice)]
p.getPool(pages).Put(slice)
......
......@@ -81,13 +81,6 @@ func CurrentOwner() *Owner {
}
}
func init() {
p := syscall.Getpagesize()
if p != PAGESIZE {
log.Panicf("page size incorrect: %d", p)
}
}
const _UTIME_OMIT = ((1 << 30) - 2)
// UtimeToTimespec converts a "Time" pointer as passed to Utimens to a
......
......@@ -163,7 +163,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
singleReader: runtime.GOOS == "darwin",
}
ms.reqPool.New = func() interface{} { return new(request) }
ms.readPool.New = func() interface{} { return make([]byte, o.MaxWrite+PAGESIZE) }
ms.readPool.New = func() interface{} { return make([]byte, o.MaxWrite+pageSize) }
mountPoint = filepath.Clean(mountPoint)
if !filepath.IsAbs(mountPoint) {
......
......@@ -8,8 +8,6 @@ import (
"syscall"
)
const PAGESIZE = 4096
const (
_DEFAULT_BACKGROUND_TASKS = 12
)
......
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