diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2015-06-03 07:10:20 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2015-06-03 07:10:20 -0600 |
commit | 8f42da05d6e14dcd20c0a19ef3f1ae7daeca6f21 (patch) | |
tree | cae3e76e053a1931b9ac9699f3c1b7df7aad2e8b /bolt_unix.go | |
parent | Merge pull request #379 from benbjohnson/tx-doc (diff) | |
parent | Add madvise() after mmap(). (diff) | |
download | dedo-8f42da05d6e14dcd20c0a19ef3f1ae7daeca6f21.tar.gz dedo-8f42da05d6e14dcd20c0a19ef3f1ae7daeca6f21.tar.xz |
Merge pull request #383 from benbjohnson/madvise
Add madvise() after mmap().
Diffstat (limited to 'bolt_unix.go')
-rw-r--r-- | bolt_unix.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/bolt_unix.go b/bolt_unix.go index 266222a..17ca318 100644 --- a/bolt_unix.go +++ b/bolt_unix.go @@ -63,6 +63,11 @@ func mmap(db *DB, sz int) error { return err } + // Advise the kernel that the mmap is accessed randomly. + if err := madvise(b, syscall.MADV_RANDOM); err != nil { + return fmt.Errorf("madvise: %s", err) + } + // Save the original byte slice and convert to a byte array pointer. db.dataref = b db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) @@ -84,3 +89,12 @@ func munmap(db *DB) error { db.datasz = 0 return err } + +// NOTE: This function is copied from stdlib because it is not available on darwin. +func madvise(b []byte, advice int) (err error) { + _, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice)) + if e1 != 0 { + err = e1 + } + return +} |