A comprehensive ~25,000-word deep dive into virtual memory covering the full stack from first principles to Linux internals. Uses a narrative dialogue format between a process (Alloca) and the Kernel to explain: why virtual memory exists, virtual address space layout (text/data/BSS/heap/stack segments), hierarchical 4-level page tables (PGD/PUD/PMD/PTE) on x86-64, MMU and TLB mechanics, demand paging and page faults, VMAs vs page table entries, memory protection via permission bits (W^X), anonymous vs file-backed memory, memory overcommit and the OOM killer, copy-on-write, mmap, NUMA topology, and performance implications for data-intensive workloads. Includes observability commands for inspecting RSS/PSS, TLB behavior, and NUMA placement on Linux.
Table of contents
How to Read This ArticleThe Need for Virtual MemorySize of Virtual MemoryThe Virtual Memory Address Space LayoutHow are Virtual Addresses Translated to Physical AddressesMemory Protection via Permission BitsDemand PagingWhen Physical Memory Runs Out: Swap and the Dual Meaning of the Present BitCopy-on-Write and ForkMemory-Mapped FilesAnonymous, File-Backed, and Shared MemoryPage Reclaim: How the Kernel Chooses What to EvictMemory Access Patterns and VM PerformanceHuge Pages and TLB EfficiencyTLB Shootdowns on Multi-Core SystemsNUMA (Non-Uniform Memory Access): The Physical Topology of MemoryObserving Virtual Memory in PracticeWhat We’ve LearnedSort: