2003-11-03 11:07:36 +03:00
|
|
|
.\" $NetBSD: uvm.9,v 1.49 2003/11/03 08:07:36 wiz Exp $
|
1998-05-04 11:10:45 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1998 Matthew R. Green
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. The name of the author may not be used to endorse or promote products
|
|
|
|
.\" derived from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2003-11-03 04:28:01 +03:00
|
|
|
.Dd November 3, 2003
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dt UVM 9
|
1999-03-16 03:40:46 +03:00
|
|
|
.Os
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh NAME
|
2000-03-29 10:00:42 +04:00
|
|
|
.Nm uvm
|
|
|
|
.Nd virtual memory system external interface
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sys/param.h
|
|
|
|
.In uvm/uvm.h
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The UVM virtual memory system manages access to the computer's memory
|
2002-09-27 11:52:48 +04:00
|
|
|
resources.
|
|
|
|
User processes and the kernel access these resources through
|
|
|
|
UVM's external interface.
|
|
|
|
UVM's external interface includes functions that:
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Bl -hyphen -compact
|
|
|
|
.It
|
|
|
|
initialise UVM sub-systems
|
|
|
|
.It
|
|
|
|
manage virtual address spaces
|
|
|
|
.It
|
|
|
|
resolve page faults
|
|
|
|
.It
|
|
|
|
memory map files and devices
|
|
|
|
.It
|
|
|
|
perform uio-based I/O to virtual memory
|
|
|
|
.It
|
|
|
|
allocate and free kernel virtual memory
|
|
|
|
.It
|
|
|
|
allocate and free physical memory
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
In addition to exporting these services, UVM has two kernel-level processes:
|
2002-09-27 11:52:48 +04:00
|
|
|
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.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
There are also several miscellaneous functions.
|
|
|
|
.Sh INITIALISATION
|
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_init "void" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_init_limits "struct proc *p" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_setpagesize "void" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_swap_init "void" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_init
|
|
|
|
sets up the UVM system at system boot time, after the
|
2002-09-27 11:52:48 +04:00
|
|
|
copyright has been printed.
|
|
|
|
It initialises global state, the page, map, kernel virtual memory state,
|
1998-05-04 11:10:45 +04:00
|
|
|
machine-dependent physical map, kernel memory allocator,
|
|
|
|
pager and anonymous memory sub-systems, and then enables
|
|
|
|
paging of kernel objects.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_init_limits
|
2002-09-27 11:52:48 +04:00
|
|
|
initialises process limits for the named process.
|
|
|
|
This is for use by the system startup for process zero, before any
|
|
|
|
other processes are created.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_setpagesize
|
|
|
|
initialises the uvmexp members pagesize (if not already done by
|
2002-09-27 11:52:48 +04:00
|
|
|
machine-dependent code), pageshift and pagemask.
|
|
|
|
It should be called by machine-dependent code early in the
|
2001-05-12 21:10:05 +04:00
|
|
|
.Fn pmap_init
|
|
|
|
call (see
|
|
|
|
.Xr pmap 9 ) .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_swap_init
|
|
|
|
initialises the swap sub-system.
|
|
|
|
.Sh VIRTUAL ADDRESS SPACE MANAGEMENT
|
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
2003-08-31 16:35:35 +04:00
|
|
|
.Fn uvm_map "struct vm_map *map" "vaddr_t *startp" "vsize_t size" "struct uvm_object *uobj" "voff_t uoffset" "vsize_t align" "uvm_flag_t flags" ;
|
2003-06-30 23:12:31 +04:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_map_pageable "struct vm_map *map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable" "int lockflags" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft boolean_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_map_checkprot "struct vm_map *map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_map_protect "struct vm_map *map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "boolean_t set_max" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_deallocate "struct vm_map *map" "vaddr_t start" "vsize_t size" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
1998-05-08 20:00:49 +04:00
|
|
|
.Ft struct vmspace *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "int pageable" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_exec "struct proc *p" "vaddr_t start" "vaddr_t end" ;
|
|
|
|
.Pp
|
1998-05-08 20:00:49 +04:00
|
|
|
.Ft struct vmspace *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_fork "struct vmspace *vm" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_free "struct vmspace *vm1" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_share "struct proc *p1" "struct proc *p2" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvmspace_unshare "struct proc *p" ;
|
|
|
|
.Pp
|
2002-11-17 11:32:43 +03:00
|
|
|
.Ft boolean_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_uarea_alloc "vaddr_t *uaddrp" ;
|
|
|
|
.Pp
|
2002-09-22 11:22:27 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_uarea_free "vaddr_t uaddr" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_map
|
|
|
|
establishes a valid mapping in map
|
|
|
|
.Fa map ,
|
2002-09-27 11:52:48 +04:00
|
|
|
which must be unlocked.
|
|
|
|
The new mapping has size
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa size ,
|
2003-04-16 13:31:35 +04:00
|
|
|
which must a multiple of
|
2003-03-09 21:28:59 +03:00
|
|
|
.Dv PAGE_SIZE .
|
2002-09-27 11:52:48 +04:00
|
|
|
The
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa uobj
|
|
|
|
and
|
|
|
|
.Fa uoffset
|
2002-09-27 11:52:48 +04:00
|
|
|
arguments can have four meanings.
|
|
|
|
When
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa uobj
|
|
|
|
is
|
|
|
|
.Dv NULL
|
|
|
|
and
|
|
|
|
.Fa uoffset
|
|
|
|
is
|
|
|
|
.Dv UVM_UNKNOWN_OFFSET ,
|
|
|
|
.Fn uvm_map
|
2001-06-21 15:59:00 +04:00
|
|
|
does not use the machine-dependent
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv PMAP_PREFER
|
2002-09-27 11:52:48 +04:00
|
|
|
function.
|
|
|
|
If
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa uoffset
|
|
|
|
is any other value, it is used as the hint to
|
|
|
|
.Dv PMAP_PREFER .
|
|
|
|
When
|
|
|
|
.Fa uobj
|
|
|
|
is not
|
|
|
|
.Dv NULL
|
|
|
|
and
|
|
|
|
.Fa uoffset
|
|
|
|
is
|
|
|
|
.Dv UVM_UNKNOWN_OFFSET ,
|
|
|
|
.Fn uvm_map
|
2001-06-21 15:59:00 +04:00
|
|
|
finds the offset based upon the virtual address, passed as
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa startp .
|
|
|
|
If
|
|
|
|
.Fa uoffset
|
2002-09-27 11:52:48 +04:00
|
|
|
is any other value, we are doing a normal mapping at this offset.
|
|
|
|
The start address of the map will be returned in
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa startp .
|
|
|
|
.Pp
|
2003-08-31 16:35:35 +04:00
|
|
|
.Fa align
|
2003-08-31 20:38:30 +04:00
|
|
|
specifies alignment of mapping unless
|
|
|
|
.Dv UVM_FLAG_FIXED
|
|
|
|
is specified in
|
2003-08-31 16:35:35 +04:00
|
|
|
.Fa flags .
|
|
|
|
.Fa align
|
2003-08-31 20:38:30 +04:00
|
|
|
must be a power of 2.
|
2003-08-31 16:35:35 +04:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa flags
|
|
|
|
passed to
|
|
|
|
.Fn uvm_map
|
|
|
|
are typically created using the
|
|
|
|
.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int advice" "int flags"
|
|
|
|
macro, which uses the following values.
|
|
|
|
The
|
|
|
|
.Fa prot
|
|
|
|
and
|
|
|
|
.Fa maxprot
|
|
|
|
can take are:
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_PROT_MASK 0x07 /* protection mask */
|
|
|
|
#define UVM_PROT_NONE 0x00 /* protection none */
|
|
|
|
#define UVM_PROT_ALL 0x07 /* everything */
|
|
|
|
#define UVM_PROT_READ 0x01 /* read */
|
|
|
|
#define UVM_PROT_WRITE 0x02 /* write */
|
|
|
|
#define UVM_PROT_EXEC 0x04 /* exec */
|
|
|
|
#define UVM_PROT_R 0x01 /* read */
|
|
|
|
#define UVM_PROT_W 0x02 /* write */
|
|
|
|
#define UVM_PROT_RW 0x03 /* read-write */
|
|
|
|
#define UVM_PROT_X 0x04 /* exec */
|
|
|
|
#define UVM_PROT_RX 0x05 /* read-exec */
|
|
|
|
#define UVM_PROT_WX 0x06 /* write-exec */
|
|
|
|
#define UVM_PROT_RWX 0x07 /* read-write-exec */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The values that
|
|
|
|
.Fa inh
|
|
|
|
can take are:
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_INH_MASK 0x30 /* inherit mask */
|
|
|
|
#define UVM_INH_SHARE 0x00 /* "share" */
|
|
|
|
#define UVM_INH_COPY 0x10 /* "copy" */
|
|
|
|
#define UVM_INH_NONE 0x20 /* "none" */
|
2002-02-13 11:17:26 +03:00
|
|
|
#define UVM_INH_DONATE 0x30 /* "donate" \*[Lt]\*[Lt] not used */
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The values that
|
|
|
|
.Fa advice
|
|
|
|
can take are:
|
|
|
|
.Bd -literal
|
2001-07-28 19:55:14 +04:00
|
|
|
#define UVM_ADV_NORMAL 0x0 /* 'normal' */
|
|
|
|
#define UVM_ADV_RANDOM 0x1 /* 'random' */
|
1998-05-04 11:10:45 +04:00
|
|
|
#define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
|
2001-07-28 19:55:14 +04:00
|
|
|
#define UVM_ADV_MASK 0x7 /* mask */
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The values that
|
|
|
|
.Fa flags
|
|
|
|
can take are:
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_FLAG_FIXED 0x010000 /* find space */
|
|
|
|
#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
|
|
|
|
#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
|
|
|
|
#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
|
|
|
|
#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
|
|
|
|
#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Dv UVM_MAPFLAG
|
2002-09-27 11:52:48 +04:00
|
|
|
macro arguments can be combined with an or operator.
|
|
|
|
There are several special purpose macros for checking protection
|
2003-04-07 11:04:49 +04:00
|
|
|
combinations, e.g., the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv UVM_PROT_WX
|
2002-09-27 11:52:48 +04:00
|
|
|
macro.
|
|
|
|
There are also some additional macros to extract bits from the flags.
|
|
|
|
The
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv UVM_PROTECTION ,
|
|
|
|
.Dv UVM_INHERIT ,
|
|
|
|
.Dv UVM_MAXPROTECTION
|
|
|
|
and
|
|
|
|
.Dv UVM_ADVICE
|
|
|
|
macros return the protection, inheritance, maximum protection and advice,
|
|
|
|
respectively.
|
|
|
|
.Fn uvm_map
|
|
|
|
returns a standard UVM return value.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_map_pageable
|
|
|
|
changes the pageability of the pages in the range from
|
|
|
|
.Fa start
|
|
|
|
to
|
|
|
|
.Fa end
|
|
|
|
in map
|
|
|
|
.Fa map
|
|
|
|
to
|
|
|
|
.Fa new_pageable .
|
|
|
|
.Fn uvm_map_pageable
|
|
|
|
returns a standard UVM return value.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_map_checkprot
|
|
|
|
checks the protection of the range from
|
|
|
|
.Fa start
|
|
|
|
to
|
|
|
|
.Fa end
|
|
|
|
in map
|
|
|
|
.Fa map
|
|
|
|
against
|
|
|
|
.Fa protection .
|
|
|
|
This returns either
|
|
|
|
.Dv TRUE
|
|
|
|
or
|
|
|
|
.Dv FALSE .
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_map_protect
|
2001-06-21 15:59:00 +04:00
|
|
|
changes the protection
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa start
|
|
|
|
to
|
|
|
|
.Fa end
|
|
|
|
in map
|
|
|
|
.Fa map
|
|
|
|
to
|
|
|
|
.Fa new_prot ,
|
|
|
|
also setting the maximum protection to the region to
|
|
|
|
.Fa new_prot
|
|
|
|
if
|
|
|
|
.Fa set_max
|
2002-09-27 11:52:48 +04:00
|
|
|
is non-zero.
|
|
|
|
This function returns a standard UVM return value.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_deallocate
|
|
|
|
deallocates kernel memory in map
|
|
|
|
.Fa map
|
|
|
|
from address
|
|
|
|
.Fa start
|
|
|
|
to
|
|
|
|
.Fa start + size .
|
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_alloc
|
|
|
|
allocates and returns a new address space, with ranges from
|
|
|
|
.Fa min
|
|
|
|
to
|
|
|
|
.Fa max ,
|
|
|
|
setting the pageability of the address space to
|
2001-06-21 15:59:00 +04:00
|
|
|
.Fa pageable .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_exec
|
|
|
|
either reuses the address space of process
|
|
|
|
.Fa p
|
|
|
|
if there are no other references to it, or creates
|
|
|
|
a new one with
|
|
|
|
.Fn uvmspace_alloc .
|
2001-07-28 19:55:14 +04:00
|
|
|
The range of valid addresses in the address space is reset to
|
|
|
|
.Fa start
|
|
|
|
through
|
|
|
|
.Fa end .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_fork
|
|
|
|
creates and returns a new address space based upon the
|
|
|
|
.Fa vm1
|
|
|
|
address space, typically used when allocating an address space for a
|
|
|
|
child process.
|
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_free
|
|
|
|
lowers the reference count on the address space
|
|
|
|
.Fa vm ,
|
|
|
|
freeing the data structures if there are no other references.
|
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_share
|
|
|
|
causes process
|
|
|
|
.Pa p2
|
|
|
|
to share the address space of
|
|
|
|
.Fa p1 .
|
|
|
|
.Pp
|
|
|
|
.Fn uvmspace_unshare
|
|
|
|
ensures that process
|
|
|
|
.Fa p
|
|
|
|
has its own, unshared address space, by creating a new one if
|
|
|
|
necessary by calling
|
|
|
|
.Fn uvmspace_fork .
|
2002-09-22 11:22:27 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_uarea_alloc
|
2002-11-17 11:32:43 +03:00
|
|
|
allocates virtual space for a u-area (i.e., a kernel stack) and stores
|
|
|
|
its virtual address in
|
|
|
|
.Fa *uaddrp .
|
|
|
|
The return value is
|
|
|
|
.Dv TRUE
|
|
|
|
if the u-area is already backed by wired physical memory, otherwise
|
|
|
|
.Dv FALSE .
|
2002-09-22 11:22:27 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_uarea_free
|
|
|
|
frees a u-area allocated with
|
|
|
|
.Fn uvm_uarea_alloc ,
|
|
|
|
freeing both the virtual space and any physical pages which may have been
|
|
|
|
allocated to back that virtual space later.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh PAGE FAULT HANDLING
|
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_fault "struct vm_map *orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" "vm_prot_t access_type" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_fault
|
2002-09-27 11:52:48 +04:00
|
|
|
is the main entry point for faults.
|
|
|
|
It takes
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa orig_map
|
|
|
|
as the map the fault originated in, a
|
|
|
|
.Fa vaddr
|
2001-04-25 06:19:48 +04:00
|
|
|
offset into the map the fault occurred,
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa fault_type
|
|
|
|
describing the type of fault, and
|
|
|
|
.Fa access_type
|
|
|
|
describing the type of access requested.
|
|
|
|
.Fn uvm_fault
|
|
|
|
returns a standard UVM return value.
|
|
|
|
.Sh MEMORY MAPPING FILES AND DEVICES
|
1998-05-08 20:00:49 +04:00
|
|
|
.Ft struct uvm_object *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvn_attach "void *arg" "vm_prot_t accessprot" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_vnp_setsize "struct vnode *vp" "voff_t newsize" ;
|
|
|
|
.Pp
|
2001-07-28 19:31:29 +04:00
|
|
|
.Ft void *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn ubc_alloc "struct uvm_object *uobj" "voff_t offset" "vsize_t *lenp" "int flags" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn ubc_release "void *va" "int flags" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvn_attach
|
|
|
|
attaches a UVM object to vnode
|
|
|
|
.Fa arg ,
|
2002-09-27 11:52:48 +04:00
|
|
|
creating the object if necessary.
|
|
|
|
The object is returned.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_vnp_setsize
|
|
|
|
sets the size of vnode
|
|
|
|
.Fa vp
|
|
|
|
to
|
|
|
|
.Fa newsize .
|
2002-09-27 11:52:48 +04:00
|
|
|
Caller must hold a reference to the vnode.
|
|
|
|
If the vnode shrinks, pages no longer used are discarded.
|
2001-07-28 19:31:29 +04:00
|
|
|
.Pp
|
|
|
|
.Fn ubc_alloc
|
|
|
|
creates a kernel mappings of
|
|
|
|
.Fa uobj
|
|
|
|
starting at offset
|
|
|
|
.Fa offset .
|
|
|
|
the desired length of the mapping is pointed to by
|
|
|
|
.Fa lenp ,
|
|
|
|
but the actual mapping may be smaller than this.
|
|
|
|
.Fa lenp
|
|
|
|
is updated to contain the actual length mapped.
|
|
|
|
The flags must be one of
|
|
|
|
.Bd -literal
|
2001-07-28 19:55:14 +04:00
|
|
|
#define UBC_READ 0x01 /* mapping will be accessed for read */
|
|
|
|
#define UBC_WRITE 0x02 /* mapping will be accessed for write */
|
2001-07-28 19:31:29 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Currently,
|
|
|
|
.Fa uobj
|
|
|
|
must actually be a vnode object.
|
|
|
|
Once the mapping is created, it must be accessed only by methods that can
|
|
|
|
handle faults, such as
|
|
|
|
.Fn uiomove
|
|
|
|
or
|
|
|
|
.Fn kcopy .
|
|
|
|
Page faults on the mapping will result in the vnode's
|
|
|
|
.Fn VOP_GETPAGES
|
|
|
|
method being called to resolve the fault.
|
|
|
|
.Pp
|
|
|
|
.Fn ubc_release
|
|
|
|
frees the mapping at
|
|
|
|
.Fa va
|
2002-09-27 11:52:48 +04:00
|
|
|
for reuse.
|
|
|
|
The mapping may be cached to speed future accesses to the same region
|
|
|
|
of the object.
|
|
|
|
The flags are currently unused.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh VIRTUAL MEMORY I/O
|
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_io "struct vm_map *map" "struct uio *uio" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_io
|
|
|
|
performs the I/O described in
|
|
|
|
.Fa uio
|
|
|
|
on the memory described in
|
|
|
|
.Fa map .
|
|
|
|
.Sh ALLOCATION OF KERNEL MEMORY
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_alloc "struct vm_map *map" "vsize_t size" ;
|
|
|
|
.Pp
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_zalloc "struct vm_map *map" "vsize_t size" ;
|
|
|
|
.Pp
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_alloc1 "struct vm_map *map" "vsize_t size" "boolean_t zeroit" ;
|
|
|
|
.Pp
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_kmemalloc "struct vm_map *map" "struct uvm_object *obj" "vsize_t size" "int flags" ;
|
|
|
|
.Pp
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_valloc "struct vm_map *map" "vsize_t size" ;
|
|
|
|
.Pp
|
1998-08-14 09:05:07 +04:00
|
|
|
.Ft vaddr_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_valloc_wait "struct vm_map *map" "vsize_t size" ;
|
|
|
|
.Pp
|
1998-05-08 20:00:49 +04:00
|
|
|
.Ft struct vm_map *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.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" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_free "struct vm_map *map" "vaddr_t addr" "vsize_t size" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_km_free_wakeup "struct vm_map *map" "vaddr_t addr" "vsize_t size" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_alloc
|
|
|
|
and
|
|
|
|
.Fn uvm_km_zalloc
|
|
|
|
allocate
|
|
|
|
.Fa size
|
|
|
|
bytes of wired kernel memory in map
|
|
|
|
.Fa map .
|
|
|
|
In addition to allocation,
|
|
|
|
.Fn uvm_km_zalloc
|
2002-09-27 11:52:48 +04:00
|
|
|
zeros the memory.
|
|
|
|
Both of these functions are defined as macros in terms of
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fn uvm_km_alloc1 ,
|
|
|
|
and should almost always be used in preference to
|
|
|
|
.Fn uvm_km_alloc1 .
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_alloc1
|
|
|
|
allocates and returns
|
|
|
|
.Fa size
|
|
|
|
bytes of wired memory in the kernel map, zeroing the memory if the
|
|
|
|
.Fa zeroit
|
|
|
|
argument is non-zero.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_kmemalloc
|
|
|
|
allocates and returns
|
|
|
|
.Fa size
|
|
|
|
bytes of wired kernel memory into
|
|
|
|
.Fa obj .
|
|
|
|
The flags can be any of:
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */
|
|
|
|
#define UVM_KMF_VALLOC 0x2 /* allocate VA only */
|
2002-09-22 11:22:27 +04:00
|
|
|
#define UVM_KMF_CANFAIL 0x4 /* caller handles failure */
|
1998-05-04 11:10:45 +04:00
|
|
|
#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Dv UVM_KMF_NOWAIT
|
|
|
|
causes
|
|
|
|
.Fn uvm_km_kmemalloc
|
|
|
|
to return immediately if no memory is available.
|
|
|
|
.Dv UVM_KMF_VALLOC
|
2002-09-22 11:22:27 +04:00
|
|
|
causes no physical pages to be allocated, only virtual space.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv UVM_KMF_TRYLOCK
|
|
|
|
causes
|
|
|
|
.Fn uvm_km_kmemalloc
|
|
|
|
to use
|
|
|
|
.Fn simple_lock_try
|
|
|
|
when locking maps.
|
2002-09-22 11:22:27 +04:00
|
|
|
.Dv UVM_KMF_CANFAIL
|
|
|
|
indicates that
|
|
|
|
.Fn uvm_km_kmemalloc
|
|
|
|
can return 0 even if
|
|
|
|
.Dv UVM_KMF_NOWAIT
|
2002-09-27 11:52:48 +04:00
|
|
|
is not specified.
|
|
|
|
(If neither
|
2002-09-22 11:22:27 +04:00
|
|
|
.Dv UVM_KMF_NOWAIT
|
|
|
|
nor
|
|
|
|
.Dv UVM_KMF_CANFAIL
|
2002-09-27 11:52:48 +04:00
|
|
|
are specified,
|
2002-09-22 11:22:27 +04:00
|
|
|
.Fn uvm_km_kmemalloc
|
|
|
|
will never fail, but rather sleep indefinitely until the allocation succeeds.)
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_valloc
|
|
|
|
and
|
|
|
|
.Fn uvm_km_valloc_wait
|
|
|
|
return a newly allocated zero-filled address in the kernel map of size
|
|
|
|
.Fa size .
|
|
|
|
.Fn uvm_km_valloc_wait
|
|
|
|
will also wait for kernel memory to become available, if there is a
|
|
|
|
memory shortage.
|
2001-07-28 19:31:29 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_free
|
|
|
|
and
|
|
|
|
.Fn uvm_km_free_wakeup
|
|
|
|
free
|
|
|
|
.Fa size
|
|
|
|
bytes of memory in the kernel map, starting at address
|
|
|
|
.Fa addr .
|
|
|
|
.Fn uvm_km_free_wakeup
|
|
|
|
calls
|
|
|
|
.Fn wakeup
|
|
|
|
on the map before unlocking the map.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_km_suballoc
|
|
|
|
allocates submap from
|
|
|
|
.Fa map ,
|
|
|
|
creating a new map if
|
|
|
|
.Fa submap
|
|
|
|
is
|
|
|
|
.Dv NULL .
|
|
|
|
The addresses of the submap can be specified exactly by setting the
|
|
|
|
.Fa fixed
|
|
|
|
argument to non-zero, which causes the
|
|
|
|
.Fa min
|
2003-05-03 23:01:05 +04:00
|
|
|
argument to specify the beginning of the address in the submap.
|
2002-09-27 11:52:48 +04:00
|
|
|
If
|
2001-07-28 19:31:29 +04:00
|
|
|
.Fa fixed
|
|
|
|
is zero, any address of size
|
|
|
|
.Fa size
|
|
|
|
will be allocated from
|
|
|
|
.Fa map
|
|
|
|
and the start and end addresses returned in
|
|
|
|
.Fa min
|
|
|
|
and
|
|
|
|
.Fa max .
|
|
|
|
If
|
|
|
|
.Fa pageable
|
|
|
|
is non-zero, entries in the map may be paged out.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh ALLOCATION OF PHYSICAL MEMORY
|
|
|
|
.Ft struct vm_page *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon" "int flags" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_pagefree "struct vm_page *pg" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.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" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_pglistfree "struct pglist *list" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_page_physload "vaddr_t start" "vaddr_t end" "vaddr_t avail_start" "vaddr_t avail_end" "int free_list" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_pagealloc
|
|
|
|
allocates a page of memory at virtual address
|
|
|
|
.Fa off
|
|
|
|
in either the object
|
|
|
|
.Fa uobj
|
|
|
|
or the anonymous memory
|
|
|
|
.Fa anon ,
|
2001-07-28 19:55:14 +04:00
|
|
|
which must be locked by the caller.
|
2001-08-17 21:11:51 +04:00
|
|
|
Only one of
|
|
|
|
.Fa uobj
|
|
|
|
and
|
|
|
|
.Fa anon
|
|
|
|
can be non
|
|
|
|
.Dv NULL .
|
1998-05-04 11:10:45 +04:00
|
|
|
Returns
|
|
|
|
.Dv NULL
|
|
|
|
when no page can be found.
|
2001-07-28 19:55:14 +04:00
|
|
|
The flags can be any of
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */
|
|
|
|
#define UVM_PGA_ZERO 0x0002 /* returned page must be zero'd */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Dv UVM_PGA_USERESERVE
|
|
|
|
means to allocate a page even if that will result in the number of free pages
|
|
|
|
being lower than
|
|
|
|
.Dv uvmexp.reserve_pagedaemon
|
|
|
|
(if the current thread is the pagedaemon) or
|
|
|
|
.Dv uvmexp.reserve_kernel
|
|
|
|
(if the current thread is not the pagedaemon).
|
|
|
|
.Dv UVM_PGA_ZERO
|
|
|
|
causes the returned page to be filled with zeroes, either by allocating it
|
|
|
|
from a pool of pre-zeroed pages or by zeroing it in-line as necessary.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_pagerealloc
|
|
|
|
reallocates page
|
|
|
|
.Fa pg
|
|
|
|
to a new object
|
|
|
|
.Fa newobj ,
|
|
|
|
at a new offset
|
|
|
|
.Fa newoff .
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_pagefree
|
2001-06-21 15:59:00 +04:00
|
|
|
frees the physical page
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa pg .
|
2003-11-03 04:28:01 +03:00
|
|
|
If the content of the page is known to be zero-filled,
|
2003-11-03 11:07:36 +03:00
|
|
|
caller should set
|
|
|
|
.Dv PG_ZERO
|
|
|
|
in pg-\*[Gt]flags so that the page allocator will use
|
|
|
|
the page to serve future
|
|
|
|
.Dv UVM_PGA_ZERO
|
|
|
|
requests efficiently.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_pglistalloc
|
|
|
|
allocates a list of pages for size
|
|
|
|
.Fa size
|
|
|
|
byte under various constraints.
|
|
|
|
.Fa low
|
|
|
|
and
|
|
|
|
.Fa high
|
2002-09-27 11:52:48 +04:00
|
|
|
describe the lowest and highest addresses acceptable for the list.
|
|
|
|
If
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa alignment
|
|
|
|
is non-zero, it describes the required alignment of the list, in
|
2002-09-27 11:52:48 +04:00
|
|
|
power-of-two notation.
|
|
|
|
If
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa boundary
|
|
|
|
is non-zero, no segment of the list may cross this power-of-two
|
|
|
|
boundary, relative to zero.
|
|
|
|
.Fa nsegs
|
2002-09-27 11:52:48 +04:00
|
|
|
is the maximum number of physically contigous segments.
|
|
|
|
If
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa waitok
|
2002-06-02 18:59:11 +04:00
|
|
|
is non-zero, the function may sleep until enough memory is available.
|
|
|
|
(It also may give up in some situations, so a non-zero
|
|
|
|
.Fa waitok
|
|
|
|
does not imply that
|
|
|
|
.Fn uvm_pglistalloc
|
2002-09-27 11:52:48 +04:00
|
|
|
cannot return an error.)
|
|
|
|
The allocated memory is returned in the
|
2002-06-02 18:59:11 +04:00
|
|
|
.Fa rlist
|
|
|
|
list; the caller has to provide storage only, the list is initialized by
|
|
|
|
.Fn uvm_pglistalloc .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_pglistfree
|
|
|
|
frees the list of pages pointed to by
|
|
|
|
.Fa list .
|
2003-11-03 04:28:01 +03:00
|
|
|
If the content of the page is known to be zero-filled,
|
2003-11-03 11:07:36 +03:00
|
|
|
caller should set
|
|
|
|
.Dv PG_ZERO
|
|
|
|
in pg-\*[Gt]flags so that the page allocator will use
|
|
|
|
the page to serve future
|
|
|
|
.Dv UVM_PGA_ZERO
|
|
|
|
requests efficiently.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_page_physload
|
2002-02-22 00:52:27 +03:00
|
|
|
loads physical memory segments into VM space on the specified
|
|
|
|
.Fa free_list .
|
2003-05-14 15:58:34 +04:00
|
|
|
It must be called at system boot time to set up physical memory
|
2002-09-27 11:52:48 +04:00
|
|
|
management pages.
|
|
|
|
The arguments describe the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa start
|
|
|
|
and
|
|
|
|
.Fa end
|
|
|
|
of the physical addresses of the segment, and the available start and end
|
|
|
|
addresses of pages not already in use.
|
|
|
|
.\" XXX expand on "system boot time"!
|
|
|
|
.Sh PROCESSES
|
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_pageout "void" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_scheduler "void" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_swapin "struct proc *p" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_pageout
|
|
|
|
is the main loop for the page daemon.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_scheduler
|
|
|
|
is the process zero main loop, which is to be called after the
|
2002-09-27 11:52:48 +04:00
|
|
|
system has finished starting other processes.
|
|
|
|
It handles the swapping in of runnable, swapped out processes in priority
|
1998-05-04 11:10:45 +04:00
|
|
|
order.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_swapin
|
|
|
|
swaps in the named process.
|
2001-12-24 15:28:46 +03:00
|
|
|
.Sh PAGE LOAN
|
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_loan "struct vm_map *map" "vaddr_t start" "vsize_t len" "void *v" "int flags" ;
|
|
|
|
.Pp
|
2001-12-24 15:28:46 +03:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_unloan "void *v" "int npages" "int flags" ;
|
2001-12-24 15:28:46 +03:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_loan
|
|
|
|
loans pages in a map out to anons or to the kernel.
|
|
|
|
.Fa map
|
|
|
|
should be unlocked ,
|
|
|
|
.Fa start
|
|
|
|
and
|
|
|
|
.Fa len
|
|
|
|
should be multiples of
|
|
|
|
.Dv PAGE_SIZE .
|
|
|
|
Argument
|
|
|
|
.Fa flags
|
|
|
|
should be one of
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_LOAN_TOANON 0x01 /* loan to anons */
|
|
|
|
#define UVM_LOAN_TOPAGE 0x02 /* loan to kernel */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Fa v
|
|
|
|
should be pointer to array of pointers to
|
|
|
|
.Li struct anon
|
|
|
|
or
|
|
|
|
.Li struct vm_page ,
|
2002-09-27 11:52:48 +04:00
|
|
|
as appropriate.
|
|
|
|
The caller has to allocate memory for the array and
|
2001-12-24 15:28:46 +03:00
|
|
|
ensure it's big enough to hold
|
|
|
|
.Fa len / PAGE_SIZE
|
|
|
|
pointers.
|
|
|
|
Returns 0 for success, or appropriate error number otherwise.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_unloan
|
2002-09-27 11:52:48 +04:00
|
|
|
kills loans on pages or anons.
|
|
|
|
The
|
2001-12-24 15:28:46 +03:00
|
|
|
.Fa v
|
|
|
|
must point to the array of pointers initialized by previous call to
|
|
|
|
.Fn uvm_loan .
|
|
|
|
.Fa npages
|
|
|
|
should match number of pages allocated for loan, this also matches
|
|
|
|
number of items in the array.
|
|
|
|
Argument
|
|
|
|
.Fa flags
|
|
|
|
should be one of
|
|
|
|
.Bd -literal
|
|
|
|
#define UVM_LOAN_TOANON 0x01 /* loan to anons */
|
|
|
|
#define UVM_LOAN_TOPAGE 0x02 /* loan to kernel */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
and should match what was used for previous call to
|
|
|
|
.Fn uvm_loan .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh MISCELLANEOUS FUNCTIONS
|
|
|
|
.Ft struct uvm_object *
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uao_create "vsize_t size" "int flags" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uao_detach "struct uvm_object *uobj" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uao_reference "struct uvm_object *uobj" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft boolean_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft boolean_t
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
2001-03-23 20:07:38 +03:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len" "vm_prot_t prot" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_meter "void" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_grow "struct proc *p" "vaddr_t sp" ;
|
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
.Ft int
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
2001-07-28 19:31:29 +04:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvn_findpages "struct uvm_object *uobj" "voff_t offset" "int *npagesp" "struct vm_page **pps" "int flags" ;
|
2001-12-26 04:02:01 +03:00
|
|
|
.Pp
|
2002-03-29 11:56:31 +03:00
|
|
|
.Ft void
|
2003-06-30 23:12:31 +04:00
|
|
|
.br
|
|
|
|
.Fn uvm_swap_stats "int cmd" "struct swapent *sep" "int sec" "register_t *retval" ;
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn uao_create ,
|
2003-05-03 23:01:05 +04:00
|
|
|
.Fn uao_detach ,
|
1998-05-04 11:10:45 +04:00
|
|
|
and
|
|
|
|
.Fn uao_reference
|
|
|
|
functions operate on anonymous memory objects, such as those used to support
|
|
|
|
System V shared memory.
|
|
|
|
.Fn uao_create
|
|
|
|
returns an object of size
|
|
|
|
.Fa size
|
|
|
|
with flags:
|
|
|
|
.Bd -literal
|
|
|
|
#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */
|
|
|
|
#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */
|
|
|
|
.Ed
|
2001-07-28 19:31:29 +04:00
|
|
|
.Pp
|
1998-05-04 11:10:45 +04:00
|
|
|
which can only be used once each at system boot time.
|
|
|
|
.Fn uao_reference
|
|
|
|
creates an additional reference to the named anonymous memory object.
|
|
|
|
.Fn uao_detach
|
|
|
|
removes a reference from the named anonymous memory object, destroying
|
|
|
|
it if removing the last reference.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_chgkprot
|
|
|
|
changes the protection of kernel memory from
|
|
|
|
.Fa addr
|
|
|
|
to
|
|
|
|
.Fa addr + len
|
|
|
|
to the value of
|
|
|
|
.Fa rw .
|
|
|
|
This is primarily useful for debuggers, for setting breakpoints.
|
|
|
|
This function is only available with options
|
|
|
|
.Dv KGDB .
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_kernacc
|
|
|
|
and
|
|
|
|
.Fn uvm_useracc
|
|
|
|
check the access at address
|
|
|
|
.Fa addr
|
|
|
|
to
|
|
|
|
.Fa addr + len
|
|
|
|
for
|
|
|
|
.Fa rw
|
|
|
|
access, in the kernel address space, and the current process'
|
|
|
|
address space respectively.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_vslock
|
|
|
|
and
|
|
|
|
.Fn uvm_vsunlock
|
1998-05-08 20:00:49 +04:00
|
|
|
control the wiring and unwiring of pages for process
|
|
|
|
.Fa p
|
|
|
|
from
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa addr
|
|
|
|
to
|
|
|
|
.Fa addr + len .
|
|
|
|
These functions are normally used to wire memory for I/O.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_meter
|
|
|
|
calculates the load average and wakes up the swapper if necessary.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_sysctl
|
|
|
|
provides support for the
|
|
|
|
.Dv CTL_VM
|
|
|
|
domain of the
|
|
|
|
.Xr sysctl 3
|
|
|
|
hierarchy.
|
|
|
|
.Fn uvm_sysctl
|
|
|
|
handles the
|
|
|
|
.Dv VM_LOADAVG ,
|
|
|
|
.Dv VM_METER
|
|
|
|
and
|
|
|
|
.Dv VM_UVMEXP
|
|
|
|
calls, which return the current load averages, calculates current VM
|
2002-09-27 11:52:48 +04:00
|
|
|
totals, and returns the uvmexp structure respectively.
|
2003-05-03 23:01:05 +04:00
|
|
|
The load averages are accessed from userland using the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Xr getloadavg 3
|
2002-09-27 11:52:48 +04:00
|
|
|
function.
|
|
|
|
The uvmexp structure has all global state of the UVM system,
|
1998-05-04 11:10:45 +04:00
|
|
|
and has the following members:
|
|
|
|
.Bd -literal
|
|
|
|
/* 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 reserve_pagedaemon; /* number of pages reserved for pagedaemon */
|
|
|
|
int reserve_kernel; /* number of pages reserved for kernel */
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
/* 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 nswget; /* number of times fault calls uvm_swap_get() */
|
|
|
|
int nanon; /* number total of anon's in system */
|
|
|
|
int nfreeanon; /* number of free anon's */
|
|
|
|
|
|
|
|
/* 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 swapins; /* swapins */
|
|
|
|
int swapouts; /* 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 */
|
|
|
|
|
|
|
|
/* fault subcounters */
|
|
|
|
int fltnoram; /* number of times fault was out of ram */
|
|
|
|
int fltnoanon; /* number of times fault was out of anons */
|
|
|
|
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 */
|
2001-06-21 15:59:00 +04:00
|
|
|
int pdscans; /* number of pages daemon scanned since boot */
|
1998-05-04 11:10:45 +04:00
|
|
|
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 */
|
2001-06-21 15:59:00 +04:00
|
|
|
int pdpending; /* number of times daemon got a pending pageout */
|
1998-05-04 11:10:45 +04:00
|
|
|
int pddeact; /* number of pages daemon deactivates */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_fork
|
|
|
|
forks a virtual address space for process' (old)
|
|
|
|
.Fa p1
|
|
|
|
and (new)
|
|
|
|
.Fa p2 .
|
|
|
|
If the
|
|
|
|
.Fa shared
|
|
|
|
argument is non zero, p1 shares its address space with p2,
|
2002-09-27 11:52:48 +04:00
|
|
|
otherwise a new address space is created.
|
|
|
|
This function currently has no return value, and thus cannot fail.
|
|
|
|
In the future, this function will be changed to allow it to
|
1998-05-04 11:10:45 +04:00
|
|
|
fail in low memory conditions.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_grow
|
|
|
|
increases the stack segment of process
|
|
|
|
.Fa p
|
|
|
|
to include
|
|
|
|
.Fa sp .
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_coredump
|
|
|
|
generates a coredump on vnode
|
|
|
|
.Fa vp
|
|
|
|
for process
|
|
|
|
.Fa p
|
|
|
|
with credentials
|
|
|
|
.Fa cred
|
|
|
|
and core header description in
|
|
|
|
.Fa chdr .
|
2001-07-28 19:31:29 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvn_findpages
|
|
|
|
looks up or creates pages in
|
|
|
|
.Fa uobj
|
|
|
|
at offset
|
|
|
|
.Fa offset ,
|
|
|
|
marks them busy and returns them in the
|
|
|
|
.Fa pps
|
|
|
|
array.
|
|
|
|
Currently
|
|
|
|
.Fa uobj
|
|
|
|
must be a vnode object.
|
|
|
|
The number of pages requested is pointed to by
|
|
|
|
.Fa npagesp ,
|
|
|
|
and this value is updated with the actual number of pages returned.
|
|
|
|
The flags can be
|
|
|
|
.Bd -literal
|
2001-07-28 19:55:14 +04:00
|
|
|
#define UFP_ALL 0x00 /* return all pages requested */
|
|
|
|
#define UFP_NOWAIT 0x01 /* don't sleep */
|
|
|
|
#define UFP_NOALLOC 0x02 /* don't allocate new pages */
|
|
|
|
#define UFP_NOCACHE 0x04 /* don't return pages which already exist */
|
|
|
|
#define UFP_NORDONLY 0x08 /* don't return PG_READONLY pages */
|
2001-07-28 19:31:29 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Dv UFP_ALL
|
|
|
|
is a pseudo-flag meaning all requested pages should be returned.
|
|
|
|
.Dv UFP_NOWAIT
|
|
|
|
means that we must not sleep.
|
|
|
|
.Dv UFP_NOALLOC
|
|
|
|
causes any pages which do not already exist to be skipped.
|
|
|
|
.Dv UFP_NOCACHE
|
|
|
|
causes any pages which do already exist to be skipped.
|
|
|
|
.Dv UFP_NORDONLY
|
|
|
|
causes any pages which are marked PG_READONLY to be skipped.
|
2002-03-29 11:56:31 +03:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_swap_stats
|
2002-09-27 11:52:48 +04:00
|
|
|
implements the
|
|
|
|
.Dv SWAP_STATS
|
2002-03-29 11:56:31 +03:00
|
|
|
and
|
|
|
|
.Dv SWAP_OSTATS
|
|
|
|
operation of the
|
|
|
|
.Xr swapctl 2
|
|
|
|
system call.
|
|
|
|
.Fa cmd
|
2002-09-27 11:52:48 +04:00
|
|
|
is the requested command,
|
2002-03-29 11:56:31 +03:00
|
|
|
.Dv SWAP_STATS
|
|
|
|
or
|
|
|
|
.Dv SWAP_OSTATS .
|
2002-09-27 11:52:48 +04:00
|
|
|
The function will copy no more than
|
2002-03-29 11:56:31 +03:00
|
|
|
.Fa sec
|
|
|
|
entries in the array pointed by
|
|
|
|
.Fa sep .
|
2002-09-27 11:52:48 +04:00
|
|
|
On return,
|
2002-03-29 11:56:31 +03:00
|
|
|
.Fa retval
|
|
|
|
holds the actual number of entries copied in the array.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh NOTES
|
|
|
|
.Fn uvm_chgkprot
|
|
|
|
is only available if the kernel has been compiled with options
|
|
|
|
.Dv KGDB .
|
|
|
|
.Pp
|
2001-06-21 15:59:00 +04:00
|
|
|
All structure and types whose names begin with
|
2000-06-29 10:08:44 +04:00
|
|
|
.Dq vm_
|
|
|
|
will be renamed to
|
|
|
|
.Dq uvm_ .
|
2001-12-26 04:02:01 +03:00
|
|
|
.Sh SEE ALSO
|
2002-03-29 11:56:31 +03:00
|
|
|
.Xr swapctl 2 ,
|
2001-12-26 04:02:01 +03:00
|
|
|
.Xr getloadavg 3 ,
|
|
|
|
.Xr kvm 3 ,
|
|
|
|
.Xr sysctl 3 ,
|
|
|
|
.Xr ddb 4 ,
|
|
|
|
.Xr options 4 ,
|
|
|
|
.Xr pmap 9
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
UVM is a new VM system developed at Washington University in St. Louis
|
2002-09-27 11:52:48 +04:00
|
|
|
(Missouri).
|
|
|
|
UVM's roots lie partly in the Mach-based
|
1998-05-04 11:10:45 +04:00
|
|
|
.Bx 4.4
|
2000-09-21 14:43:49 +04:00
|
|
|
VM system, the
|
|
|
|
.Fx
|
2003-04-07 00:54:16 +04:00
|
|
|
VM system, and the SunOS 4 VM system.
|
2002-09-27 11:52:48 +04:00
|
|
|
UVM's basic structure is based on the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Bx 4.4
|
2002-09-27 11:52:48 +04:00
|
|
|
VM system.
|
|
|
|
UVM's new anonymous memory system is based on the
|
2003-04-07 00:54:16 +04:00
|
|
|
anonymous memory system found in the SunOS 4 VM (as described in papers
|
2002-09-27 11:52:48 +04:00
|
|
|
published by Sun Microsystems, Inc.).
|
|
|
|
UVM also includes a number of feature new to
|
2000-09-21 14:43:49 +04:00
|
|
|
.Bx
|
|
|
|
including page loanout, map entry passing, simplified
|
2002-09-27 11:52:48 +04:00
|
|
|
copy-on-write, and clustered anonymous memory pageout.
|
2003-05-03 23:01:05 +04:00
|
|
|
UVM is also further documented in an August 1998 dissertation by
|
2002-09-27 11:52:48 +04:00
|
|
|
Charles D. Cranor.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
UVM appeared in
|
|
|
|
.Nx 1.4 .
|
2001-04-06 19:53:43 +04:00
|
|
|
.Sh AUTHORS
|
2002-09-27 11:52:48 +04:00
|
|
|
Charles D. Cranor
|
|
|
|
.Aq chuck@ccrc.wustl.edu
|
|
|
|
designed and implemented UVM.
|
|
|
|
.Pp
|
|
|
|
Matthew Green
|
|
|
|
.Aq mrg@eterna.com.au
|
|
|
|
wrote the swap-space management code and handled the logistical issues
|
|
|
|
involved with merging UVM into the
|
2000-09-21 14:43:49 +04:00
|
|
|
.Nx
|
|
|
|
source tree.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
2002-09-27 11:52:48 +04:00
|
|
|
Chuck Silvers
|
|
|
|
.Aq chuq@chuq.com
|
|
|
|
implemented the aobj pager, thus allowing UVM to support System V shared
|
|
|
|
memory and process swapping.
|
|
|
|
He also designed and implemented the UBC part of UVM, which uses UVM pages
|
|
|
|
to cache vnode data rather than the traditional buffer cache buffers.
|