From 7782064498ca74f7180c982301d74468114e6dfc Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 12 Aug 2021 04:31:10 +0900 Subject: [PATCH] Calculate pageSize and bufSize at run-time (#102) ARM-based macOS uses 16 KB pages instead of 4 KB. Fixes GoogleCloudPlatform/gcsfuse#548. --- internal/buffer/in_message.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/buffer/in_message.go b/internal/buffer/in_message.go index 80671f4..cfa1d31 100644 --- a/internal/buffer/in_message.go +++ b/internal/buffer/in_message.go @@ -25,31 +25,30 @@ import ( // All requests read from the kernel, without data, are shorter than // this. -const pageSize = 4096 - -func init() { - // Confirm the page size. - if syscall.Getpagesize() != pageSize { - panic(fmt.Sprintf("Page size is unexpectedly %d", syscall.Getpagesize())) - } -} +var pageSize int // We size the buffer to have enough room for a fuse request plus data // 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 // struct. Provides storage for messages and convenient access to their // contents. type InMessage struct { remaining []byte - storage [bufSize]byte + storage []byte } // 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 // struct. func (m *InMessage) Init(r io.Reader) error { + m.storage = make([]byte, bufSize, bufSize) n, err := r.Read(m.storage[:]) if err != nil { return err