Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #455 from gyuho/boltdb_unix_map_populate
Browse files Browse the repository at this point in the history
Add MmapFlags option for MAP_POPULATE (unix)
  • Loading branch information
benbjohnson committed Nov 12, 2015
2 parents d359c78 + d97579c commit 0b00eff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bolt_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func mmap(db *DB, sz int) error {
}

// Map the data file to memory.
b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED)
b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions bolt_unix_solaris.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package bolt

import (
Expand All @@ -7,6 +6,7 @@ import (
"syscall"
"time"
"unsafe"

"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -68,7 +68,7 @@ func mmap(db *DB, sz int) error {
}

// Map the data file to memory.
b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED)
b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type DB struct {
// https://github.com/boltdb/bolt/issues/284
NoGrowSync bool

// If you want to read the entire database fast, you can set MmapFlag to
// syscall.MAP_POPULATE on Linux 2.6.23+ for sequential read-ahead.
MmapFlags int

// MaxBatchSize is the maximum size of a batch. Default value is
// copied from DefaultMaxBatchSize in Open.
//
Expand Down Expand Up @@ -136,6 +140,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
options = DefaultOptions
}
db.NoGrowSync = options.NoGrowSync
db.MmapFlags = options.MmapFlags

// Set default values for later DB operations.
db.MaxBatchSize = DefaultMaxBatchSize
Expand Down Expand Up @@ -672,6 +677,9 @@ type Options struct {
// Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
// grab a shared lock (UNIX).
ReadOnly bool

// Sets the DB.MmapFlags flag before memory mapping the file.
MmapFlags int
}

// DefaultOptions represent the options used if nil options are passed into Open().
Expand Down

0 comments on commit 0b00eff

Please sign in to comment.