Skip to content

Commit f1b686c

Browse files
committed
wasm: simplify platform-specific page size handling
Replace os.Getpagesize() calls with common.DefaultPageSize constant and remove redundant pagesize.go implementation. Simplify WASM-specific code by removing custom initialization and page size handling. Update tests to use the new constant. Signed-off-by: Travis Cline <[email protected]>
1 parent 55aec40 commit f1b686c

File tree

7 files changed

+13
-36
lines changed

7 files changed

+13
-36
lines changed

bucket_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
bolt "go.etcd.io/bbolt"
2121
berrors "go.etcd.io/bbolt/errors"
2222
"go.etcd.io/bbolt/internal/btesting"
23+
"go.etcd.io/bbolt/internal/common"
2324
)
2425

2526
// Ensure that a bucket that gets a non-existent key returns nil.
@@ -1350,7 +1351,7 @@ func TestBucket_Stats(t *testing.T) {
13501351
func TestBucket_Stats_RandomFill(t *testing.T) {
13511352
if testing.Short() {
13521353
t.Skip("skipping test in short mode.")
1353-
} else if os.Getpagesize() != 4096 {
1354+
} else if common.DefaultPageSize != 4096 {
13541355
t.Skip("invalid page size for test")
13551356
}
13561357

cmd/bbolt/main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"testing"
1616

1717
"go.etcd.io/bbolt/internal/btesting"
18+
"go.etcd.io/bbolt/internal/common"
1819
"go.etcd.io/bbolt/internal/guts_cli"
1920

2021
"github.com/stretchr/testify/assert"
@@ -41,7 +42,7 @@ func TestInfoCommand_Run(t *testing.T) {
4142
// Ensure the "stats" command executes correctly with an empty database.
4243
func TestStatsCommand_Run_EmptyDatabase(t *testing.T) {
4344
// Ignore
44-
if os.Getpagesize() != 4096 {
45+
if common.DefaultPageSize != 4096 {
4546
t.Skip("system does not use 4KB page size")
4647
}
4748

@@ -199,7 +200,7 @@ func TestPageItemCommand_Run(t *testing.T) {
199200
// Ensure the "stats" command can execute correctly.
200201
func TestStatsCommand_Run(t *testing.T) {
201202
// Ignore
202-
if os.Getpagesize() != 4096 {
203+
if common.DefaultPageSize != 4096 {
203204
t.Skip("system does not use 4KB page size")
204205
}
205206

db_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestOpen_ErrInvalid(t *testing.T) {
147147

148148
// Ensure that opening a file with two invalid versions returns ErrVersionMismatch.
149149
func TestOpen_ErrVersionMismatch(t *testing.T) {
150-
if pageSize != os.Getpagesize() {
150+
if pageSize != common.DefaultPageSize {
151151
t.Skip("page size mismatch")
152152
}
153153

@@ -241,7 +241,7 @@ func TestOpen_ReadPageSize_FromMeta1_OS(t *testing.T) {
241241

242242
// Reopen data file.
243243
db = btesting.MustOpenDBWithOption(t, path, nil)
244-
require.Equalf(t, common.GetPagesize(), db.Info().PageSize, "check page size failed")
244+
require.Equalf(t, common.DefaultPageSize, db.Info().PageSize, "check page size failed")
245245
}
246246

247247
// Ensure that it can read the page size from the second meta page if the first one is invalid.
@@ -584,7 +584,7 @@ func TestDB_Open_ReadOnly_NoCreate(t *testing.T) {
584584
// TestOpen_BigPage checks the database uses bigger pages when
585585
// changing PageSize.
586586
func TestOpen_BigPage(t *testing.T) {
587-
pageSize := os.Getpagesize()
587+
pageSize := common.DefaultPageSize
588588

589589
db1 := btesting.MustCreateDBWithOption(t, &bolt.Options{PageSize: pageSize * 2})
590590

internal/common/bolt_386.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package common
44
const MaxMapSize = 0x7FFFFFFF // 2GB
55

66
// MaxAllocSize is the size used when creating array pointers.
7-
const MaxAllocSize = 0xFFFFFFF
7+
const MaxAllocSize = 0xFFFFFF

internal/common/bolt_wasm.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33
package common
44

55
// MaxMapSize represents the largest mmap size supported by Bolt.
6-
// Reduced for WASM due to memory constraints.
7-
const MaxMapSize = 0x10000000 // 256MB
6+
const MaxMapSize = 0x10000000
87

98
// MaxAllocSize is the size used when creating array pointers.
10-
// Slightly larger than MaxMapSize to accommodate metadata overhead.
11-
const MaxAllocSize = 0x10100000 // 257MB
12-
13-
func init() {
14-
// Override the default page size for WASM to use 4KB instead of 64KB.
15-
// This reduces memory usage and makes behavior more consistent with other platforms.
16-
// Note: Databases created with different page sizes are not compatible.
17-
DefaultPageSize = 4096
18-
}
19-
20-
// GetPagesize returns the system page size.
21-
// On WASM platforms, we always return 4KB as the page size.
22-
func GetPagesize() int {
23-
return 4096
24-
}
9+
const MaxAllocSize = 0x10100000

internal/common/pagesize.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

tx_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
bolt "go.etcd.io/bbolt"
1717
berrors "go.etcd.io/bbolt/errors"
1818
"go.etcd.io/bbolt/internal/btesting"
19+
"go.etcd.io/bbolt/internal/common"
1920
)
2021

2122
// TestTx_Check_ReadOnly tests consistency checking on a ReadOnly database.
@@ -701,7 +702,7 @@ func TestTx_releaseRange(t *testing.T) {
701702
// Set initial mmap size well beyond the limit we will hit in this
702703
// test, since we are testing with long running read transactions
703704
// and will deadlock if db.grow is triggered.
704-
db := btesting.MustCreateDBWithOption(t, &bolt.Options{InitialMmapSize: os.Getpagesize() * 100})
705+
db := btesting.MustCreateDBWithOption(t, &bolt.Options{InitialMmapSize: common.DefaultPageSize * 100})
705706

706707
bucket := "bucket"
707708

0 commit comments

Comments
 (0)