mnemosyne-backend
Memory backend implementations for the
Mnemosyne allocator: the layer that
turns MemoryBackend calls into OS virtual-memory operations.
[]
= "0.5"
Layout, by concern
mapping— theMemoryBackendWrapperstruct and the single centralimpl MemoryBackend for MemoryBackendWrapperblock (trait coherence requires one file).allocateanddeallocatelive inline;make_guard,page_reset, anddecommitdelegate to the helpers below via#[inline(always)]static dispatch.guard—PROT_NONE(mprotect) /PAGE_NOACCESS(VirtualProtect) guard installation, used for segment-tail out-of-bounds trapping.reset—page_reset(MADV_DONTNEEDon Linux,MADV_FREEon macOS/FreeBSD,MEM_RESETon Windows) anddecommit. These drop physical backing while keeping the virtual mapping committed.recorders— telemetry counter statics and theBackendMemoryStatssnapshot, reachable publicly throughbackend_memory_stats().backends—UnixBackend,WindowsBackend, the CUDA backends (CudaUnifiedBackend,CudaDeviceBackend, tier-keyedCudaHbmBackendandCudaGddrBackend,CudaHostPinnedBackend), andDefaultBackend, which selects the OS-conditional backing at compile time.
Release accounting
MemoryBackend::deallocate returns a release-success boolean and is
#[must_use]. current_mapped_bytes is decremented only on confirmed OS
release; a failed munmap/VirtualFree routes through record_unmap_failure
so the counter cannot under-count still-mapped bytes. page_reset and
make_guard never decrement it — the mapping stays owned, only the resident set
drops.
On Linux, segment-sized mappings receive a madvise(MADV_HUGEPAGE) hint. The
hint is advisory; failure never invalidates the mapping.
Licensed under MIT OR Apache-2.0.