aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db.go')
-rw-r--r--db.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/db.go b/db.go
index 9f80681..9048f6c 100644
--- a/db.go
+++ b/db.go
@@ -110,6 +110,8 @@ type DB struct {
freelist *freelist
stats Stats
+ pagePool sync.Pool
+
batchMu sync.Mutex
batch *batch
@@ -209,6 +211,13 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
}
}
+ // Initialize page pool.
+ db.pagePool = sync.Pool{
+ New: func() interface{} {
+ return make([]byte, db.pageSize)
+ },
+ }
+
// Memory map the data file.
if err := db.mmap(options.InitialMmapSize); err != nil {
_ = db.close()
@@ -324,7 +333,7 @@ func (db *DB) mmapSize(size int) (int, error) {
// init creates a new database file and initializes its meta pages.
func (db *DB) init() error {
// Set the page size to the OS page size.
- db.pageSize = defaultPageSize
+ db.pageSize = os.Getpagesize()
// Create two meta pages on a buffer.
buf := make([]byte, db.pageSize*4)
@@ -787,18 +796,12 @@ func (db *DB) meta() *meta {
return db.meta1
}
-var pagePool = sync.Pool{
- New: func() interface{} {
- return make([]byte, defaultPageSize)
- },
-}
-
// allocate returns a contiguous block of memory starting at a given page.
func (db *DB) allocate(count int) (*page, error) {
// Allocate a temporary buffer for the page.
var buf []byte
- if count == 1 && db.pageSize == defaultPageSize {
- buf = pagePool.Get().([]byte)
+ if count == 1 {
+ buf = db.pagePool.Get().([]byte)
} else {
buf = make([]byte, count*db.pageSize)
}