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

Function mmap

bolt_unix.go:55–74  ·  view source on GitHub ↗

mmap memory maps a DB's data file.

(db *DB, sz int)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected