Bounded global allocator — architecture¶
Design notes for the taktora-bounded-alloc crate (Bounded global allocator (FEAT_0040)).
Captures the design decisions, the building-block decomposition, and
the concrete implementation footprint. Test cases live in
Bounded global allocator — verification.
Solution strategy¶
Context. The allocator must serve every allocation from a statically-sized arena (Pre-allocated fixed-block a... (REQ_0300)). Two axes of choice:
Decision. Const generics for the caps; hand-rolled fixed-block bitmap for free-list management. Alternatives considered.
Consequences. ✅ Zero runtime overhead beyond a single |
Building blocks¶
The
The diagram below illustrates how the four sub-components are
arranged inside the single
graph TD
subgraph Static["static BoundedAllocator<N, S>"]
Arena["Arena<br/>UnsafeCell<[u8; N×S]><br/>(repr(align(S)))"]
Bitmap["Free bitmap<br/>[AtomicU64; (N+63)/64]<br/>bit i = 1 → block i free"]
Counters["Counters<br/>alloc_count · dealloc_count<br/>peak_in_use (AtomicUsize)"]
Lock["Lock flag<br/>AtomicBool<br/>(false = open)"]
end
Caller["caller: alloc(layout)"]
Caller -->|"1. load(Acquire)"| Lock
Lock -->|"true → panic"| Panic["panic (abort)"]
Lock -->|"false → size/align check"| Check{"layout.size ≤ S?"}
Check -->|"no → return null"| Null["null → alloc_error_handler → abort"]
Check -->|"yes → bit-scan"| Bitmap
Bitmap -->|"no free bit → return null"| Null
Bitmap -->|"CAS 1→0 on bit i"| Arena
Arena -->|"pointer to block i"| Counters
Counters -->|"fetch_add alloc_count<br/>update peak_in_use"| Result["return ptr"]
Lifetime contract — the entire structure is intended for
|
Implementation¶
Workspace integration
``crates/taktora-bounded-alloc/Cargo.toml``
``crates/taktora-bounded-alloc/src/lib.rs``
The lock lifecycle (Lock-after-init panic mode (REQ_0302)) is one-way — once
stateDiagram-v2
[*] --> Open : static initialisation
Open --> Open : alloc / dealloc (normal operation)
Open --> Locked : lock() — stores true (Release)
Locked --> Locked : dealloc (still permitted)
Locked --> Abort : alloc / alloc_zeroed / realloc\n→ panic → abort
``crates/taktora-bounded-alloc/tests/``
``crates/taktora-bounded-alloc/examples/fail_closed.rs``
``crates/taktora-executor/tests/no_alloc_dispatch.rs`` migration
|