Add proper mmap calls

This commit is contained in:
Fabian Reinartz 2016-12-11 15:49:36 +01:00
parent 8425df035d
commit 5e02e28f9c
2 changed files with 20 additions and 46 deletions

2
db.go
View File

@ -322,7 +322,7 @@ func (s *SeriesShard) persist() error {
} }
} }
sz := fmt.Sprintf("%fMiB", float64(sw.Size()+iw.Size())/1024/1024) sz := fmt.Sprintf("%.2fMiB", float64(sw.Size()+iw.Size())/1024/1024)
s.logger.With("size", sz). s.logger.With("size", sz).
With("samples", head.samples). With("samples", head.samples).

View File

@ -2,52 +2,26 @@
package tsdb package tsdb
// import ( import (
// "fmt" "os"
// "syscall" "unsafe"
// "unsafe"
// )
// // mmap memory maps a DB's data file. "golang.org/x/sys/unix"
// func mmap(db *DB, sz int) error { )
// // Map the data file to memory.
// b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
// if err != nil {
// return err
// }
// // Advise the kernel that the mmap is accessed randomly. func mmap(f *os.File, length int) ([]byte, error) {
// if err := madvise(b, syscall.MADV_RANDOM); err != nil { return unix.Mmap(int(f.Fd()), 0, length, unix.PROT_READ, unix.MAP_SHARED)
// return fmt.Errorf("madvise: %s", err) }
// }
// // Save the original byte slice and convert to a byte array pointer. func munmap(b []byte) (err error) {
// db.dataref = b return unix.Munmap(b)
// db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) }
// db.datasz = sz
// return nil
// }
// // munmap unmaps a DB's data file from memory. // unix.Madvise is not defined for darwin, so we define it ourselves.
// func munmap(db *DB) error { func madvise(b []byte, advice int) (err error) {
// // Ignore the unmap if we have no mapped data. _, _, e1 := unix.Syscall(unix.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
// if db.dataref == nil { if e1 != 0 {
// return nil err = e1
// } }
return
// // Unmap using the original byte slice. }
// err := syscall.Munmap(db.dataref)
// db.dataref = nil
// db.data = nil
// 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
// }