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