Calculate pageSize and bufSize at run-time (#102)
ARM-based macOS uses 16 KB pages instead of 4 KB. Fixes GoogleCloudPlatform/gcsfuse#548.geesefs-0-30-9
parent
5d146b000c
commit
7782064498
|
@ -25,31 +25,30 @@ import (
|
||||||
|
|
||||||
// All requests read from the kernel, without data, are shorter than
|
// All requests read from the kernel, without data, are shorter than
|
||||||
// this.
|
// this.
|
||||||
const pageSize = 4096
|
var pageSize int
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Confirm the page size.
|
|
||||||
if syscall.Getpagesize() != pageSize {
|
|
||||||
panic(fmt.Sprintf("Page size is unexpectedly %d", syscall.Getpagesize()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We size the buffer to have enough room for a fuse request plus data
|
// We size the buffer to have enough room for a fuse request plus data
|
||||||
// associated with a write request.
|
// associated with a write request.
|
||||||
const bufSize = pageSize + MaxWriteSize
|
var bufSize int
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pageSize = syscall.Getpagesize()
|
||||||
|
bufSize = pageSize + MaxWriteSize
|
||||||
|
}
|
||||||
|
|
||||||
// An incoming message from the kernel, including leading fusekernel.InHeader
|
// An incoming message from the kernel, including leading fusekernel.InHeader
|
||||||
// struct. Provides storage for messages and convenient access to their
|
// struct. Provides storage for messages and convenient access to their
|
||||||
// contents.
|
// contents.
|
||||||
type InMessage struct {
|
type InMessage struct {
|
||||||
remaining []byte
|
remaining []byte
|
||||||
storage [bufSize]byte
|
storage []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize with the data read by a single call to r.Read. The first call to
|
// Initialize with the data read by a single call to r.Read. The first call to
|
||||||
// Consume will consume the bytes directly after the fusekernel.InHeader
|
// Consume will consume the bytes directly after the fusekernel.InHeader
|
||||||
// struct.
|
// struct.
|
||||||
func (m *InMessage) Init(r io.Reader) error {
|
func (m *InMessage) Init(r io.Reader) error {
|
||||||
|
m.storage = make([]byte, bufSize, bufSize)
|
||||||
n, err := r.Read(m.storage[:])
|
n, err := r.Read(m.storage[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue