mmap

package
v0.3.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MAP_POPULATE = 0x08000
View Source
const MaxSize = 0xFFFFFFFFFFFF // 256TB

MaxSize represents the largest supported mmap size.

Variables

This section is empty.

Functions

func Fdatasync

func Fdatasync(f *os.File, mapping []byte) error

Fdatasync triggers the fastest fsync-like operation that ensures durability of the data written to the given file and/or memory mapping.

Fdatasync might be faster than f.Sync() aka fsync thanks to not syncing metadata (last modification/access time) that isn't necessary to ensure durability of the data.

If mapping is provided, it's an mmap'ed slice corresponding to the given file, in case the operating system supports an alternative interface for syncing mmap'ed data.

WARNING: ERRORS RETURNED BY THIS FUNCTION ARE NOT RECOVERABLE. Many operating systems and file systems mark modified pages as clean in case of fsync failures, and there is no way to ensure data correctness after a failure. Moreover, the data in disk caches might not correspond to the data on disk, so whether the data appears corrupt upon reading back might not reflect whether the corruption actually exists on disk. The only sensible handling of fsync errors is to mark the database as corrupted and require manual inspection and recovery (including a reboot).

func Mmap

func Mmap(f *os.File, offset, size int, opt Options) ([]byte, error)

mmap memory maps a DB's data file.

func Munmap

func Munmap(b []byte) error

Munmap unmaps the given slice from memory. The slice must have been returned by Mmap.

Types

type Options

type Options uint
const (
	// Writable opens the file for writing (otherwise, it's opened read-only).
	Writable Options = 1 << 0

	// SequentialAccess is a hint requesting aggressive read-ahead.
	// Incompatible with RandomAccess. Maps to MADV_SEQUENTIAL on Unix.
	SequentialAccess Options = 1 << 1

	// RandomAccess is a hint that read ahead is less useful than normally.
	// Incompatible with SequentialAccess. Maps to MADV_RANDOM on Unix.
	RandomAccess Options = 1 << 2

	// Prefault is a hint requesting the entire file to be loaded in memory
	// for fastest access. Maps to MAP_POPULATE on Linux.
	Prefault Options = 1 << 3
)

func (Options) Has

func (o Options) Has(v Options) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL