Memory Architecture & Custom Allocators
Before we can understand GPU VRAM bottlenecks, KV-cache paging, or high-throughput LLM serving, we must demystify how computers actually allocate, align, and address physical and virtual memory.
Day 1: Virtual Memory Layout & Struct Alignment
✓ CompletedToday we mapped out the 64-bit Linux process virtual address space (Text, Data, BSS, Heap, Stack) and measured the mechanical penalty of memory alignment and silent compiler struct padding.
Tensors in PyTorch/CUDA are contiguous blocks aligned to 256-byte or 512-byte boundaries for vectorized memory coalescing.
When activation tensors and KV-cache blocks fragment memory, an inference pipeline throws
"CUDA: Out of Memory" even when nvidia-smi shows gigabytes of total free VRAM.
Understanding allocator coalescence is the bedrock of GPU optimization.
Upcoming Week 1 Sprints:
- Day 2: Raw Syscalls & The Program Break (
sbrkbump allocator) - Day 3: Metadata Headers & Free-List Traversal (
malloc/free) - Day 4: External Fragmentation & Boundary-Tag Coalescence
- Day 5: Microbenchmarks:
my_mallocvsglibc ptmalloc - Weekend Capstone: Synthesis essay & Substack/Medium release