forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmap_unix.go
43 lines (33 loc) · 965 Bytes
/
mmap_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// +build !windows,!plan9
package tsm1
import (
"os"
"syscall"
"golang.org/x/sys/unix"
)
func mmap(f *os.File, offset int64, length int) ([]byte, error) {
// anonymous mapping
if f == nil {
return unix.Mmap(-1, 0, length, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
}
mmap, err := unix.Mmap(int(f.Fd()), 0, length, syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return nil, err
}
return mmap, nil
}
func munmap(b []byte) (err error) {
return unix.Munmap(b)
}
// madviseWillNeed gives the kernel the mmap madvise value MADV_WILLNEED, hinting
// that we plan on using the provided buffer in the near future.
func madviseWillNeed(b []byte) error {
return madvise(b, syscall.MADV_WILLNEED)
}
func madviseDontNeed(b []byte) error {
return madvise(b, syscall.MADV_DONTNEED)
}
// From: github.com/boltdb/bolt/bolt_unix.go
func madvise(b []byte, advice int) (err error) {
return unix.Madvise(b, advice)
}