/work/deterministic-allocator
AmanShah
Brief
amanashishshah@gmail.com

© 2026 Aman Shah

Recruiter mode

Self-directed

Work/

Deterministic Memory Allocator

Deterministic Memory Allocator, at a glance

memory systems

concurrency

Project overview

Hybrid slab + TLSF allocator for HFT

A hybrid slab + TLSF memory allocator that serves every malloc/free in constant worst-case time and runs lock-free across threads.

Role

  • Systems engineer

Date

2026

Field

Quant

Stack

C++17, TLSF, Lock-free, mmap

O(1) worst case

0.24% fragmentation

lock-free (TSan-clean)

Context

A custom C++17 allocator built for the high-frequency-trading traffic profile, where a single multi-microsecond allocation stall during a market burst is a missed fill.

Deterministic Memory Allocator, image 1
Deterministic Memory Allocator, image 2
Deterministic Memory Allocator, image 3
Deterministic Memory Allocator, image 4

Deterministic Memory Allocator

Deterministic Memory Allocator, image 1

The hard part

General-purpose allocators are tuned for the average case; low-latency systems instead need deterministic allocation with no tail stalls and no lock contention on the hot path.

Deterministic Memory Allocator, image 3

What it took

  • Built a slab engine with an intrusive free-list and zero per-object header for fixed-size records, routing header-less frees correctly through a sorted address-range registry.
  • Implemented a Two-Level Segregated Fit engine whose two-level bitmap index finds a good-fit block in two hardware bit-scans (no loop), with splitting and boundary-tag coalescing that bounds internal waste below 1/32 ≈ 3.1%.
  • Made the hot path lock-free across threads with per-thread caches over CAS-carved superblocks; cross-thread frees are pushed onto a lock-free MPSC remote-free stack threaded through the freed block's own memory and drained by the owner on its next allocation.

Outcome

Achieves flat O(1) latency across 16 B–64 KB, holds fragmentation at 0.24% of live bytes, runs a p99.9 tail ~6–10× tighter than the system allocator, stays lock-free under ThreadSanitizer, and passes 74 tests under release, ASan, and TSan.