The Linux Memory Manager

Chapters

  1. Allocators - Describes in detail how dynamic memory allocation works, the trade-offs, the algorithms - essentially the what, why and how of memory allocation.
  2. Physical memory - The buddy allocator, struct page*, struct folio*, the kernel functions that provide memory (e.g. alloc_pages()), nodes, zones (in brief), watermarks, migrate types, page blocks, GFP flags, migrate types, detailed analysis of physical page allocation and freeing.
  3. Virtual memory - The why, what and how, page tables, page table flags, page table sizes, virtual memory layout, direct mapping, kernel/userland split and a detailed description of vmalloc().
  4. Process memory - An overview of how userland memory is structured - mm_struct, Process VMAs, Copy-on-Write and more.
  5. Memory mapping - A description of how memory mapping is performed within the kernel - mmap, brk (used by malloc()) and how mappings (via VMAs) are split/merged.
  6. Page faults - A detailed examination of how page faults are handled and propagated within the kernel.
  7. The reverse mapping - A detailed look at how the kernel maps raw physical pages of userland memory back to the abstract VMA representation.
  8. LRU vectors and folio batches - A description of how raw memory pages interact with LRU vectors, a key mechanism for reclaim, and how kernel operations are batched using folio batches.
  9. Manipulating userland memory - A detailed examination of functions like madvise(), mprotect(), mlock(), mremap() and how they manipulate userland memory.
  10. The page cache - A detailed look into the page cache, how it interacts with the Linux virtual file system, read-ahead, read-behind, writeback, what happens under memory pressure and generally a very focused discussion of how the memory subsystem interacts with VFS. Potential overlap with the process memory chapter.
  11. Reclaim and memory pressure - A detailed explanation of how reclaim operations, what direct and indirect reclaim are, how it interacts with demand paging, higher order page starvation, etc.
  12. Slab memory - A discussion of the slab memory allocator with a focus on SLUB, kmalloc(), kfree(), slab caches, shrinkers and how they interact with the rest of the memory management subsystem.
  13. Compaction and migration - How direct and indirect page compaction works, kcompactd and how folios are migrated from one area of memory to another.
  14. Swap memory - A detailed description of how the swap operations in the kernel and how pages are paged out and paged back in again.
  15. Huge pages - A deep dive into hugetlb, Transparent Huge Pages (THPs), the why what, how and when.
  16. The Out Of Memory (OOM) killer - A deep dive into how it works, how to tune it, the what, why and how.
  17. Practical memory management - How to decode the memory manager - procfs, tuneables, dmesg, tracepoints, eBPF and more. A description of procfs/sysfs/sysrq-m interfaces and how to use and decode them, generally a practical 'how to' for sysadmins/developers. Additionally covering DAMON and eBPF.
  18. Appendix: Folio flags - A list of all folio flags with detailed descriptions.
Email me when it's released!