mmap

package
v0.15.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MadviseDontNeed added in v0.15.0

func MadviseDontNeed(desc Descriptor) error

MadviseDontNeed frees mmapped memory. `MADV_DONTNEED` informs the kernel to free the mmapped pages right away instead of waiting for memory pressure. NB(bodu): DO NOT FREE anonymously mapped memory or else it will null all of the underlying bytes as the memory is not file backed.

func Munmap

func Munmap(desc Descriptor) error

Munmap munmaps a byte slice that is backed by an mmap

Types

type Context added in v0.15.0

type Context struct {
	Size     int64
	Name     string
	Metadata map[string]string
}

Context provides context about the current mmap for reporting purposes

type Descriptor added in v0.15.0

type Descriptor struct {
	Bytes           []byte
	Warning         error
	ReporterOptions ReporterOptions
}

Descriptor is a descriptor of a successful mmap

func Bytes

func Bytes(length int64, opts Options) (Descriptor, error)

Bytes requests a private (non-shared) region of anonymous (not backed by a file) memory from the O.S

func Fd

func Fd(fd, offset, length int64, opts Options) (Descriptor, error)

Fd mmaps a file

func File

func File(file *os.File, opts Options) (Descriptor, error)

File mmap's a file

type FileDesc

type FileDesc struct {
	// file is the *os.File ref to store
	File **os.File
	// bytes is the []byte slice ref to store the mmap'd address
	Descriptor *Descriptor
	// options specifies options to use when mmaping a file
	Options Options
}

FileDesc contains the fields required for Mmaping a file using MmapFiles

type FileOpener

type FileOpener func(filePath string) (*os.File, error)

FileOpener is the signature of a function that MmapFiles can use to open files

type FilesResult

type FilesResult struct {
	Warning error
}

FilesResult contains the result of calling MmapFiles

func Files

func Files(opener FileOpener, files map[string]FileDesc) (FilesResult, error)

Files is a utility function for mmap'ing a group of files at once

type HugeTLBOptions

type HugeTLBOptions struct {
	// enabled determines if using the huge TLB flag is enabled for platforms
	// that support it
	Enabled bool
	// threshold determines if the size being mmap'd is greater or equal
	// to this value to use or not use the huge TLB flag if enabled
	Threshold int64
}

HugeTLBOptions contains all options related to huge TLB

type Options

type Options struct {
	// read is whether to make mmap bytes ref readable
	Read bool
	// write is whether to make mmap bytes ref writable
	Write bool
	// hugeTLB is the mmap huge TLB options
	HugeTLB HugeTLBOptions
	// ReporterOptions is the reporter options
	ReporterOptions ReporterOptions
}

Options contains the options for mmap'ing a file

type Reporter added in v0.15.0

type Reporter interface {
	// ReportMap reports the mapping of an mmap and allows an error to be
	// returned in case the reporter want's to deny allowing this map call.
	ReportMap(ctx Context) error
	// ReportUnmap reports the unmapping of an mmap and allows an error to be
	// returned in case the reporter want's to deny allowing this unmap call.
	ReportUnmap(ctx Context) error
}

Reporter implements the reporting of mmap.

type ReporterOptions added in v0.15.0

type ReporterOptions struct {
	// Context is the context to report to reporter for this
	Context Context
	// Reporter if set will receive events for reporting
	Reporter Reporter
}

ReporterOptions contains all options to tracking mmap calls

Jump to

Keyboard shortcuts

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