MCPcopy
hub / github.com/etcd-io/bbolt / mmap

Function mmap

bolt_aix.go:60–77  ·  bolt_aix.go::mmap

mmap memory maps a DB's data file.

(db *DB, sz int)

Source from the content-addressed store, hash-verified

58
59// mmap memory maps a DB's data file.
60func mmap(db *DB, sz int) error {
61 // Map the data file to memory.
62 b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
63 if err != nil {
64 return err
65 }
66
67 // Advise the kernel that the mmap is accessed randomly.
68 if err := unix.Madvise(b, syscall.MADV_RANDOM); err != nil {
69 return fmt.Errorf("madvise: %s", err)
70 }
71
72 // Save the original byte slice and convert to a byte array pointer.
73 db.dataref = b
74 db.data = (*[common.MaxMapSize]byte)(unsafe.Pointer(&b[0]))
75 db.datasz = sz
76 return nil
77}
78
79// munmap unmaps a DB's data file from memory.
80func munmap(db *DB) error {

Callers 1

mmapMethod · 0.70

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected