Skip to main content

Crate lgalloc

Crate lgalloc 

Source
Expand description

A size-classed large object allocator backed by anonymous mappings.

This library contains types to allocate memory outside the heap, supporting power-of-two object sizes. Each size class has its own memory pool.

Allocations use MAP_ANONYMOUS with MADV_HUGEPAGE hints to benefit from transparent huge pages when available.

§Safety

This library is very unsafe on account of unsafe and interacting directly with libc, including Linux extension.

The library relies on anonymous memory mappings. Users must not fork the process because otherwise two processes would share the same mappings, causing undefined behavior because the mutable pointers would not be unique anymore. Unfortunately, there is no way to tell the memory subsystem that the shared mappings must not be inherited.

Clients must not lock pages (mlock), or need to unlock the pages before returning them to lgalloc.

Structs§

BackgroundWorkerConfig
Configuration for lgalloc’s background worker.
Handle
Handle to describe allocations.
LgAlloc
Lgalloc configuration
LgAllocStats
Statistics about lgalloc’s internal behavior.
SizeClassStats
Statistics per size class.

Enums§

AllocError
Allocation errors
PrefetchError
Errors from Handle::prefetch.

Constants§

VALID_SIZE_CLASS
Range of valid size classes.

Functions§

allocate
Allocate a memory area suitable to hold capacity consecutive elements of T.
deallocate
Free the memory referenced by handle, which has been obtained from allocate.
lgalloc_set_config
Set or update the configuration for lgalloc.
lgalloc_stats
Determine global statistics per size class.