Level 7 of 12 · about 3 weeks
Memory in practice
How real programs use memory: malloc and the heap, heap bugs and their tools, the stack, memory-mapped files, shared memory, huge pages, swap, overcommit and the OOM killer, and how to trace where memory went.
Modules
Core: everyone needs it. Common: most jobs use it. Specialist: optional depth, safe to skip on a first read.
1
How malloc works
How a C program gets memory in small pieces from an allocator that gets it in large pieces from the kernel
Core 7 parts · about 5 hours
2
Heap bugs and the tools that find them
The ways a C program misuses heap memory, why many of them do not crash, and how AddressSanitizer and Valgrind catch them
Core 7 parts · about 5 hours
3
The stack and stack overflow
How function calls use memory, how the kernel grows the stack on demand, and what happens when it runs out
Core 7 parts · about 4 hours
4
Memory-mapped files and mmap
How a file becomes part of the address space, what private and shared mappings do, and when mapping beats read and write
Core 7 parts · about 5 hours
5
Shared memory between processes
How two processes use the same physical pages, why it is the fastest way to exchange data, and what it demands from the programmer
Core 7 parts · about 5 hours
6
Huge pages
Why Linux offers pages of 2 MiB, the two ways to get them, what they save, what they cost, and why they must be measured
Common 7 parts · about 4 hours
7
Swap, overcommit and the OOM killer
What happens when programs ask for more memory than the machine has, from promises the kernel makes to the process it ends
Core 7 parts · about 5 hours
8
Case study, where did the memory go
Reading the memory numbers of a running process, splitting them by kind and by mapping, and tracing growth back to a line of code
Core 7 parts · about 5 hours