Skip to content

Repository files navigation

AethAlloc

A high-performance memory allocator optimized for network packet processing and memory-constrained workloads.

Overview

AethAlloc is a production-grade memory allocator featuring:

  • Thread-Local Caching: Lock-free per-thread free lists with 14 size classes (16B - 64KB)
  • SIMD-Safe Alignment: All allocations are 16-byte aligned for AVX/SSE safety
  • O(1) Anti-Hoarding: Batch transfer to global pool prevents memory bloat in producer-consumer patterns
  • Zero Fragmentation: 11x better memory efficiency than glibc in long-running workloads

Architecture

┌─────────────────────────────────────────────────────────────────┐
│ Thread N │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ ThreadLocalCache │ │
│ │ heads[14] ──► Free List (size class 0-13) │ │
│ │ counts[14] ──► Cached block counts │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ Anti-Hoarding Threshold (4096) │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ GlobalFreeList[14] │ │
│ │ Lock-free Treiber Stack (O(1) batch push) │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ PageAllocator │
│ mmap/munmap backend with 4KB page granularity │
│ PageHeader: magic + num_pages + requested_size │
└─────────────────────────────────────────────────────────────────┘

Crates

CrateDescription
aethalloc-coreCore algorithms (page allocator, size classes, lock-free stack)
aethalloc-abiC ABI exports for LD_PRELOAD injection

Deployment Targets

m720q Gateway (Multi-WAN Routing)

  • Producer-Consumer: 447K ops/s (competitive with all allocators)
  • Anti-hoarding: Prevents memory bloat in packet handoff workloads
  • Guarantees line-rate packet inspection

X1 Yoga Workstation (Desktop)

  • Fragmentation RSS: 17 MB (1.8x better than glibc)
  • Prevents memory bloat in long-running desktop environments
  • Preserves NVMe lifespan and battery capacity

Building

# Build the shared library
nix build
# Or with cargo
cargo build --release -p aethalloc-abi

Usage

# LD_PRELOAD injection
LD_PRELOAD=./target/release/libaethalloc_abi.so ./your-program
# With Nix wrapper
nix run .#suricata-aeth

Feature Flags

FeatureDescriptionDefault
magazine-cachingHoard-style magazines with global poolYes
simple-cacheThread-local free-list per size classNo
metricsEnable allocation metrics collectionNo

Benchmarks

Test System: Intel Core i5-8365U (4 cores, 8 threads) @ 1.60GHz, 16 GB RAM

Quick Summary

BenchmarkAethAllocBest CompetitorResult
Multithread Churn17.0M ops/sAethAllocWINNER
Packet Churn205K ops/sjemalloc: 218K ops/s#2 (-6%)
Tail Latency P99106nsjemalloc: 106nsTIED BEST
Tail Latency P99.9927µsAethAllocWINNER
Fragmentation RSS17.0 MBAethAllocWINNER (1.8x better)
Producer-Consumer447K ops/smimalloc: 441K ops/sTIED

See BENCHMARK.md for full methodology, detailed results, and analysis.

Technical Implementation

SIMD Alignment

All allocations return 16-byte aligned pointers:

constCACHE_HEADER_SIZE:usize = 16;// Ensures AVX/SSE safety

O(1) Batch Push

Anti-hoarding uses single CAS for entire batch:

// Walk local list to find tailwhile walked < flush_count {
batch_tail = (*batch_tail).next;}// Single atomic swap for entire batchGLOBAL_FREE_LISTS[class].push_batch(batch_head, batch_tail);

Size Classes

14 power-of-two size classes from 16 bytes to 64KB:

ClassSizeClassSize
016B72KB
132B84KB
264B98KB
3128B1016KB
4256B1132KB
5512B1264KB
61KB13(reserved)

Testing

# Run all tests
cargo test --all
# Run benchmarks
gcc -O3 -pthread benches/packet_churn.c -o /tmp/packet_churn
LD_PRELOAD=./target/release/libaethalloc_abi.so /tmp/packet_churn
# Run stress tests
gcc -O3 benches/corruption_test.c -o /tmp/corruption_test
LD_PRELOAD=./target/release/libaethalloc_abi.so /tmp/corruption_test

Status

ComponentStatus
Core allocator✅ Complete
Thread-local caching✅ Complete
SIMD alignment✅ Complete
O(1) anti-hoarding✅ Complete
Lock-free global pool✅ Complete
Benchmarks✅ Complete
Stress tests✅ Complete
CI/CD✅ Complete

License

MIT

About

Rust Memory Hypervisor implementing asynchronous metadata offloading, hardware-enforced spatial safety, and virtual memory page compaction.

Topics

Resources

Stars

14 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages