xref: /netbsd-src/share/man/man9/uvm.9 (revision 220b5c059a84c51ea44107ea8951a57ffaecdc8c)
1.\"	$NetBSD: uvm.9,v 1.27 2001/08/17 17:11:51 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.
576Only one of
577.Fa uobj
578and
579.Fa anon
580can be non
581.Dv NULL .
582Returns
583.Dv NULL
584when no page can be found.
585The flags can be any of
586.Bd -literal
587#define UVM_PGA_USERESERVE      0x0001  /* ok to use reserve pages */
588#define UVM_PGA_ZERO            0x0002  /* returned page must be zero'd */
589.Ed
590.Pp
591.Dv UVM_PGA_USERESERVE
592means to allocate a page even if that will result in the number of free pages
593being lower than
594.Dv uvmexp.reserve_pagedaemon
595(if the current thread is the pagedaemon) or
596.Dv uvmexp.reserve_kernel
597(if the current thread is not the pagedaemon).
598.Dv UVM_PGA_ZERO
599causes the returned page to be filled with zeroes, either by allocating it
600from a pool of pre-zeroed pages or by zeroing it in-line as necessary.
601.Pp
602.Fn uvm_pagerealloc
603reallocates page
604.Fa pg
605to a new object
606.Fa newobj ,
607at a new offset
608.Fa newoff .
609.Pp
610.Fn uvm_pagefree
611frees the physical page
612.Fa pg .
613.Pp
614.Fn uvm_pglistalloc
615allocates a list of pages for size
616.Fa size
617byte under various constraints.
618.Fa low
619and
620.Fa high
621describe the lowest and highest addresses acceptable for the list.  If
622.Fa alignment
623is non-zero, it describes the required alignment of the list, in
624power-of-two notation.  If
625.Fa boundary
626is non-zero, no segment of the list may cross this power-of-two
627boundary, relative to zero.
628The
629.Fa nsegs
630and
631.Fa waitok
632arguments are currently ignored.
633.Pp
634.Fn uvm_pglistfree
635frees the list of pages pointed to by
636.Fa list .
637.Pp
638.Fn uvm_page_physload
639loads physical memory segments into VM space.  It must be called at system
640boot time to setup physical memory management pages.  The arguments describe
641the
642.Fa start
643and
644.Fa end
645of the physical addresses of the segment, and the available start and end
646addresses of pages not already in use.
647.\" XXX expand on "system boot time"!
648.Sh PROCESSES
649.Pp
650.nr nS 1
651.Ft void
652.Fn uvm_pageout "void"
653.Ft void
654.Fn uvm_scheduler "void"
655.Ft void
656.Fn uvm_swapin "struct proc *p"
657.nr nS 0
658.Pp
659.Fn uvm_pageout
660is the main loop for the page daemon.
661.Pp
662.Fn uvm_scheduler
663is the process zero main loop, which is to be called after the
664system has finished starting other processes.  It handles the
665swapping in of runnable, swapped out processes in priority
666order.
667.Pp
668.Fn uvm_swapin
669swaps in the named process.
670.Sh MISCELLANEOUS FUNCTIONS
671.nr nS 1
672.Pp
673.Ft struct uvm_object *
674.Fn uao_create "vsize_t size" "int flags"
675.Ft void
676.Fn uao_detach "struct uvm_object *uobj"
677.Ft void
678.Fn uao_reference "struct uvm_object *uobj"
679
680.Ft boolean_t
681.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw"
682.Ft void
683.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw"
684.Ft boolean_t
685.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw"
686
687.Ft int
688.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" "vm_prot_t prot"
689.Ft void
690.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len"
691
692.Ft void
693.Fn uvm_meter "void"
694.Ft int
695.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p"
696
697.Ft void
698.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared"
699.Ft int
700.Fn uvm_grow "struct proc *p" "vaddr_t sp"
701.Ft int
702.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr"
703
704.Ft void
705.Fn uvn_findpages "struct uvm_object *uobj" "voff_t offset" "int *npagesp" "struct vm_page **pps" "int flags"
706
707.nr nS 0
708.Pp
709The
710.Fn uao_create ,
711.Fn uao_detach
712and
713.Fn uao_reference
714functions operate on anonymous memory objects, such as those used to support
715System V shared memory.
716.Fn uao_create
717returns an object of size
718.Fa size
719with flags:
720.Bd -literal
721#define UAO_FLAG_KERNOBJ        0x1     /* create kernel object */
722#define UAO_FLAG_KERNSWAP       0x2     /* enable kernel swap */
723.Ed
724.Pp
725which can only be used once each at system boot time.
726.Fn uao_reference
727creates an additional reference to the named anonymous memory object.
728.Fn uao_detach
729removes a reference from the named anonymous memory object, destroying
730it if removing the last reference.
731.Pp
732.Fn uvm_chgkprot
733changes the protection of kernel memory from
734.Fa addr
735to
736.Fa addr + len
737to the value of
738.Fa rw .
739This is primarily useful for debuggers, for setting breakpoints.
740This function is only available with options
741.Dv KGDB .
742.Pp
743.Fn uvm_kernacc
744and
745.Fn uvm_useracc
746check the access at address
747.Fa addr
748to
749.Fa addr + len
750for
751.Fa rw
752access, in the kernel address space, and the current process'
753address space respectively.
754.Pp
755.Fn uvm_vslock
756and
757.Fn uvm_vsunlock
758control the wiring and unwiring of pages for process
759.Fa p
760from
761.Fa addr
762to
763.Fa addr + len .
764These functions are normally used to wire memory for I/O.
765.Pp
766.Fn uvm_meter
767calculates the load average and wakes up the swapper if necessary.
768.Pp
769.Fn uvm_sysctl
770provides support for the
771.Dv CTL_VM
772domain of the
773.Xr sysctl 3
774hierarchy.
775.Fn uvm_sysctl
776handles the
777.Dv VM_LOADAVG ,
778.Dv VM_METER
779and
780.Dv VM_UVMEXP
781calls, which return the current load averages, calculates current VM
782totals, and returns the uvmexp structure respectively.  The load averages
783are access from userland using the
784.Xr getloadavg 3
785function.  The uvmexp structure has all global state of the UVM system,
786and has the following members:
787.Bd -literal
788/* vm_page constants */
789int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
790int pagemask;   /* page mask */
791int pageshift;  /* page shift */
792
793/* vm_page counters */
794int npages;     /* number of pages we manage */
795int free;       /* number of free pages */
796int active;     /* number of active pages */
797int inactive;   /* number of pages that we free'd but may want back */
798int paging;     /* number of pages in the process of being paged out */
799int wired;      /* number of wired pages */
800int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
801int reserve_kernel; /* number of pages reserved for kernel */
802
803/* pageout params */
804int freemin;    /* min number of free pages */
805int freetarg;   /* target number of free pages */
806int inactarg;   /* target number of inactive pages */
807int wiredmax;   /* max number of wired pages */
808
809/* swap */
810int nswapdev;   /* number of configured swap devices in system */
811int swpages;    /* number of PAGE_SIZE'ed swap pages */
812int swpginuse;  /* number of swap pages in use */
813int nswget;     /* number of times fault calls uvm_swap_get() */
814int nanon;      /* number total of anon's in system */
815int nfreeanon;  /* number of free anon's */
816
817/* stat counters */
818int faults;             /* page fault count */
819int traps;              /* trap count */
820int intrs;              /* interrupt count */
821int swtch;              /* context switch count */
822int softs;              /* software interrupt count */
823int syscalls;           /* system calls */
824int pageins;            /* pagein operation count */
825                        /* pageouts are in pdpageouts below */
826int swapins;            /* swapins */
827int swapouts;           /* swapouts */
828int pgswapin;           /* pages swapped in */
829int pgswapout;          /* pages swapped out */
830int forks;              /* forks */
831int forks_ppwait;       /* forks where parent waits */
832int forks_sharevm;      /* forks where vmspace is shared */
833
834/* fault subcounters */
835int fltnoram;   /* number of times fault was out of ram */
836int fltnoanon;  /* number of times fault was out of anons */
837int fltpgwait;  /* number of times fault had to wait on a page */
838int fltpgrele;  /* number of times fault found a released page */
839int fltrelck;   /* number of times fault relock called */
840int fltrelckok; /* number of times fault relock is a success */
841int fltanget;   /* number of times fault gets anon page */
842int fltanretry; /* number of times fault retrys an anon get */
843int fltamcopy;  /* number of times fault clears "needs copy" */
844int fltnamap;   /* number of times fault maps a neighbor anon page */
845int fltnomap;   /* number of times fault maps a neighbor obj page */
846int fltlget;    /* number of times fault does a locked pgo_get */
847int fltget;     /* number of times fault does an unlocked get */
848int flt_anon;   /* number of times fault anon (case 1a) */
849int flt_acow;   /* number of times fault anon cow (case 1b) */
850int flt_obj;    /* number of times fault is on object page (2a) */
851int flt_prcopy; /* number of times fault promotes with copy (2b) */
852int flt_przero; /* number of times fault promotes with zerofill (2b) */
853
854/* daemon counters */
855int pdwoke;     /* number of times daemon woke up */
856int pdrevs;     /* number of times daemon rev'd clock hand */
857int pdswout;    /* number of times daemon called for swapout */
858int pdfreed;    /* number of pages daemon freed since boot */
859int pdscans;    /* number of pages daemon scanned since boot */
860int pdanscan;   /* number of anonymous pages scanned by daemon */
861int pdobscan;   /* number of object pages scanned by daemon */
862int pdreact;    /* number of pages daemon reactivated since boot */
863int pdbusy;     /* number of times daemon found a busy page */
864int pdpageouts; /* number of times daemon started a pageout */
865int pdpending;  /* number of times daemon got a pending pageout */
866int pddeact;    /* number of pages daemon deactivates */
867.Ed
868.Pp
869.Fn uvm_fork
870forks a virtual address space for process' (old)
871.Fa p1
872and (new)
873.Fa p2 .
874If the
875.Fa shared
876argument is non zero, p1 shares its address space with p2,
877otherwise a new address space is created.  This function
878currently has no return value, and thus cannot fail.  In
879the future, this function will changed to allowed it to
880fail in low memory conditions.
881.Pp
882.Fn uvm_grow
883increases the stack segment of process
884.Fa p
885to include
886.Fa sp .
887.Pp
888.Fn uvm_coredump
889generates a coredump on vnode
890.Fa vp
891for process
892.Fa p
893with credentials
894.Fa cred
895and core header description in
896.Fa chdr .
897.Pp
898.Fn uvn_findpages
899looks up or creates pages in
900.Fa uobj
901at offset
902.Fa offset ,
903marks them busy and returns them in the
904.Fa pps
905array.
906Currently
907.Fa uobj
908must be a vnode object.
909The number of pages requested is pointed to by
910.Fa npagesp ,
911and this value is updated with the actual number of pages returned.
912The flags can be
913.Bd -literal
914#define UFP_ALL         0x00    /* return all pages requested */
915#define UFP_NOWAIT      0x01    /* don't sleep */
916#define UFP_NOALLOC     0x02    /* don't allocate new pages */
917#define UFP_NOCACHE     0x04    /* don't return pages which already exist */
918#define UFP_NORDONLY    0x08    /* don't return PG_READONLY pages */
919.Ed
920.Pp
921.Dv UFP_ALL
922is a pseudo-flag meaning all requested pages should be returned.
923.Dv UFP_NOWAIT
924means that we must not sleep.
925.Dv UFP_NOALLOC
926causes any pages which do not already exist to be skipped.
927.Dv UFP_NOCACHE
928causes any pages which do already exist to be skipped.
929.Dv UFP_NORDONLY
930causes any pages which are marked PG_READONLY to be skipped.
931.Sh NOTES
932.Fn uvm_chgkprot
933is only available if the kernel has been compiled with options
934.Dv KGDB .
935.Pp
936All structure and types whose names begin with
937.Dq vm_
938will be renamed to
939.Dq uvm_ .
940.Sh HISTORY
941UVM is a new VM system developed at Washington University in St. Louis
942(Missouri).  UVM's roots lie partly in the Mach-based
943.Bx 4.4
944VM system, the
945.Fx
946VM system, and the SunOS4 VM system.  UVM's basic structure is based on the
947.Bx 4.4
948VM system.  UVM's new anonymous memory system is based on the
949anonymous memory system found in the SunOS4 VM (as described in papers
950published by Sun Microsystems, Inc.).  UVM also includes a number of feature
951new to
952.Bx
953including page loanout, map entry passing, simplified
954copy-on-write, and clustered anonymous memory pageout.  UVM is also
955further documented in a August 1998 dissertation by Charles D. Cranor.
956.Pp
957UVM appeared in
958.Nx 1.4 .
959.Sh AUTHORS
960Charles D. Cranor <chuck@ccrc.wustl.edu> designed and implemented UVM.
961.Pp
962Matthew Green <mrg@eterna.com.au> wrote the swap-space management code
963and handled the logistical issues involved with merging UVM into the
964.Nx
965source tree.
966.Pp
967Chuck Silvers <chuq@chuq.com> implemented the aobj pager, thus allowing
968UVM to support System V shared memory and process swapping.  He also
969designed and implemented the UBC part of UVM, which uses UVM pages to
970cache vnode data rather than the traditional buffer cache buffers.
971.Sh SEE ALSO
972.Xr getloadavg 3 ,
973.Xr kvm 3 ,
974.Xr sysctl 3 ,
975.Xr ddb 4 ,
976.Xr options 4 ,
977.Xr pmap 9 .
978