Expand description
rusty_alloc core — a pure-Rust remake of mimalloc v2.4.5.
Plan of record: docs/plans/rusty_alloc_v1.md. Module map mirrors upstream C
files 1:1 (plan §6) so every diff-vs-oracle conversation has a shared map.
Milestone status: M4 — per-thread heaps, lock-free cross-thread frees (the loom-modeled xthread/delayed protocol), thread-exit abandonment and segment reclaim. No global lock anywhere on the alloc/free paths.
std note: M4’s TLS fast path uses thread_local! (const-init, !Drop — the
R1 spike measured it at atomic-load parity). A no_std profile returns
post-v1 with the nightly #[thread_local] or a platform TLS shim.
Re-exports§
pub use bins::good_size;
Modules§
- alloc
- Public allocation entry points (mirrors
alloc.c/free.crouting). - arena
- Arenas v1 (M6 subset of upstream
arena.c): pre-reserved OS regions carved into SEGMENT-sized chunks that segment alloc/free recycles instead of round-tripping the OS. Upstream arenas allocate at slice granularity; ours are segment-granular (32 MiB chunks) — sufficient for the §5.9 API and thedisallow_os_alloc/ programmatic-memory use cases; slice-granular arenas are a post-v1 refinement. - bins
- Size-class (bin) geometry, mirroring upstream
page-queue.cmi_bin. - heap
- The heap: per-bin page queues, the small-size direct table, the generic
(heartbeat) allocation path, and free (mirrors
heap.c+ the hot parts ofalloc.c/page.c). Since M4 there is NO global lock: every thread owns its own heap,freeroutes by the segment’s owner id, and cross-thread frees go through the loom-modeled 4-state protocol inpage.rs. - init
- Thread + heap lifecycle (mirrors upstream
init.c+ the abandonment side ofarena-abandon.c). - options
- Options table, environment parsing, and the registered hooks (mirrors
options.c). Option INDICES are ABI: the enum matches the oracle v2.4.5 ordering exactly, deprecated slots included. - os
- OS memory layer over
crate::prim(mirrors upstreamsrc/os.c). - page
- Pages and their three sharded free lists (mirrors upstream
page.cdata side). A page is a slice-span inside a segment holding blocks of ONE size. - prim
- OS primitive layer (mirrors upstream
src/prim/*, plan §6). One backend per platform, selected at compile time; under miri a registry-backed [mock] stands in so the layers above stay testable where FFI cannot run (gate G4). - random
- ChaCha8 CSPRNG (mirrors
random.c): per-heap streams for free-list encoding keys, guarded-object sampling, and page-start randomization. - segment
- Segments: 32 MiB-aligned reservations sliced into 64 KiB slices (M3 subset
of upstream
segment.c). The alignment IS the addressing scheme —ptr → segmentis a mask,ptr → pagetwo shifts and a table walk. - segment_
map - Global segment map (mirrors upstream
segment-map.c): one bit per 32 MiB address window, answering “does this pointer lie in memory we own?” —mi_is_in_heap_region, and thedebug_checksforeign-free guard. - stats
- Stats reporting (mirrors
stats.c): per-heap counters live incrate::heap::Stats; this module aggregates them across the global heap registry, formats reports through the output hook, and queries process metrics (mi_process_info). - types
- Core size constants, mirroring mimalloc v2.4.5
include/mimalloc/types.h.
Constants§
- MI_
COMPAT_ VERSION - The mimalloc version we are API- and ABI-compatible with, in mimalloc’s
encoding (major·10⁴ + minor·10² + patch): v2.4.5.
mi_version()reports this. - VERSION
- Our own semantic version, from the crate manifest.
Functions§
- ptr_
with_ addr - Rebuild a pointer at
addrkeepingp’s provenance. Used wherever an address round-trips through an integer (atomic words, encoded links) — the thrice-learned law: provenance and reachability follow POINTERS. - version
- mimalloc-encoded compat version, as reported by the C ABI
mi_version().