Skip to main content

Module mmap

Module mmap 

Source
Expand description

Audited OS-interface island: read-only memory mapping of a checkpoint file.

This exists so weights can be addressed without being read. A 1.7 GB checkpoint loaded with fs::read costs 1.7 GB of resident anonymous memory before a single tensor is touched; mapped read-only, the same file costs address space, and only the pages actually dereferenced — the embedding rows a prompt names, the layers a frame walks — are ever faulted in. That difference is the whole point of the .fttsq access-class design, and it cannot be expressed in safe Rust.

Scope of the island: mmap, munmap, madvise, mincore, and page-size discovery. No kernels, no arithmetic, no parsing. Everything above this file — the safetensors directory, the census, every accessor — is forbid(unsafe_code) and operates on the &[u8] this hands out.

§The truncation hazard, stated plainly

A file that is truncated by another process while mapped will fault with SIGBUS on access to the vanished pages. Rust cannot prevent this, and neither can any mmap wrapper — it is a property of the syscall. We accept it for the same reason every mmap-based loader does, under a narrow usage contract: the mapped file is a content-addressed model artifact that is written once and read many times, never appended to or truncated in place while an engine holds it. Callers that cannot honour that contract should read the file instead.

Structs§

MappedFile
A read-only, private memory mapping of a whole file.

Enums§

MemoryAdvice
A kernel page-cache hint for a byte range within a mapped artifact.
MemoryAdviceOutcome
What became of one MemoryAdvice request.
MemoryResidency
An observation of which pages in one mapped byte range are currently resident.