— virtual memory system external
The UVM virtual memory system manages access to the computer's memory resources. User processes and the kernel access these resources through UVM's external interface. UVM's external interface includes functions that:
- initialise UVM subsystems
- manage virtual address spaces
- resolve page faults
- memory map files and devices
- perform uio-based I/O to virtual memory
- allocate and free kernel virtual memory
- allocate and free physical memory
In addition to exporting these services, UVM has two kernel-level processes: pagedaemon and swapper. The pagedaemon process sleeps until physical memory becomes scarce. When that happens, pagedaemon is awoken. It scans physical memory, paging out and freeing memory that has not been recently used. The swapper process swaps in runnable processes that are currently swapped out, if there is room.
UVM has a machine independent and a machine dependent layer. See pmap(9) for the machine dependent layer.
function sets up the UVM system at system boot time, after the copyright has
been printed. It initialises global state, the page, map, kernel virtual
memory state, machine-dependent physical map, kernel memory allocator, pager
and anonymous memory subsystems, and then enables paging of kernel objects.
uvm_init() must be called after machine-dependent
code has registered some free RAM with the
function initialises process limits in the given limit structure. This is
for use by the system startup for process zero, before any other processes
function initialises the uvmexp members pagesize (if not already done by
machine-dependent code), pageshift and pagemask. It should be called by
machine-dependent code early in the
function initialises the swap subsystem.
VIRTUAL MEMORY I/O
map, struct uio
function performs the I/O described in uio on the
memory described in map.
function is the main loop for the page daemon. The arg
argument is ignored.
struct uvm_object *
addr, size_t len,
addr, size_t len,
*oldlenp, void *newp
, size_t newlen,
struct proc *p);
proc *p, vaddr_t
proc *p, struct vnode
*vp, struct ucred
*cred, struct core
uao_reference() functions operate on anonymous
memory objects, such as those used to support System V shared memory.
uao_create() returns an object of size
size with flags:
#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */ #define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */
uao_reference() creates an additional reference to the named anonymous memory object.
uao_detach() removes a reference from the named anonymous memory object, destroying it if removing the last reference.
function checks the access at address addr to
addr + len for rw access, in the
kernel address space.
function calculates the load average and wakes up the swapper if
function provides support for the
CTL_VM domain of
the sysctl(2) hierarchy.
uvm_sysctl() handles the
VM_UVMEXP calls, which return the current load
averages, calculates current VM totals, and returns the uvmexp structure
respectively. The load averages are accessed from userland using the
getloadavg(3) function. The uvmexp structure has all global
state of the UVM system, and has the following members:
/* vm_page constants */ int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */ int pagemask; /* page mask */ int pageshift; /* page shift */ /* vm_page counters */ int npages; /* number of pages we manage */ int free; /* number of free pages */ int active; /* number of active pages */ int inactive; /* number of pages that we free'd but may want back */ int paging; /* number of pages in the process of being paged out */ int wired; /* number of wired pages */ int zeropages; /* number of zero'd pages */ int reserve_pagedaemon; /* number of pages reserved for pagedaemon */ int reserve_kernel; /* number of pages reserved for kernel */ int unused01; /* formerly anonpages */ int vnodepages; /* XXX # of pages used by vnode page cache */ int vtextpages; /* XXX # of pages used by vtext vnodes */ /* pageout params */ int freemin; /* min number of free pages */ int freetarg; /* target number of free pages */ int inactarg; /* target number of inactive pages */ int wiredmax; /* max number of wired pages */ int anonmin; /* min threshold for anon pages */ int vtextmin; /* min threshold for vtext pages */ int vnodemin; /* min threshold for vnode pages */ int anonminpct; /* min percent anon pages */ int vtextminpct;/* min percent vtext pages */ int vnodeminpct;/* min percent vnode pages */ /* swap */ int nswapdev; /* number of configured swap devices in system */ int swpages; /* number of PAGE_SIZE'ed swap pages */ int swpginuse; /* number of swap pages in use */ int swpgonly; /* number of swap pages in use, not also in RAM */ int nswget; /* number of swap pages moved from disk to RAM */ int nanon; /* XXX number total of anon's in system */ int unused05; /* formerly nanonneeded */ int unused06; /* formerly nfreeanon */ /* stat counters */ int faults; /* page fault count */ int traps; /* trap count */ int intrs; /* interrupt count */ int swtch; /* context switch count */ int softs; /* software interrupt count */ int syscalls; /* system calls */ int pageins; /* pagein operation count */ /* pageouts are in pdpageouts below */ int unused07; /* formerly obsolete_swapins */ int unused08; /* formerly obsolete_swapouts */ int pgswapin; /* pages swapped in */ int pgswapout; /* pages swapped out */ int forks; /* forks */ int forks_ppwait; /* forks where parent waits */ int forks_sharevm; /* forks where vmspace is shared */ int pga_zerohit; /* pagealloc where zero wanted and zero was available */ int pga_zeromiss; /* pagealloc where zero wanted and zero not available */ int unused09; /* formerly zeroaborts */ /* fault subcounters */ int fltnoram; /* number of times fault was out of ram */ int fltnoanon; /* number of times fault was out of anons */ int fltnoamap; /* number of times fault was out of amap chunks */ int fltpgwait; /* number of times fault had to wait on a page */ int fltpgrele; /* number of times fault found a released page */ int fltrelck; /* number of times fault relock called */ int fltrelckok; /* number of times fault relock is a success */ int fltanget; /* number of times fault gets anon page */ int fltanretry; /* number of times fault retrys an anon get */ int fltamcopy; /* number of times fault clears "needs copy" */ int fltnamap; /* number of times fault maps a neighbor anon page */ int fltnomap; /* number of times fault maps a neighbor obj page */ int fltlget; /* number of times fault does a locked pgo_get */ int fltget; /* number of times fault does an unlocked get */ int flt_anon; /* number of times fault anon (case 1a) */ int flt_acow; /* number of times fault anon cow (case 1b) */ int flt_obj; /* number of times fault is on object page (2a) */ int flt_prcopy; /* number of times fault promotes with copy (2b) */ int flt_przero; /* number of times fault promotes with zerofill (2b) */ /* daemon counters */ int pdwoke; /* number of times daemon woke up */ int pdrevs; /* number of times daemon rev'd clock hand */ int pdswout; /* number of times daemon called for swapout */ int pdfreed; /* number of pages daemon freed since boot */ int pdscans; /* number of pages daemon scanned since boot */ int pdanscan; /* number of anonymous pages scanned by daemon */ int pdobscan; /* number of object pages scanned by daemon */ int pdreact; /* number of pages daemon reactivated since boot */ int pdbusy; /* number of times daemon found a busy page */ int pdpageouts; /* number of times daemon started a pageout */ int pdpending; /* number of times daemon got a pending pagout */ int pddeact; /* number of pages daemon deactivates */ int unused11; /* formerly pdreanon */ int unused12; /* formerly pdrevnode */ int unused13; /* formerly pdrevtext */ int fpswtch; /* FPU context switches */ int kmapent; /* number of kernel map entries */
function increases the stack segment of process p to
function generates a coredump on vnode vp for process
p with credentials cred and core
header description in chdr.
The structure and types whose names begin with “vm_” were named so UVM could coexist with BSD VM during the early development stages.
sysctl(2), getloadavg(3), kvm(3), ddb(4), options(4), pmap(9)
Charles D. Cranor, Design and Implementation of the UVM Virtual Memory System, D.Sc. dissertation, Department of Computer Science, Sever Institute of Technology, Washington University, St. Louis, Missouri, August 1998.
The UVM virtual memory system was developed at Washington University in St. Louis. UVM's roots lie partly in the Mach-based 4.4BSD VM system, the FreeBSD VM system, and the SunOS4 VM system. UVM's basic structure is based on the 4.4BSD VM system. UVM's new anonymous memory system is based on the anonymous memory system found in the SunOS4 VM (as described in papers published by Sun Microsystems, Inc.). UVM also includes a number of features new to BSD including page loanout, map entry passing, simplified copy-on-write, and clustered anonymous memory pageout.
UVM appeared in OpenBSD 2.9.
Charles D. Cranor <email@example.com> designed and implemented UVM.
Matthew Green <firstname.lastname@example.org> wrote the swap-space management code.
Chuck Silvers <email@example.com> implemented the aobj pager, thus allowing UVM to support System V shared memory and process swapping.
Artur Grabowski <firstname.lastname@example.org> handled the logistical issues involved with merging UVM into the OpenBSD source tree.