This mini malloc implementation uses a multi-arena system to reduce lock contention in multi-threaded environments.
ID: 12345
Arena: 12345 % 8 = 1
ID: 67890
Arena: 67890 % 8 = 2
ID: 54321
Arena: 54321 % 8 = 1
size = ALIGN8(size)
arena_idx = pthread_self() % NUM_ARENAS
if (size >= MMAP_THRESHOLD) goto mmap_path
find_free_block(&last, size, arena)
block_meta *b = (block_meta *)ptr - 1
if (b->use_mmap) munmap(b, total_size)
b->free = 1; coalesce(b)
__builtin_mul_overflow(nmemb, size, &total)
Total Allocations: 0
Active Blocks: 0
Free Blocks: 0
MMAP Blocks: 0
Total Memory: 0 bytes
Fragmentation: 0%
Arena Striping: Each thread is assigned to an arena based on thread ID modulo number of arenas (8).
Reduced Lock Contention: Threads in different arenas can allocate/free simultaneously.
Cache Locality: Related allocations from the same thread are likely in the same arena.
MMAP Bypass: Large allocations (โฅ64KB) bypass arena system entirely for better performance.