Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntegerHash ¶
func UpperPowerOfTwo ¶
Types ¶
type MmapMalloc ¶
type MmapMalloc struct { Path string `capid:"0"` File *os.File Fd int `capid:"1"` FileBytesLen int64 `capid:"2"` BytesAlloc int64 `capid:"3"` MMap gommap.MMap // equiv to Mem, just avoids casts everywhere. Mem []byte `capid:"4"` // equiv to Mmap ReadOnly bool }
The MmapMalloc struct represents either an anonymous, private region of memory (if path was "", or a memory mapped file if path was supplied to Malloc() at creation.
Malloc() creates and returns an MmapMalloc struct, which can then be later Free()-ed. Malloc() calls request memory directly from the kernel via mmap(). Memory can optionally be backed by a file for simplicity/efficiency of saving to disk.
For use when the Go GC overhead is too large, and you need to move the hash table off-heap.
func Malloc ¶
func Malloc(numBytes int64, path string) *MmapMalloc
Malloc() creates a new memory region that is provided directly by OS via the mmap() call, and is thus not scanned by the Go garbage collector.
If path is not empty then we memory map to the given path. Otherwise it is just like a call to malloc(): an anonymous memory allocation, outside the realm of the Go Garbage Collector. If numBytes is -1, then we take the size from the path file's size. Otherwise the file is expanded or truncated to be numBytes in size. If numBytes is -1 then a path must be provided; otherwise we have no way of knowing the size to allocate, and the function will panic.
The returned value's .Mem member holds a []byte pointing to the returned memory (as does .MMap, for use in other gommap calls).
func MallocReadOnly ¶
func MallocReadOnly(path string) (mm *MmapMalloc, err error)
MallocReadOnly creates new read-only memory region from existing file
func (*MmapMalloc) BackgrounSync ¶
func (mm *MmapMalloc) BackgrounSync()
BackgroundSync() schedules a sync to disk, but may return before it is done. Without a call to either BackgroundSync() or BlockUntilSync(), there is no guarantee that file has ever been written to disk at any point before the munmap() call that happens during Free(). See the man pages msync(2) and mmap(2) for details.
func (*MmapMalloc) BlockUntilSync ¶
func (mm *MmapMalloc) BlockUntilSync()
BlockUntilSync() returns only once the file is synced to disk.
func (*MmapMalloc) Free ¶
func (mm *MmapMalloc) Free()
Free eleases the memory allocation back to the OS by removing the (possibly anonymous and private) memroy mapped file that was backing it. Warning: any pointers still remaining will crash the program if dereferenced.
func (*MmapMalloc) TruncateTo ¶
func (mm *MmapMalloc) TruncateTo(newSize int64)
TruncateTo enlarges or shortens the file backing the memory map to be size newSize bytes. It only impacts the file underlying the mapping, not the mapping itself at this point.