Codebase list golang-github-boltdb-bolt / 88f777f
Add madvise() after mmap(). This commit advises the mmapped data file to use MADV_RANDOM to avoid readahead. This can provide a performance boost to Bolt databases that are larger than memory by avoiding unnecessary disk i/o. Ben Johnson 8 years ago
1 changed file(s) with 14 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6262 return err
6363 }
6464
65 // Advise the kernel that the mmap is accessed randomly.
66 if err := madvise(b, syscall.MADV_RANDOM); err != nil {
67 return fmt.Errorf("madvise: %s", err)
68 }
69
6570 // Save the original byte slice and convert to a byte array pointer.
6671 db.dataref = b
6772 db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0]))
8388 db.datasz = 0
8489 return err
8590 }
91
92 // NOTE: This function is copied from stdlib because it is not available on darwin.
93 func madvise(b []byte, advice int) (err error) {
94 _, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
95 if e1 != 0 {
96 err = e1
97 }
98 return
99 }