xref: /netbsd-src/share/man/man9/uvm.9 (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1.\"	$NetBSD: uvm.9,v 1.13 2000/05/07 17:09:32 mrg Exp $
2.\"
3.\" Copyright (c) 1998 Matthew R. Green
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. The name of the author may not be used to endorse or promote products
15.\"    derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\" XXX this manual sets nS to 1 or 0 in the description, to obtain
30.\" synopsis-like function prototypes.  any better way?
31.\"
32.Dd March 26, 2000
33.Dt UVM 9
34.Os
35.Sh NAME
36.Nm uvm
37.Nd virtual memory system external interface
38.Sh SYNOPSIS
39.Fd #include <sys/param.h>
40.Fd #include <vm/vm.h>
41.Fd #include <uvm/uvm.h>
42.Sh DESCRIPTION
43The UVM virtual memory system manages access to the computer's memory
44resources.  User processes and the kernel access these resources through
45UVM's external interface.  UVM's external interface includes functions that:
46.Pp
47.Bl -hyphen -compact
48.It
49initialise UVM sub-systems
50.It
51manage virtual address spaces
52.It
53resolve page faults
54.It
55memory map files and devices
56.It
57perform uio-based I/O to virtual memory
58.It
59allocate and free kernel virtual memory
60.It
61allocate and free physical memory
62.El
63.Pp
64In addition to exporting these services, UVM has two kernel-level processes:
65pagedaemon and swapper.   The pagedaemon process sleeps until physical memory
66becomes scarce.  When that happens, pagedaemon is awoken.   It scans physical
67memory, paging out and freeing memory that has not been recently used.  The
68swapper process swaps in runnable processes that are currently swapped out,
69if there is room.
70.Pp
71There are also several miscellaneous functions.
72.Sh INITIALISATION
73.nr nS 1
74.Pp
75.Ft void
76.Fn uvm_init
77.Ft void
78.Fn uvm_init_limits "struct proc *p"
79.Ft void
80.Fn uvm_setpagesize
81.Ft void
82.Fn uvm_swap_init
83.nr nS 0
84.Pp
85.Fn uvm_init
86sets up the UVM system at system boot time, after the
87copyright has been printed.  It initialises
88global state, the page, map, kernel virtual memory state,
89machine-dependent physical map, kernel memory allocator,
90pager and anonymous memory sub-systems, and then enables
91paging of kernel objects.
92.Pp
93.Fn uvm_init_limits
94initialises process limits for the named process.  This is for use by
95the system startup for process zero, before any other processes are
96created.
97.Pp
98.Fn uvm_setpagesize
99initialises the uvmexp members pagesize (if not already done by
100machine-dependent code), pageshift and pagemask.  It should be called by
101machine-dependent code early in the
102.Xr pmap_init 9
103call.
104.Pp
105.Fn uvm_swap_init
106initialises the swap sub-system.
107.Sh VIRTUAL ADDRESS SPACE MANAGEMENT
108.Pp
109.nr nS 1
110.Ft int
111.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct uvm_object *uobj" "voff_t uoffset" "uvm_flag_t flags"
112.Ft int
113.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable"
114.Ft boolean_t
115.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection"
116.Ft int
117.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "boolean_t set_max"
118.Ft int
119.Fn uvm_deallocate "vm_map_t map" "vaddr_t start" "vsize_t size"
120
121.Ft struct vmspace *
122.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "int pageable"
123.Ft void
124.Fn uvmspace_exec "struct proc *p"
125.Ft struct vmspace *
126.Fn uvmspace_fork "struct vmspace *vm"
127.Ft void
128.Fn uvmspace_free "struct vmspace *vm1"
129.Ft void
130.Fn uvmspace_share "struct proc *p1" "struct proc *p2"
131.Ft void
132.Fn uvmspace_unshare "struct proc *p"
133.nr nS 0
134.Pp
135.Fn uvm_map
136establishes a valid mapping in map
137.Fa map ,
138which must be unlocked.  The new mapping has size
139.Fa size ,
140which must be in
141.Dv PAGE_SIZE
142units.  The
143.Fa uobj
144and
145.Fa uoffset
146arguments can have four meanings.  When
147.Fa uobj
148is
149.Dv NULL
150and
151.Fa uoffset
152is
153.Dv UVM_UNKNOWN_OFFSET ,
154.Fn uvm_map
155does not use the machine-dependant
156.Dv PMAP_PREFER
157function.  If
158.Fa uoffset
159is any other value, it is used as the hint to
160.Dv PMAP_PREFER .
161When
162.Fa uobj
163is not
164.Dv NULL
165and
166.Fa uoffset
167is
168.Dv UVM_UNKNOWN_OFFSET ,
169.Fn uvm_map
170finds the offset based upon the virtual address, passed as
171.Fa startp .
172If
173.Fa uoffset
174is any other value, we are doing a normal mapping at this offset.  The
175start address of the map will be returned in
176.Fa startp .
177.Pp
178.Fa flags
179passed to
180.Fn uvm_map
181are typically created using the
182.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int advice" "int flags"
183macro, which uses the following values.
184The
185.Fa prot
186and
187.Fa maxprot
188can take are:
189.Bd -literal
190#define UVM_PROT_MASK   0x07    /* protection mask */
191#define UVM_PROT_NONE   0x00    /* protection none */
192#define UVM_PROT_ALL    0x07    /* everything */
193#define UVM_PROT_READ   0x01    /* read */
194#define UVM_PROT_WRITE  0x02    /* write */
195#define UVM_PROT_EXEC   0x04    /* exec */
196#define UVM_PROT_R      0x01    /* read */
197#define UVM_PROT_W      0x02    /* write */
198#define UVM_PROT_RW     0x03    /* read-write */
199#define UVM_PROT_X      0x04    /* exec */
200#define UVM_PROT_RX     0x05    /* read-exec */
201#define UVM_PROT_WX     0x06    /* write-exec */
202#define UVM_PROT_RWX    0x07    /* read-write-exec */
203.Ed
204.Pp
205The values that
206.Fa inh
207can take are:
208.Bd -literal
209#define UVM_INH_MASK    0x30    /* inherit mask */
210#define UVM_INH_SHARE   0x00    /* "share" */
211#define UVM_INH_COPY    0x10    /* "copy" */
212#define UVM_INH_NONE    0x20    /* "none" */
213#define UVM_INH_DONATE  0x30    /* "donate" << not used */
214.Ed
215.Pp
216The values that
217.Fa advice
218can take are:
219.Bd -literal
220#define UVM_ADV_NORMAL  0x0     /* 'normal' */
221#define UVM_ADV_RANDOM  0x1     /* 'random' */
222#define UVM_ADV_SEQUENTIAL 0x2  /* 'sequential' */
223#define UVM_ADV_MASK    0x7     /* mask */
224.Ed
225.Pp
226The values that
227.Fa flags
228can take are:
229.Bd -literal
230#define UVM_FLAG_FIXED   0x010000 /* find space */
231#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
232#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
233#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
234#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
235#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
236.Ed
237.Pp
238The
239.Dv UVM_MAPFLAG
240macro arguments can be combined with an or operator.  There are
241several special purpose macros for checking protection combinations, e.g. the
242.Dv UVM_PROT_WX
243macro.  There are also some additional macros to extract bits from
244the flags.  The
245.Dv UVM_PROTECTION ,
246.Dv UVM_INHERIT ,
247.Dv UVM_MAXPROTECTION
248and
249.Dv UVM_ADVICE
250macros return the protection, inheritance, maximum protection and advice,
251respectively.
252.Fn uvm_map
253returns a standard UVM return value.
254.Pp
255.Fn uvm_map_pageable
256changes the pageability of the pages in the range from
257.Fa start
258to
259.Fa end
260in map
261.Fa map
262to
263.Fa new_pageable .
264.Fn uvm_map_pageable
265returns a standard UVM return value.
266.Pp
267.Fn uvm_map_checkprot
268checks the protection of the range from
269.Fa start
270to
271.Fa end
272in map
273.Fa map
274against
275.Fa protection .
276This returns either
277.Dv TRUE
278or
279.Dv FALSE .
280.Pp
281.Fn uvm_map_protect
282changes the protection
283.Fa start
284to
285.Fa end
286in map
287.Fa map
288to
289.Fa new_prot ,
290also setting the maximum protection to the region to
291.Fa new_prot
292if
293.Fa set_max
294is non-zero.  This function returns a standard UVM return value.
295.Pp
296.Fn uvm_deallocate
297deallocates kernel memory in map
298.Fa map
299from address
300.Fa start
301to
302.Fa start + size .
303.Pp
304.Fn uvmspace_alloc
305allocates and returns a new address space, with ranges from
306.Fa min
307to
308.Fa max ,
309setting the pageability of the address space to
310.Fa pageable.
311.Pp
312.Fn uvmspace_exec
313either reuses the address space of process
314.Fa p
315if there are no other references to it, or creates
316a new one with
317.Fn uvmspace_alloc .
318.Pp
319.Fn uvmspace_fork
320creates and returns a new address space based upon the
321.Fa vm1
322address space, typically used when allocating an address space for a
323child process.
324.Pp
325.Fn uvmspace_free
326lowers the reference count on the address space
327.Fa vm ,
328freeing the data structures if there are no other references.
329.Pp
330.Fn uvmspace_share
331causes process
332.Pa p2
333to share the address space of
334.Fa p1 .
335.Pp
336.Fn uvmspace_unshare
337ensures that process
338.Fa p
339has its own, unshared address space, by creating a new one if
340necessary by calling
341.Fn uvmspace_fork .
342.Sh PAGE FAULT HANDLING
343.Pp
344.nr nS 1
345.Ft int
346.Fn uvm_fault "vm_map_t orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" "vm_prot_t access_type"
347.nr nS 0
348.Pp
349.Fn uvm_fault
350is the main entry point for faults.  It takes
351.Fa orig_map
352as the map the fault originated in, a
353.Fa vaddr
354offset into the map the fault occured,
355.Fa fault_type
356describing the type of fault, and
357.Fa access_type
358describing the type of access requested.
359.Fn uvm_fault
360returns a standard UVM return value.
361.Sh MEMORY MAPPING FILES AND DEVICES
362.Pp
363.nr nS 1
364.Ft struct uvm_object *
365.Fn uvn_attach "void *arg" "vm_prot_t accessprot"
366.Ft void
367.Fn uvm_vnp_setsize "struct vnode *vp" "u_quad_t newsize"
368.Ft void
369.Fn uvm_vnp_sync "struct mount *mp"
370.Ft void
371.Fn uvm_vnp_terminate "struct vnode *vp"
372.Ft boolean_t
373.Fn uvm_vnp_uncache "struct vnode *vp"
374.nr nS 0
375.Pp
376.Fn uvn_attach
377attaches a UVM object to vnode
378.Fa arg ,
379creating the object if necessary.  The object is returned.
380.Pp
381.Fn uvm_vnp_setsize
382sets the size of vnode
383.Fa vp
384to
385.Fa newsize .
386Caller must hold a reference to the vnode.  If the vnode shrinks, pages
387no longer used are discarded.  This function will be removed when the
388filesystem and VM buffer caches are merged.
389.Pp
390.Fn uvm_vnp_sync
391flushes dirty vnodes from either the mount point passed in
392.Fa mp ,
393or all dirty vnodes if
394.Fa mp
395is
396.Dv NULL .
397This function will be removed when the filesystem and VM buffer caches
398are merged.
399.Pp
400.Fn uvm_vnp_terminate
401frees all VM resources allocated to vnode
402.Fa vp .
403If the vnode still has references, it will not be destroyed; however
404all future operations using this vnode will fail.  This function will be
405removed when the filesystem and VM buffer caches are merged.
406.Pp
407.Fn uvm_vnp_uncache
408disables vnode
409.Fa vp
410from persisting when all references are freed.  This function will be
411removed when the file-system and UVM caches are unified.  Returns
412true if there is no active vnode.
413.Sh VIRTUAL MEMORY I/O
414.Pp
415.nr nS 1
416.Ft int
417.Fn uvm_io "vm_map_t map" "struct uio *uio"
418.nr nS 0
419.Pp
420.Fn uvm_io
421performs the I/O described in
422.Fa uio
423on the memory described in
424.Fa map .
425.Sh ALLOCATION OF KERNEL MEMORY
426.Pp
427.nr nS 1
428.Ft vaddr_t
429.Fn uvm_km_alloc "vm_map_t map" "vsize_t size"
430.Ft vaddr_t
431.Fn uvm_km_zalloc "vm_map_t map" "vsize_t size"
432.Ft vaddr_t
433.Fn uvm_km_alloc1 "vm_map_t map" "vsize_t size" "boolean_t zeroit"
434.Ft vaddr_t
435.Fn uvm_km_kmemalloc "vm_map_t map" "struct uvm_object *obj" "vsize_t size" "int flags"
436.Ft vaddr_t
437.Fn uvm_km_valloc "vm_map_t map" "vsize_t size"
438.Ft vaddr_t
439.Fn uvm_km_valloc_wait "vm_map_t map" "vsize_t size"
440.Ft struct vm_map *
441.Fn uvm_km_suballoc "vm_map_t map" "vaddr_t *min" "vaddr_t *max " "vsize_t size" "boolean_t pageable" "boolean_t fixed" "vm_map_t submap"
442.Ft void
443.Fn uvm_km_free "vm_map_t map" "vaddr_t addr" "vsize_t size"
444.Ft void
445.Fn uvm_km_free_wakeup "vm_map_t map" "vaddr_t addr" "vsize_t size"
446.nr nS 0
447.Pp
448.Fn uvm_km_alloc
449and
450.Fn uvm_km_zalloc
451allocate
452.Fa size
453bytes of wired kernel memory in map
454.Fa map .
455In addition to allocation,
456.Fn uvm_km_zalloc
457zeros the memory.  Both of these functions are defined as macros in
458terms of
459.Fn uvm_km_alloc1 ,
460and should almost always be used in preference to
461.Fn uvm_km_alloc1 .
462.Pp
463.Fn uvm_km_alloc1
464allocates and returns
465.Fa size
466bytes of wired memory in the kernel map, zeroing the memory if the
467.Fa zeroit
468argument is non-zero.
469.Pp
470.Fn uvm_km_kmemalloc
471allocates and returns
472.Fa size
473bytes of wired kernel memory into
474.Fa obj .
475The flags can be any of:
476.Bd -literal
477#define UVM_KMF_NOWAIT  0x1                     /* matches M_NOWAIT */
478#define UVM_KMF_VALLOC  0x2                     /* allocate VA only */
479#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK        /* try locking only */
480.Ed
481.Pp
482.Dv UVM_KMF_NOWAIT
483causes
484.Fn uvm_km_kmemalloc
485to return immediately if no memory is available.
486.Dv UVM_KMF_VALLOC
487causes no pages to be allocated, only a virtual address.
488.Dv UVM_KMF_TRYLOCK
489causes
490.Fn uvm_km_kmemalloc
491to use
492.Fn simple_lock_try
493when locking maps.
494.Pp
495.Fn uvm_km_valloc
496and
497.Fn uvm_km_valloc_wait
498return a newly allocated zero-filled address in the kernel map of size
499.Fa size .
500.Fn uvm_km_valloc_wait
501will also wait for kernel memory to become available, if there is a
502memory shortage.
503.Sh ALLOCATION OF PHYSICAL MEMORY
504.Pp
505.nr nS 1
506.Ft struct vm_page *
507.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon"
508.Ft void
509.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff"
510.Ft void
511.Fn uvm_pagefree "struct vm_page *pg"
512.Ft int
513.Fn uvm_pglistalloc "psize_t size" "paddr_t low" "paddr_t high" "paddr_t alignment" "paddr_t boundary" "struct pglist *rlist" "int nsegs" "int waitok"
514.Ft void
515.Fn uvm_pglistfree "struct pglist *list"
516.Ft void
517.Fn uvm_page_physload "vaddr_t start" "vaddr_t end" "vaddr_t avail_start" "vaddr_t avail_end"
518.nr nS 0
519.Pp
520.Fn uvm_pagealloc
521allocates a page of memory at virtual address
522.Fa off
523in either the object
524.Fa uobj
525or the anonymous memory
526.Fa anon ,
527which must be locked by the caller.  Only one of
528.Fa off
529and
530.Fa uobj
531can be non
532.Dv NULL .
533Returns
534.Dv NULL
535when no page can be found.
536.Pp
537.Fn uvm_pagerealloc
538reallocates page
539.Fa pg
540to a new object
541.Fa newobj ,
542at a new offset
543.Fa newoff .
544.Pp
545.Fn uvm_pagefree
546free's the physical page
547.Fa pg .
548.Pp
549.Fn uvm_pglistalloc
550allocates a list of pages for size
551.Fa size
552byte under various constraints.
553.Fa low
554and
555.Fa high
556describe the lowest and highest addresses acceptable for the list.  If
557.Fa alignment
558is non-zero, it describes the required alignment of the list, in
559power-of-two notation.  If
560.Fa boundary
561is non-zero, no segment of the list may cross this power-of-two
562boundary, relative to zero.
563The
564.Fa nsegs
565and
566.Fa waitok
567arguments are currently ignored.
568.Pp
569.Fn uvm_pglistfree
570frees the list of pages pointed to by
571.Fa list .
572.Pp
573.Fn uvm_page_physload
574loads physical memory segments into VM space.  It must be called at system
575boot time to setup physical memory management pages.  The arguments describe
576the
577.Fa start
578and
579.Fa end
580of the physical addresses of the segment, and the available start and end
581addresses of pages not already in use.
582.\" XXX expand on "system boot time"!
583.Pp
584.Fn uvm_km_suballoc
585allocates submap from
586.Fa map ,
587creating a new map if
588.Fa submap
589is
590.Dv NULL .
591The addresses of the submap can be specified exactly by setting the
592.Fa fixed
593argument to non-zero, which causes the
594.Fa min
595argument specify the beginning of the address in thes submap.  If
596.Fa fixed
597is zero, any address of size
598.Fa size
599will be allocated from
600.Fa map
601and the start and end addresses returned in
602.Fa min
603and
604.Fa max .
605If
606.Fa pageable
607is non-zero, entries in the map may be paged out.
608.Pp
609.Fn uvm_km_free
610and
611.Fn uvm_km_free_wakeup
612free
613.Fa size
614bytes of memory in the kernal map, starting at address
615.Fa addr .
616.Fn uvm_km_free_wakeup
617calls
618.Fn thread_wakeup
619on the map before unlocking the map.
620.Sh PROCESSES
621.Pp
622.nr nS 1
623.Ft void
624.Fn uvm_pageout
625.Ft void
626.Fn uvm_scheduler
627.Ft void
628.Fn uvm_swapin "struct proc *p"
629.nr nS 0
630.Pp
631.Fn uvm_pageout
632is the main loop for the page daemon.
633.Pp
634.Fn uvm_scheduler
635is the process zero main loop, which is to be called after the
636system has finished starting other processes.  It handles the
637swapping in of runnable, swapped out processes in priority
638order.
639.Pp
640.Fn uvm_swapin
641swaps in the named process.
642.Sh MISCELLANEOUS FUNCTIONS
643.nr nS 1
644.Pp
645.Ft struct uvm_object *
646.Fn uao_create "vsize_t size" "int flags"
647.Ft void
648.Fn uao_detach "struct uvm_object *uobj"
649.Ft void
650.Fn uao_reference "struct uvm_object *uobj"
651
652.Ft boolean_t
653.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw"
654.Ft void
655.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw"
656.Ft boolean_t
657.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw"
658
659.Ft void
660.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len"
661.Ft void
662.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len"
663
664.Ft void
665.Fn uvm_meter
666.Ft int
667.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p"
668
669.Ft void
670.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared"
671.Ft int
672.Fn uvm_grow "struct proc *p" "vaddr_t sp"
673.Ft int
674.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr"
675.nr nS 0
676.Pp
677The
678.Fn uao_create ,
679.Fn uao_detach
680and
681.Fn uao_reference
682functions operate on anonymous memory objects, such as those used to support
683System V shared memory.
684.Fn uao_create
685returns an object of size
686.Fa size
687with flags:
688.Bd -literal
689#define UAO_FLAG_KERNOBJ        0x1     /* create kernel object */
690#define UAO_FLAG_KERNSWAP       0x2     /* enable kernel swap */
691.Pp
692.Ed
693which can only be used once each at system boot time.
694.Fn uao_reference
695creates an additional reference to the named anonymous memory object.
696.Fn uao_detach
697removes a reference from the named anonymous memory object, destroying
698it if removing the last reference.
699.Pp
700.Fn uvm_chgkprot
701changes the protection of kernel memory from
702.Fa addr
703to
704.Fa addr + len
705to the value of
706.Fa rw .
707This is primarily useful for debuggers, for setting breakpoints.
708This function is only available with options
709.Dv KGDB .
710.Pp
711.Fn uvm_kernacc
712and
713.Fn uvm_useracc
714check the access at address
715.Fa addr
716to
717.Fa addr + len
718for
719.Fa rw
720access, in the kernel address space, and the current process'
721address space respectively.
722.Pp
723.Fn uvm_vslock
724and
725.Fn uvm_vsunlock
726control the wiring and unwiring of pages for process
727.Fa p
728from
729.Fa addr
730to
731.Fa addr + len .
732These functions are normally used to wire memory for I/O.
733.Pp
734.Fn uvm_meter
735calculates the load average and wakes up the swapper if necessary.
736.Pp
737.Fn uvm_sysctl
738provides support for the
739.Dv CTL_VM
740domain of the
741.Xr sysctl 3
742hierarchy.
743.Fn uvm_sysctl
744handles the
745.Dv VM_LOADAVG ,
746.Dv VM_METER
747and
748.Dv VM_UVMEXP
749calls, which return the current load averages, calculates current VM
750totals, and returns the uvmexp structure respectively.  The load averages
751are access from userland using the
752.Xr getloadavg 3
753function.  The uvmexp structure has all global state of the UVM system,
754and has the following members:
755.Bd -literal
756/* vm_page constants */
757int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
758int pagemask;   /* page mask */
759int pageshift;  /* page shift */
760
761/* vm_page counters */
762int npages;     /* number of pages we manage */
763int free;       /* number of free pages */
764int active;     /* number of active pages */
765int inactive;   /* number of pages that we free'd but may want back */
766int paging;     /* number of pages in the process of being paged out */
767int wired;      /* number of wired pages */
768int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
769int reserve_kernel; /* number of pages reserved for kernel */
770
771/* pageout params */
772int freemin;    /* min number of free pages */
773int freetarg;   /* target number of free pages */
774int inactarg;   /* target number of inactive pages */
775int wiredmax;   /* max number of wired pages */
776
777/* swap */
778int nswapdev;   /* number of configured swap devices in system */
779int swpages;    /* number of PAGE_SIZE'ed swap pages */
780int swpginuse;  /* number of swap pages in use */
781int nswget;     /* number of times fault calls uvm_swap_get() */
782int nanon;      /* number total of anon's in system */
783int nfreeanon;  /* number of free anon's */
784
785/* stat counters */
786int faults;             /* page fault count */
787int traps;              /* trap count */
788int intrs;              /* interrupt count */
789int swtch;              /* context switch count */
790int softs;              /* software interrupt count */
791int syscalls;           /* system calls */
792int pageins;            /* pagein operation count */
793                        /* pageouts are in pdpageouts below */
794int swapins;            /* swapins */
795int swapouts;           /* swapouts */
796int pgswapin;           /* pages swapped in */
797int pgswapout;          /* pages swapped out */
798int forks;              /* forks */
799int forks_ppwait;       /* forks where parent waits */
800int forks_sharevm;      /* forks where vmspace is shared */
801
802/* fault subcounters */
803int fltnoram;   /* number of times fault was out of ram */
804int fltnoanon;  /* number of times fault was out of anons */
805int fltpgwait;  /* number of times fault had to wait on a page */
806int fltpgrele;  /* number of times fault found a released page */
807int fltrelck;   /* number of times fault relock called */
808int fltrelckok; /* number of times fault relock is a success */
809int fltanget;   /* number of times fault gets anon page */
810int fltanretry; /* number of times fault retrys an anon get */
811int fltamcopy;  /* number of times fault clears "needs copy" */
812int fltnamap;   /* number of times fault maps a neighbor anon page */
813int fltnomap;   /* number of times fault maps a neighbor obj page */
814int fltlget;    /* number of times fault does a locked pgo_get */
815int fltget;     /* number of times fault does an unlocked get */
816int flt_anon;   /* number of times fault anon (case 1a) */
817int flt_acow;   /* number of times fault anon cow (case 1b) */
818int flt_obj;    /* number of times fault is on object page (2a) */
819int flt_prcopy; /* number of times fault promotes with copy (2b) */
820int flt_przero; /* number of times fault promotes with zerofill (2b) */
821
822/* daemon counters */
823int pdwoke;     /* number of times daemon woke up */
824int pdrevs;     /* number of times daemon rev'd clock hand */
825int pdswout;    /* number of times daemon called for swapout */
826int pdfreed;    /* number of pages daemon freed since boot */
827int pdscans;    /* number of pages daemon scaned since boot */
828int pdanscan;   /* number of anonymous pages scanned by daemon */
829int pdobscan;   /* number of object pages scanned by daemon */
830int pdreact;    /* number of pages daemon reactivated since boot */
831int pdbusy;     /* number of times daemon found a busy page */
832int pdpageouts; /* number of times daemon started a pageout */
833int pdpending;  /* number of times daemon got a pending pagout */
834int pddeact;    /* number of pages daemon deactivates */
835.Ed
836.Pp
837.Fn uvm_fork
838forks a virtual address space for process' (old)
839.Fa p1
840and (new)
841.Fa p2 .
842If the
843.Fa shared
844argument is non zero, p1 shares its address space with p2,
845otherwise a new address space is created.  This function
846currently has no return value, and thus cannot fail.  In
847the future, this function will changed to allowed it to
848fail in low memory conditions.
849.Pp
850.Fn uvm_grow
851increases the stack segment of process
852.Fa p
853to include
854.Fa sp .
855.Pp
856.Fn uvm_coredump
857generates a coredump on vnode
858.Fa vp
859for process
860.Fa p
861with credentials
862.Fa cred
863and core header description in
864.Fa chdr .
865.Sh STANDARD UVM RETURN VALUES
866This section documents the standard return values that callers of UVM
867functions can expect.  They are derived from the Mach VM values
868of the same function.  The full list of values can be seen below.
869.Bd -literal
870#define KERN_SUCCESS            0
871#define KERN_INVALID_ADDRESS    1
872#define KERN_PROTECTION_FAILURE 2
873#define KERN_NO_SPACE           3
874#define KERN_INVALID_ARGUMENT   4
875#define KERN_FAILURE            5
876#define KERN_RESOURCE_SHORTAGE  6
877#define KERN_NOT_RECEIVER       7
878#define KERN_NO_ACCESS          8
879#define KERN_PAGES_LOCKED       9
880.Ed
881.Pp
882Note that
883.Dv KERN_NOT_RECEIVER
884and
885.Dv KERN_PAGES_LOCKED
886values are not actually returned by the UVM code.
887.Sh NOTES
888These functions are only available with options
889.Dv UVM .
890.Pp
891.Fn uvm_chgkprot
892is only available if the kernel has been compiled with options
893.Dv KGDB .
894.Pp
895The include file
896.Pa <vm/vm.h>
897will be deprecated when then Mach VM system is obsoleted.  All structure
898and types whose names begin with ``vm_'' will be renamed to ``uvm_''.
899.Pp
900The
901.Xr pmap 9
902manual page is not yet written.
903.Sh HISTORY
904UVM is a new VM system developed at Washington University in St. Louis
905(Missouri).  UVM's roots lie partly in the Mach-based
906.Bx 4.4
907VM system, the FreeBSD VM system, and the SunOS4 VM system.  UVM's basic
908structure is based on the
909.Bx 4.4
910VM system.  UVM's new i386 machine-depenent layer includes several ideas
911from FreeBSD.  UVM's new anonymous memory system is based on the
912anonymous memory system found in SunOS4 VM (as described in papers by
913published Sun Microsystems, Inc.).  UVM also includes a number of feature
914new to BSD including page loanout, map entry passing, simplified
915copy-on-write, and clustered anonymous memory pageout.  UVM will be
916further documented in August 1998 in a dissertation by Charles D. Cranor.
917.Pp
918UVM appeared in
919.Nx 1.4 .
920.Sh AUTHOR
921Charles D. Cranor <chuck@ccrc.wustl.edu> designed and implemented UVM.
922.Pp
923Matthew Green <mrg@eterna.com.au> wrote the swap-space management code
924and handled the logistical issues involed with merging UVM into the
925NetBSD source tree.
926.Pp
927Chuck Silvers <chuq@chuq.com> implemented the aobj pager, thus allowing
928UVM to support System V shared memory and process swapping.
929.Sh SEE ALSO
930.Xr getloadavg 3 ,
931.Xr kvm 3 ,
932.Xr sysctl 3 ,
933.Xr ddb 4 ,
934.Xr options 4
935