• Sources: primary
  • Summary: The post walks through Allocator implementations for a 32 MiB bump arena that frees a million-node linked structure in one deallocation, an accounting wrapper that counts live bytes, and a stack-first allocator that spills to the heap. It also shows a 4096-byte block-aligned allocator for O_DIRECT file reads and the author's thresher crate, which Logfire uses to trigger heap profiles when allocation crosses a threshold.
  • Why it matters: Collections such as Vec can now take a per-use allocator on stable Rust, so arena and accounting strategies no longer need nightly or bespoke container types.
  • Background: Rust's Allocator trait lets a collection be generic over where its memory comes from, as in Vec<T, A>, separate from the single process-wide GlobalAlloc. Before stabilization, crates such as bumpalo, smallvec and aligned-vec each shipped their own container types to get these behaviors. O_DIRECT bypasses the Linux page cache but requires buffers aligned to the device's logical block size.