Virtual memory and page faults
Quick answer
Virtual addresses are translated by hardware with kernel-managed page tables. A page fault is an exception that may be handled normally, not necessarily a program crash.
Accessing an untouched allocated page can trigger a normal fault that makes memory available to the process. A fault on an invalid access may instead terminate it. Fault counts alone cannot distinguish a healthy workload from a bug; inspect type and context.
Prepare the practice environment
Run python3 lab-fixtures/kernel/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not write kernel attributes, load modules, or change boot settings. Supplied records are fictional; read only the selected non-sensitive live fields. Review the lab guide.
Prerequisites
Review: Tasks, scheduling and interrupts.
How it works
The MMU translates virtual page numbers to physical frames and checks permissions; the TLB caches translations. Page size and table depth depend on architecture and configuration. A valid mapping may not yet have a resident page; demand paging can allocate a zero-filled page, map cached file data or retrieve data from storage. Copy-on-write initially shares pages and creates a private copy on a permitted write. Minor faults generally need no I/O for resolution, major faults require I/O according to kernel accounting; an invalid access can instead result in SIGSEGV. Virtual size includes reserved mappings, RSS counts resident pages and PSS apportions shared resident pages. Do not assume any particular virtual layout or reveal addresses of unrelated processes.
Try the examples
getconf PAGE_SIZE | grep -Eq '^[1-9][0-9]*$' && printf 'page size reported\n'The actual page size is variable; the check validates a positive numeric result.
Expected stdout:
page size reportedA 4096-byte teaching page and synthetic mapping 3→9 are used; this is not actual physical memory.
Expected stdout:
page=3 offset=17 frame=9 physical=36881pmap "$$" | grep -Eq '^ total +[0-9]+K' && printf 'mapping total present\n'pmap reports mappings for the current shell; the numeric value is not fixed.
Expected stdout:
mapping total presentCommon mistakes
Page fault does not imply SIGSEGV. RSS is not unique physical usage and virtual size is not resident memory.
Practice
Calculate page and offset for the example, then explain a valid demand fault versus an invalid access.
Related references
Study: pmap. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Virtual memory and page faults — Knowledge Check
Apply kernel concepts to read-only observations and synthetic models.
What caches address translations?
Can a valid access cause a page fault?
What does PSS do for shared pages?
With page size 4096, offset of address 12305?