Understanding Linux Memory Management: Page Faults, mmap, and userfaultfd
By
shayonj
A five-star bake. Worth schmearing, sharing, saving.
Summary
This technical article explores Linux memory management concepts including page faults, mmap system calls, and userfaultfd. The author explains how Linux uses demand paging to lazily allocate physical memory, how mmap creates virtual-to-physical mappings, and how userfaultfd allows userspace programs to handle page faults. The practical motivation was optimizing VM snapshot restoration by lazily populating guest memory, but the article focuses on the underlying Linux memory model that enables such optimizations.
Key quotes
· 4 pulledThe motivation was a specific problem, which was making Virtual Machine (VM) snapshot restore fast by lazily populating guest memory.
But the underlying mechanisms are general Linux concepts that I think are worth understanding on their own.
This post is less about any specific Virtual Machine Monitor (VMM) and more about the Linux memory model that makes lazy restore possible.
How Linux demand-pages memory, what mmap does to physical pages, why replacing a mapping breaks direct memory access and shared memory, and how userfaultfd lets you lazily populate memory without destroying the mapping.
You might also wanna read
Understanding ELF Binary Execution on Linux Systems
This technical article explains how ELF (Executable and Linkable Format) binaries are executed on Linux systems. It covers the detailed proc
Restartable Sequences: A Linux Kernel Feature for Lock-Free Thread-Safe Programming
This article explores restartable sequences (rseq), a Linux kernel feature introduced in version 4.18 (circa 2018) that enables creation of
How to Install Ubuntu Server 26.04 on Raspberry Pi: A Step-by-Step Guide
A practical guide for installing Ubuntu Server 26.04 on Raspberry Pi models. The article covers using Raspberry Pi Imager or direct download
Zig Days: Collaborative Full-Day Programming Events for the Zig Community
Zig Days are full-day collaborative programming events organized by the Zig community, typically held on Saturdays. Participants meet in the
Flatpak to require systemd in next major version, dropping support for alternative init systems
Flatpak, a universal Linux app distribution system that previously prided itself on being distribution-agnostic (including support for non-s
Omarchy is not a Linux distribution — it's Arch Linux with DHH's personal dotfiles
The article criticizes omarchy, a project by DHH that markets itself as a Linux distribution. The author argues omarchy is not a true distro
