Virtual memory

FreeBSD’s virtual memory system connects a process’s address space to the objects that supply its data and the physical pages that currently hold it. The machine-independent implementation lives primarily in sys/vm; architecture-specific pmap implementations manage hardware translations.

An address-space mapping, a VM object, and a resident page have different lifetimes. Understanding those lifetimes is the starting point for following faults, copy-on-write, file mappings, and memory pressure.

Finding the implementation

Source map

Source

Responsibility

vm_map.c, vm_map.h

Address ranges, protections, mapping changes, and lookup.

vm_object.c, vm_object.h

Backing objects, resident-page indexing, and object lifetimes.

vm_page.c, vm_page.h

Physical-page metadata, allocation, busy state, and wiring.

vm_fault.c

Resolving a virtual address to a page and installing a translation.

vm_pager.c, vm_pager.h

Dispatch to the object type’s backing-store operations.

vnode_pager.c, swap_pager.c

File-backed and swap-backed object behavior.

vm_pageout.c, vm_pagequeue.h

Page aging, reclamation, and laundry processing.

vm_phys.c, vm_domainset.c, vm_reserv.c

Physical allocation, NUMA policy, and page reservations.

uma_core.c, uma.h

The kernel’s Universal Memory Allocator for object-sized allocations.

All paths in this table are relative to sys/vm. sys/vm/pmap.h declares the common translation interface; its implementations are in the architecture directories under sys.

Connections to other topics

File-backed objects connect VM to Virtual file system through the vnode pager. Waiting for a busy page or memory allocation can block a thread, connecting VM to Scheduling. UMA allocates many kernel structures, but its zones and caches are a separate layer from user address-space mappings.