memmap2
Cross-platform Rust API for memory-mapped file IO on Unix and Windows
Repository Health
Technical Analysis
memmap2 is a cross-platform Rust library for memory-mapped file IO, exposing Mmap and MmapMut types that let a File be mapped into a process’s address space and accessed as a plain byte slice — &[u8] or &mut [u8] — instead of going through explicit read/write syscalls. It is a maintained fork of the original memmap crate, supporting file-backed maps, anonymous maps, copy-on-write maps, read-only maps, synchronous and asynchronous flushing, executable mappings, stack-backed mappings, and (on Linux) huge pages, with platform-specific backends for Unix (via mmap/libc) and Windows (via the Win32 mapping APIs).
Because mapping a file directly into memory avoids the copy overhead of standard read calls and lets the OS page cache manage data transparently, memmap2 is widely used by databases, parsers, and any Rust code that needs to work with large files efficiently — it has become the de facto standard memory-mapping crate in the Rust ecosystem, with hundreds of millions of downloads across dependents ranging from embedded databases to font- and font-rendering libraries.
What You Get
MmapandMmapMuttypes for read-only and read-write file-backed memory maps, plusMmapOptionsfor configuring offset, length, and mapping flags- Anonymous memory maps not backed by any file, for cases needing raw mapped memory (e.g. as a growable buffer or guarded stack)
- Copy-on-write mappings so writes to a mapped file are never persisted back to disk
- Platform-specific backends for Unix (unix.rs, built on
libc) and Windows (windows.rs, built on Win32 mapping APIs), plus a stub fallback for other targets - Advice APIs (
Advice/UncheckedAdviceon Unix) for hinting access patterns to the OS, plus optional huge-page support on Linux
Common Use Cases
- Parsing or indexing large files (databases, log files, binary formats) without loading the entire contents into a heap-allocated buffer
- Building embedded/append-only databases or storage engines that rely on the OS page cache instead of custom buffer management
- Sharing read-only data between processes via a common memory-mapped file
- High-performance font, archive, or binary-format parsers that want zero-copy slice access to file contents
Under The Hood
Architecture The crate’s public API lives in src/lib.rs (2,375 lines), centered on MmapOptions as a builder and Mmap/MmapMut/MmapRaw as the resulting handle types, all of which Deref/DerefMut to [u8] for slice-like access. Platform differences are isolated behind a mod os indirection (#[cfg_attr(unix, path = "unix.rs")] / windows.rs / stub.rs), so the public types are identical across platforms while the underlying MmapInner implementation swaps per-OS: unix.rs (550 lines) wraps POSIX mmap/munmap/mprotect via libc, windows.rs (545 lines) wraps CreateFileMappingW/MapViewOfFile, and stub.rs provides a non-functional fallback for unsupported targets. src/advice.rs (422 lines) adds Unix-only madvise-based access hints as a separate, optional module. Tech Stack Pure Rust with a thin libc dependency gated to cfg(unix) and an optional stable_deref_trait integration for interop with crates like owning_ref; dev-dependencies (tempfile, owning_ref) support the test suite. Edition 2021, MSRV 1.65, single-crate repository (not a workspace) maintained as a fork of the original danburkert/memmap-rs. Code Quality The crate opts into #![deny(clippy::all, clippy::pedantic)] and #![deny(unsafe_op_in_unsafe_fn)] at the top of lib.rs, a notably strict lint posture for a crate whose core job is wrapping unsafe OS mapping calls; doc comments on Mmap/MmapMut include runnable examples (file.read_to_end + Mmap::map doctest) that double as documentation tests in CI. Given the crate directly wraps unsafe syscalls (mmap, CreateFileMappingW), correctness depends heavily on careful unsafe-block auditing rather than being fully provable through ordinary unit tests, though the examples/ directory (examples/cat.rs) demonstrates realistic usage patterns. API Design The Deref-to-slice design means Mmap/MmapMut behave like ordinary byte slices everywhere a &[u8]/&mut [u8] is expected, minimizing the learning curve for anyone already comfortable with Rust slices; MmapOptions centralizes the more advanced configuration (offset, length, populate, huge pages) behind a builder rather than proliferating constructor variants.
Used by 7 apps in this directory
Anarlog
Note Taking · AI Assistants · Productivity
Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.
ClickHouse
Databases · Analytics · Data Engineering
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
Fluree DB
Databases
A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
Murr
Databases
A RocksDB-based NVMe/S3 cache purpose-built for AI inference workloads — a faster Redis replacement optimized for batch, low-latency, zero-copy reads and writes between data pipelines and inference apps.
QuestDB
Databases · Analytics
A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.
Spacedrive
File Storage · Collaboration
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.