Chapters
- Allocators - Describes in detail how dynamic memory
allocation works, the trade-offs, the algorithms - essentially the
what, why and how of memory allocation.
- Physical memory - The buddy allocator, struct page*, struct
folio*, the kernel functions that provide memory (e.g. alloc_pages()),
nodes, zones (in brief, more detailed in NUMA chapter), watermarks,
migrate types, page blocks, GFP flags, migrate types, detailed
analysis of physical page allocation and freeing.
- 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().
- Process memory - mm_struct, Process VMAs, page faults,
demand paging, dynamic stack allocation, how memory is copied between
userland/kernel, how malloc() actually feeds into the kernel
(e.g. sbrk(), mmap()). Copy-on-write, forking, basics of huge pages
(covered in more detail in huge pages chapter), rmaps, pagevecs, lru &
lruvecs. GUP.
- 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.
- 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.
- 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.
- Compaction and migration - How direct and indirect page
compaction works, kcompactd and how folios are migrated from one area
of memory to another.
- Swap memory - A detailed description of how the swap
operations in the kernel and how pages are paged out and paged back
in again.
- NUMA - A detailed dive into Non-Uniform Memory Access
(NUMA) sytems, discussing NUMA balancing, how different NUMA
architectures are modelled in the kernel and how everything
interacts.
- cgroups - A dive into memory control groups, how the are
implemented and how they interact and can be configured, a chapter
that will be of particular interest for those interested in
containerisation.
- Huge pages - A deep dive into hugetlb, Transparent Huge
Pages (THPs), the why what, how and when.
- The Out Of Memory (OOM) killer - A deep dive into how it
works, how to tune it, the what, why and how.
- 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.
- Device memory - A deep dive into managing memory for device
drivers covering topics such as ioremap() and friends.
- Debugging the memory manager - A practical discuss around
how to effectively debug the memory management subsystem of the
kernel, e.g. the use of CONFIG_DEBUG_PAGEALLOC and friends.
- Appendix: Folio flags - A list of all folio flags with
detailed descriptions.