xref: /netbsd-src/share/man/man9/uvm.9 (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1.\"	$NetBSD: uvm.9,v 1.26 2001/07/28 15:55:14 chs 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 <uvm/uvm.h>
41.Sh DESCRIPTION
42The UVM virtual memory system manages access to the computer's memory
43resources.  User processes and the kernel access these resources through
44UVM's external interface.  UVM's external interface includes functions that:
45.Pp
46.Bl -hyphen -compact
47.It
48initialise UVM sub-systems
49.It
50manage virtual address spaces
51.It
52resolve page faults
53.It
54memory map files and devices
55.It
56perform uio-based I/O to virtual memory
57.It
58allocate and free kernel virtual memory
59.It
60allocate and free physical memory
61.El
62.Pp
63In addition to exporting these services, UVM has two kernel-level processes:
64pagedaemon and swapper.   The pagedaemon process sleeps until physical memory
65becomes scarce.  When that happens, pagedaemon is awoken.   It scans physical
66memory, paging out and freeing memory that has not been recently used.  The
67swapper process swaps in runnable processes that are currently swapped out,
68if there is room.
69.Pp
70There are also several miscellaneous functions.
71.Sh INITIALISATION
72.nr nS 1
73.Pp
74.Ft void
75.Fn uvm_init "void"
76.Ft void
77.Fn uvm_init_limits "struct proc *p"
78.Ft void
79.Fn uvm_setpagesize "void"
80.Ft void
81.Fn uvm_swap_init "void"
82.nr nS 0
83.Pp
84.Fn uvm_init
85sets up the UVM system at system boot time, after the
86copyright has been printed.  It initialises
87global state, the page, map, kernel virtual memory state,
88machine-dependent physical map, kernel memory allocator,
89pager and anonymous memory sub-systems, and then enables
90paging of kernel objects.
91.Pp
92.Fn uvm_init_limits
93initialises process limits for the named process.  This is for use by
94the system startup for process zero, before any other processes are
95created.
96.Pp
97.Fn uvm_setpagesize
98initialises the uvmexp members pagesize (if not already done by
99machine-dependent code), pageshift and pagemask.  It should be called by
100machine-dependent code early in the
101.Fn pmap_init
102call (see
103.Xr pmap 9 ) .
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 "struct vm_map *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 "struct vm_map *map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable" "int lockflags"
114.Ft boolean_t
115.Fn uvm_map_checkprot "struct vm_map *map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection"
116.Ft int
117.Fn uvm_map_protect "struct vm_map *map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "boolean_t set_max"
118.Ft int
119.Fn uvm_deallocate "struct vm_map *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" "vaddr_t start" "vaddr_t end"
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-dependent
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 .
318The range of valid addresses in the address space is reset to
319.Fa start
320through
321.Fa end .
322.Pp
323.Fn uvmspace_fork
324creates and returns a new address space based upon the
325.Fa vm1
326address space, typically used when allocating an address space for a
327child process.
328.Pp
329.Fn uvmspace_free
330lowers the reference count on the address space
331.Fa vm ,
332freeing the data structures if there are no other references.
333.Pp
334.Fn uvmspace_share
335causes process
336.Pa p2
337to share the address space of
338.Fa p1 .
339.Pp
340.Fn uvmspace_unshare
341ensures that process
342.Fa p
343has its own, unshared address space, by creating a new one if
344necessary by calling
345.Fn uvmspace_fork .
346.Sh PAGE FAULT HANDLING
347.Pp
348.nr nS 1
349.Ft int
350.Fn uvm_fault "struct vm_map *orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" "vm_prot_t access_type"
351.nr nS 0
352.Pp
353.Fn uvm_fault
354is the main entry point for faults.  It takes
355.Fa orig_map
356as the map the fault originated in, a
357.Fa vaddr
358offset into the map the fault occurred,
359.Fa fault_type
360describing the type of fault, and
361.Fa access_type
362describing the type of access requested.
363.Fn uvm_fault
364returns a standard UVM return value.
365.Sh MEMORY MAPPING FILES AND DEVICES
366.Pp
367.nr nS 1
368.Ft struct uvm_object *
369.Fn uvn_attach "void *arg" "vm_prot_t accessprot"
370.Ft void
371.Fn uvm_vnp_setsize "struct vnode *vp" "voff_t newsize"
372.Ft void *
373.Fn ubc_alloc "struct uvm_object *uobj" "voff_t offset" "vsize_t *lenp" "int flags"
374.Ft void
375.Fn ubc_release "void *va" "int flags"
376.nr nS 0
377.Pp
378.Fn uvn_attach
379attaches a UVM object to vnode
380.Fa arg ,
381creating the object if necessary.  The object is returned.
382.Pp
383.Fn uvm_vnp_setsize
384sets the size of vnode
385.Fa vp
386to
387.Fa newsize .
388Caller must hold a reference to the vnode.  If the vnode shrinks, pages
389no longer used are discarded.
390.Pp
391.Fn ubc_alloc
392creates a kernel mappings of
393.Fa uobj
394starting at offset
395.Fa offset .
396the desired length of the mapping is pointed to by
397.Fa lenp ,
398but the actual mapping may be smaller than this.
399.Fa lenp
400is updated to contain the actual length mapped.
401The flags must be one of
402.Bd -literal
403#define UBC_READ        0x01    /* mapping will be accessed for read */
404#define UBC_WRITE       0x02    /* mapping will be accessed for write */
405.Ed
406.Pp
407Currently,
408.Fa uobj
409must actually be a vnode object.
410Once the mapping is created, it must be accessed only by methods that can
411handle faults, such as
412.Fn uiomove
413or
414.Fn kcopy .
415Page faults on the mapping will result in the vnode's
416.Fn VOP_GETPAGES
417method being called to resolve the fault.
418.Pp
419.Fn ubc_release
420frees the mapping at
421.Fa va
422for reuse.  The mapping may be cached to speed future accesses to the same
423region of the object.  The flags are currently unused.
424.Sh VIRTUAL MEMORY I/O
425.Pp
426.nr nS 1
427.Ft int
428.Fn uvm_io "struct vm_map *map" "struct uio *uio"
429.nr nS 0
430.Pp
431.Fn uvm_io
432performs the I/O described in
433.Fa uio
434on the memory described in
435.Fa map .
436.Sh ALLOCATION OF KERNEL MEMORY
437.Pp
438.nr nS 1
439.Ft vaddr_t
440.Fn uvm_km_alloc "struct vm_map *map" "vsize_t size"
441.Ft vaddr_t
442.Fn uvm_km_zalloc "struct vm_map *map" "vsize_t size"
443.Ft vaddr_t
444.Fn uvm_km_alloc1 "struct vm_map *map" "vsize_t size" "boolean_t zeroit"
445.Ft vaddr_t
446.Fn uvm_km_kmemalloc "struct vm_map *map" "struct uvm_object *obj" "vsize_t size" "int flags"
447.Ft vaddr_t
448.Fn uvm_km_valloc "struct vm_map *map" "vsize_t size"
449.Ft vaddr_t
450.Fn uvm_km_valloc_wait "struct vm_map *map" "vsize_t size"
451.Ft struct vm_map *
452.Fn uvm_km_suballoc "struct vm_map *map" "vaddr_t *min" "vaddr_t *max " "vsize_t size" "boolean_t pageable" "boolean_t fixed" "struct vm_map *submap"
453.Ft void
454.Fn uvm_km_free "struct vm_map *map" "vaddr_t addr" "vsize_t size"
455.Ft void
456.Fn uvm_km_free_wakeup "struct vm_map *map" "vaddr_t addr" "vsize_t size"
457.nr nS 0
458.Pp
459.Fn uvm_km_alloc
460and
461.Fn uvm_km_zalloc
462allocate
463.Fa size
464bytes of wired kernel memory in map
465.Fa map .
466In addition to allocation,
467.Fn uvm_km_zalloc
468zeros the memory.  Both of these functions are defined as macros in
469terms of
470.Fn uvm_km_alloc1 ,
471and should almost always be used in preference to
472.Fn uvm_km_alloc1 .
473.Pp
474.Fn uvm_km_alloc1
475allocates and returns
476.Fa size
477bytes of wired memory in the kernel map, zeroing the memory if the
478.Fa zeroit
479argument is non-zero.
480.Pp
481.Fn uvm_km_kmemalloc
482allocates and returns
483.Fa size
484bytes of wired kernel memory into
485.Fa obj .
486The flags can be any of:
487.Bd -literal
488#define UVM_KMF_NOWAIT  0x1                     /* matches M_NOWAIT */
489#define UVM_KMF_VALLOC  0x2                     /* allocate VA only */
490#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK        /* try locking only */
491.Ed
492.Pp
493.Dv UVM_KMF_NOWAIT
494causes
495.Fn uvm_km_kmemalloc
496to return immediately if no memory is available.
497.Dv UVM_KMF_VALLOC
498causes no pages to be allocated, only a virtual address.
499.Dv UVM_KMF_TRYLOCK
500causes
501.Fn uvm_km_kmemalloc
502to use
503.Fn simple_lock_try
504when locking maps.
505.Pp
506.Fn uvm_km_valloc
507and
508.Fn uvm_km_valloc_wait
509return a newly allocated zero-filled address in the kernel map of size
510.Fa size .
511.Fn uvm_km_valloc_wait
512will also wait for kernel memory to become available, if there is a
513memory shortage.
514.Pp
515.Fn uvm_km_free
516and
517.Fn uvm_km_free_wakeup
518free
519.Fa size
520bytes of memory in the kernel map, starting at address
521.Fa addr .
522.Fn uvm_km_free_wakeup
523calls
524.Fn wakeup
525on the map before unlocking the map.
526.Pp
527.Fn uvm_km_suballoc
528allocates submap from
529.Fa map ,
530creating a new map if
531.Fa submap
532is
533.Dv NULL .
534The addresses of the submap can be specified exactly by setting the
535.Fa fixed
536argument to non-zero, which causes the
537.Fa min
538argument specify the beginning of the address in the submap.  If
539.Fa fixed
540is zero, any address of size
541.Fa size
542will be allocated from
543.Fa map
544and the start and end addresses returned in
545.Fa min
546and
547.Fa max .
548If
549.Fa pageable
550is non-zero, entries in the map may be paged out.
551.Sh ALLOCATION OF PHYSICAL MEMORY
552.Pp
553.nr nS 1
554.Ft struct vm_page *
555.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon" "int flags"
556.Ft void
557.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff"
558.Ft void
559.Fn uvm_pagefree "struct vm_page *pg"
560.Ft int
561.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"
562.Ft void
563.Fn uvm_pglistfree "struct pglist *list"
564.Ft void
565.Fn uvm_page_physload "vaddr_t start" "vaddr_t end" "vaddr_t avail_start" "vaddr_t avail_end"
566.nr nS 0
567.Pp
568.Fn uvm_pagealloc
569allocates a page of memory at virtual address
570.Fa off
571in either the object
572.Fa uobj
573or the anonymous memory
574.Fa anon ,
575which must be locked by the caller.
576Returns
577.Dv NULL
578when no page can be found.
579The flags can be any of
580.Bd -literal
581#define UVM_PGA_USERESERVE      0x0001  /* ok to use reserve pages */
582#define UVM_PGA_ZERO            0x0002  /* returned page must be zero'd */
583.Ed
584.Pp
585.Dv UVM_PGA_USERESERVE
586means to allocate a page even if that will result in the number of free pages
587being lower than
588.Dv uvmexp.reserve_pagedaemon
589(if the current thread is the pagedaemon) or
590.Dv uvmexp.reserve_kernel
591(if the current thread is not the pagedaemon).
592.Dv UVM_PGA_ZERO
593causes the returned page to be filled with zeroes, either by allocating it
594from a pool of pre-zeroed pages or by zeroing it in-line as necessary.
595.Pp
596.Fn uvm_pagerealloc
597reallocates page
598.Fa pg
599to a new object
600.Fa newobj ,
601at a new offset
602.Fa newoff .
603.Pp
604.Fn uvm_pagefree
605frees the physical page
606.Fa pg .
607.Pp
608.Fn uvm_pglistalloc
609allocates a list of pages for size
610.Fa size
611byte under various constraints.
612.Fa low
613and
614.Fa high
615describe the lowest and highest addresses acceptable for the list.  If
616.Fa alignment
617is non-zero, it describes the required alignment of the list, in
618power-of-two notation.  If
619.Fa boundary
620is non-zero, no segment of the list may cross this power-of-two
621boundary, relative to zero.
622The
623.Fa nsegs
624and
625.Fa waitok
626arguments are currently ignored.
627.Pp
628.Fn uvm_pglistfree
629frees the list of pages pointed to by
630.Fa list .
631.Pp
632.Fn uvm_page_physload
633loads physical memory segments into VM space.  It must be called at system
634boot time to setup physical memory management pages.  The arguments describe
635the
636.Fa start
637and
638.Fa end
639of the physical addresses of the segment, and the available start and end
640addresses of pages not already in use.
641.\" XXX expand on "system boot time"!
642.Sh PROCESSES
643.Pp
644.nr nS 1
645.Ft void
646.Fn uvm_pageout "void"
647.Ft void
648.Fn uvm_scheduler "void"
649.Ft void
650.Fn uvm_swapin "struct proc *p"
651.nr nS 0
652.Pp
653.Fn uvm_pageout
654is the main loop for the page daemon.
655.Pp
656.Fn uvm_scheduler
657is the process zero main loop, which is to be called after the
658system has finished starting other processes.  It handles the
659swapping in of runnable, swapped out processes in priority
660order.
661.Pp
662.Fn uvm_swapin
663swaps in the named process.
664.Sh MISCELLANEOUS FUNCTIONS
665.nr nS 1
666.Pp
667.Ft struct uvm_object *
668.Fn uao_create "vsize_t size" "int flags"
669.Ft void
670.Fn uao_detach "struct uvm_object *uobj"
671.Ft void
672.Fn uao_reference "struct uvm_object *uobj"
673
674.Ft boolean_t
675.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw"
676.Ft void
677.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw"
678.Ft boolean_t
679.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw"
680
681.Ft int
682.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" "vm_prot_t prot"
683.Ft void
684.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len"
685
686.Ft void
687.Fn uvm_meter "void"
688.Ft int
689.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p"
690
691.Ft void
692.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared"
693.Ft int
694.Fn uvm_grow "struct proc *p" "vaddr_t sp"
695.Ft int
696.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr"
697
698.Ft void
699.Fn uvn_findpages "struct uvm_object *uobj" "voff_t offset" "int *npagesp" "struct vm_page **pps" "int flags"
700
701.nr nS 0
702.Pp
703The
704.Fn uao_create ,
705.Fn uao_detach
706and
707.Fn uao_reference
708functions operate on anonymous memory objects, such as those used to support
709System V shared memory.
710.Fn uao_create
711returns an object of size
712.Fa size
713with flags:
714.Bd -literal
715#define UAO_FLAG_KERNOBJ        0x1     /* create kernel object */
716#define UAO_FLAG_KERNSWAP       0x2     /* enable kernel swap */
717.Ed
718.Pp
719which can only be used once each at system boot time.
720.Fn uao_reference
721creates an additional reference to the named anonymous memory object.
722.Fn uao_detach
723removes a reference from the named anonymous memory object, destroying
724it if removing the last reference.
725.Pp
726.Fn uvm_chgkprot
727changes the protection of kernel memory from
728.Fa addr
729to
730.Fa addr + len
731to the value of
732.Fa rw .
733This is primarily useful for debuggers, for setting breakpoints.
734This function is only available with options
735.Dv KGDB .
736.Pp
737.Fn uvm_kernacc
738and
739.Fn uvm_useracc
740check the access at address
741.Fa addr
742to
743.Fa addr + len
744for
745.Fa rw
746access, in the kernel address space, and the current process'
747address space respectively.
748.Pp
749.Fn uvm_vslock
750and
751.Fn uvm_vsunlock
752control the wiring and unwiring of pages for process
753.Fa p
754from
755.Fa addr
756to
757.Fa addr + len .
758These functions are normally used to wire memory for I/O.
759.Pp
760.Fn uvm_meter
761calculates the load average and wakes up the swapper if necessary.
762.Pp
763.Fn uvm_sysctl
764provides support for the
765.Dv CTL_VM
766domain of the
767.Xr sysctl 3
768hierarchy.
769.Fn uvm_sysctl
770handles the
771.Dv VM_LOADAVG ,
772.Dv VM_METER
773and
774.Dv VM_UVMEXP
775calls, which return the current load averages, calculates current VM
776totals, and returns the uvmexp structure respectively.  The load averages
777are access from userland using the
778.Xr getloadavg 3
779function.  The uvmexp structure has all global state of the UVM system,
780and has the following members:
781.Bd -literal
782/* vm_page constants */
783int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
784int pagemask;   /* page mask */
785int pageshift;  /* page shift */
786
787/* vm_page counters */
788int npages;     /* number of pages we manage */
789int free;       /* number of free pages */
790int active;     /* number of active pages */
791int inactive;   /* number of pages that we free'd but may want back */
792int paging;     /* number of pages in the process of being paged out */
793int wired;      /* number of wired pages */
794int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
795int reserve_kernel; /* number of pages reserved for kernel */
796
797/* pageout params */
798int freemin;    /* min number of free pages */
799int freetarg;   /* target number of free pages */
800int inactarg;   /* target number of inactive pages */
801int wiredmax;   /* max number of wired pages */
802
803/* swap */
804int nswapdev;   /* number of configured swap devices in system */
805int swpages;    /* number of PAGE_SIZE'ed swap pages */
806int swpginuse;  /* number of swap pages in use */
807int nswget;     /* number of times fault calls uvm_swap_get() */
808int nanon;      /* number total of anon's in system */
809int nfreeanon;  /* number of free anon's */
810
811/* stat counters */
812int faults;             /* page fault count */
813int traps;              /* trap count */
814int intrs;              /* interrupt count */
815int swtch;              /* context switch count */
816int softs;              /* software interrupt count */
817int syscalls;           /* system calls */
818int pageins;            /* pagein operation count */
819                        /* pageouts are in pdpageouts below */
820int swapins;            /* swapins */
821int swapouts;           /* swapouts */
822int pgswapin;           /* pages swapped in */
823int pgswapout;          /* pages swapped out */
824int forks;              /* forks */
825int forks_ppwait;       /* forks where parent waits */
826int forks_sharevm;      /* forks where vmspace is shared */
827
828/* fault subcounters */
829int fltnoram;   /* number of times fault was out of ram */
830int fltnoanon;  /* number of times fault was out of anons */
831int fltpgwait;  /* number of times fault had to wait on a page */
832int fltpgrele;  /* number of times fault found a released page */
833int fltrelck;   /* number of times fault relock called */
834int fltrelckok; /* number of times fault relock is a success */
835int fltanget;   /* number of times fault gets anon page */
836int fltanretry; /* number of times fault retrys an anon get */
837int fltamcopy;  /* number of times fault clears "needs copy" */
838int fltnamap;   /* number of times fault maps a neighbor anon page */
839int fltnomap;   /* number of times fault maps a neighbor obj page */
840int fltlget;    /* number of times fault does a locked pgo_get */
841int fltget;     /* number of times fault does an unlocked get */
842int flt_anon;   /* number of times fault anon (case 1a) */
843int flt_acow;   /* number of times fault anon cow (case 1b) */
844int flt_obj;    /* number of times fault is on object page (2a) */
845int flt_prcopy; /* number of times fault promotes with copy (2b) */
846int flt_przero; /* number of times fault promotes with zerofill (2b) */
847
848/* daemon counters */
849int pdwoke;     /* number of times daemon woke up */
850int pdrevs;     /* number of times daemon rev'd clock hand */
851int pdswout;    /* number of times daemon called for swapout */
852int pdfreed;    /* number of pages daemon freed since boot */
853int pdscans;    /* number of pages daemon scanned since boot */
854int pdanscan;   /* number of anonymous pages scanned by daemon */
855int pdobscan;   /* number of object pages scanned by daemon */
856int pdreact;    /* number of pages daemon reactivated since boot */
857int pdbusy;     /* number of times daemon found a busy page */
858int pdpageouts; /* number of times daemon started a pageout */
859int pdpending;  /* number of times daemon got a pending pageout */
860int pddeact;    /* number of pages daemon deactivates */
861.Ed
862.Pp
863.Fn uvm_fork
864forks a virtual address space for process' (old)
865.Fa p1
866and (new)
867.Fa p2 .
868If the
869.Fa shared
870argument is non zero, p1 shares its address space with p2,
871otherwise a new address space is created.  This function
872currently has no return value, and thus cannot fail.  In
873the future, this function will changed to allowed it to
874fail in low memory conditions.
875.Pp
876.Fn uvm_grow
877increases the stack segment of process
878.Fa p
879to include
880.Fa sp .
881.Pp
882.Fn uvm_coredump
883generates a coredump on vnode
884.Fa vp
885for process
886.Fa p
887with credentials
888.Fa cred
889and core header description in
890.Fa chdr .
891.Pp
892.Fn uvn_findpages
893looks up or creates pages in
894.Fa uobj
895at offset
896.Fa offset ,
897marks them busy and returns them in the
898.Fa pps
899array.
900Currently
901.Fa uobj
902must be a vnode object.
903The number of pages requested is pointed to by
904.Fa npagesp ,
905and this value is updated with the actual number of pages returned.
906The flags can be
907.Bd -literal
908#define UFP_ALL         0x00    /* return all pages requested */
909#define UFP_NOWAIT      0x01    /* don't sleep */
910#define UFP_NOALLOC     0x02    /* don't allocate new pages */
911#define UFP_NOCACHE     0x04    /* don't return pages which already exist */
912#define UFP_NORDONLY    0x08    /* don't return PG_READONLY pages */
913.Ed
914.Pp
915.Dv UFP_ALL
916is a pseudo-flag meaning all requested pages should be returned.
917.Dv UFP_NOWAIT
918means that we must not sleep.
919.Dv UFP_NOALLOC
920causes any pages which do not already exist to be skipped.
921.Dv UFP_NOCACHE
922causes any pages which do already exist to be skipped.
923.Dv UFP_NORDONLY
924causes any pages which are marked PG_READONLY to be skipped.
925.Sh NOTES
926.Fn uvm_chgkprot
927is only available if the kernel has been compiled with options
928.Dv KGDB .
929.Pp
930All structure and types whose names begin with
931.Dq vm_
932will be renamed to
933.Dq uvm_ .
934.Sh HISTORY
935UVM is a new VM system developed at Washington University in St. Louis
936(Missouri).  UVM's roots lie partly in the Mach-based
937.Bx 4.4
938VM system, the
939.Fx
940VM system, and the SunOS4 VM system.  UVM's basic structure is based on the
941.Bx 4.4
942VM system.  UVM's new anonymous memory system is based on the
943anonymous memory system found in the SunOS4 VM (as described in papers
944published by Sun Microsystems, Inc.).  UVM also includes a number of feature
945new to
946.Bx
947including page loanout, map entry passing, simplified
948copy-on-write, and clustered anonymous memory pageout.  UVM is also
949further documented in a August 1998 dissertation by Charles D. Cranor.
950.Pp
951UVM appeared in
952.Nx 1.4 .
953.Sh AUTHORS
954Charles D. Cranor <chuck@ccrc.wustl.edu> designed and implemented UVM.
955.Pp
956Matthew Green <mrg@eterna.com.au> wrote the swap-space management code
957and handled the logistical issues involved with merging UVM into the
958.Nx
959source tree.
960.Pp
961Chuck Silvers <chuq@chuq.com> implemented the aobj pager, thus allowing
962UVM to support System V shared memory and process swapping.  He also
963designed and implemented the UBC part of UVM, which uses UVM pages to
964cache vnode data rather than the traditional buffer cache buffers.
965.Sh SEE ALSO
966.Xr getloadavg 3 ,
967.Xr kvm 3 ,
968.Xr sysctl 3 ,
969.Xr ddb 4 ,
970.Xr options 4 ,
971.Xr pmap 9 .
972