2017-07-04 00:28:48 +03:00
|
|
|
.\" $NetBSD: uvm.9,v 1.114 2017/07/03 21:28:48 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.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
2015-03-23 11:11:10 +03:00
|
|
|
.Dd March 23, 2015
|
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
|
2007-12-03 01:09:34 +03:00
|
|
|
initialize UVM sub-systems
|
1998-05-04 11:10:45 +04:00
|
|
|
.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.
|
2007-12-03 01:09:34 +03:00
|
|
|
.Sh INITIALIZATION
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_init "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2005-12-20 22:53:14 +03:00
|
|
|
.Fn uvm_init_limits "struct lwp *l" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_setpagesize "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_swap_init "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
|
|
|
.Fn uvm_init
|
|
|
|
sets up the UVM system at system boot time, after the
|
2006-02-27 14:21:03 +03:00
|
|
|
console has been setup.
|
2007-12-03 01:09:34 +03:00
|
|
|
It initializes 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
|
2007-12-03 01:09:34 +03:00
|
|
|
initializes process limits for the named process.
|
2002-09-27 11:52:48 +04:00
|
|
|
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
|
2017-01-03 00:42:01 +03:00
|
|
|
.Fn uvm_md_init
|
2017-01-05 12:55:01 +03:00
|
|
|
does early boot initialization.
|
|
|
|
This currently includes:
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fn uvm_setpagesize
|
2017-01-05 12:55:01 +03:00
|
|
|
which initializes the uvmexp members pagesize (if not already done by
|
2002-09-27 11:52:48 +04:00
|
|
|
machine-dependent code), pageshift and pagemask.
|
2017-01-03 00:42:01 +03:00
|
|
|
.Fn uvm_physseg_init
|
|
|
|
which initialises the
|
|
|
|
.Xr uvm_hotplug 9
|
|
|
|
subsystem.
|
2002-09-27 11:52:48 +04:00
|
|
|
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
|
2007-12-03 01:09:34 +03:00
|
|
|
initializes the swap sub-system.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh VIRTUAL ADDRESS SPACE MANAGEMENT
|
2011-06-01 06:22:18 +04:00
|
|
|
See
|
|
|
|
.Xr uvm_map 9 .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh PAGE FAULT HANDLING
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft int
|
2007-05-06 16:38:09 +04:00
|
|
|
.Fn uvm_fault "struct vm_map *orig_map" "vaddr_t vaddr" "vm_prot_t access_type" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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
|
2007-05-06 16:38:09 +04:00
|
|
|
offset into the map the fault occurred, and
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa access_type
|
|
|
|
describing the type of access requested.
|
|
|
|
.Fn uvm_fault
|
|
|
|
returns a standard UVM return value.
|
2011-06-01 06:22:18 +04:00
|
|
|
.Sh MEMORY MAPPING FILES AND DEVICES
|
|
|
|
See
|
|
|
|
.Xr ubc 9 .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh VIRTUAL MEMORY I/O
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft int
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_io "struct vm_map *map" "struct uio *uio" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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
|
2011-06-01 06:22:18 +04:00
|
|
|
See
|
|
|
|
.Xr uvm_km 9 .
|
1998-05-04 11:10:45 +04:00
|
|
|
.Sh ALLOCATION OF PHYSICAL MEMORY
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft struct vm_page *
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_pagealloc "struct uvm_object *uobj" "voff_t off" "struct vm_anon *anon" "int flags" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "voff_t newoff" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_pagefree "struct vm_page *pg" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft int
|
2004-12-08 17:12:43 +03:00
|
|
|
.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" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_pglistfree "struct pglist *list" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2009-12-21 23:57:31 +03:00
|
|
|
.Fn uvm_page_physload "paddr_t start" "paddr_t end" "paddr_t avail_start" "paddr_t avail_end" "int free_list" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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
|
2017-07-04 00:28:48 +03:00
|
|
|
in pg->flags so that the page allocator will use
|
2003-11-03 11:07:36 +03:00
|
|
|
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
|
2007-12-03 01:09:34 +03:00
|
|
|
is the maximum number of physically contiguous segments.
|
2002-09-27 11:52:48 +04:00
|
|
|
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
|
2017-07-04 00:28:48 +03:00
|
|
|
in pg->flags so that the page allocator will use
|
2003-11-03 11:07:36 +03:00
|
|
|
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
|
2009-03-12 16:13:16 +03:00
|
|
|
addresses of pages not already in use.
|
|
|
|
If a system has memory banks of
|
2009-03-12 15:55:16 +03:00
|
|
|
different speeds the slower memory should be given a higher
|
|
|
|
.Fa free_list
|
|
|
|
value.
|
1998-05-04 11:10:45 +04:00
|
|
|
.\" XXX expand on "system boot time"!
|
|
|
|
.Sh PROCESSES
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_pageout "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_scheduler "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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.
|
2001-12-24 15:28:46 +03:00
|
|
|
.Sh PAGE LOAN
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft int
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_loan "struct vm_map *map" "vaddr_t start" "vsize_t len" "void *v" "int flags" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_unloan "void *v" "int npages" "int flags" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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
|
2005-08-13 13:49:58 +04:00
|
|
|
should be unlocked,
|
2001-12-24 15:28:46 +03:00
|
|
|
.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.
|
2004-11-23 14:20:18 +03:00
|
|
|
Note that wired pages can't be loaned out and
|
|
|
|
.Fn uvm_loan
|
|
|
|
will fail in that case.
|
2001-12-24 15:28:46 +03:00
|
|
|
.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
|
2009-03-12 15:39:15 +03:00
|
|
|
.Bl -ohang
|
|
|
|
.It Ft struct uvm_object *
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uao_create "vsize_t size" "int flags" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uao_detach "struct uvm_object *uobj" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uao_reference "struct uvm_object *uobj" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft bool
|
2007-03-07 03:41:16 +03:00
|
|
|
.Fn uvm_chgkprot "void *addr" "size_t len" "int rw" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2007-03-07 03:41:16 +03:00
|
|
|
.Fn uvm_kernacc "void *addr" "size_t len" "int rw" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft int
|
2006-10-05 18:48:32 +04:00
|
|
|
.Fn uvm_vslock "struct vmspace *vs" "void *addr" "size_t len" "vm_prot_t prot" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2006-10-05 18:48:32 +04:00
|
|
|
.Fn uvm_vsunlock "struct vmspace *vs" "void *addr" "size_t len" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvm_meter "void" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2009-10-22 01:11:57 +04:00
|
|
|
.Fn uvm_proc_fork "struct proc *p1" "struct proc *p2" "bool shared" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft int
|
2006-01-29 06:09:19 +03:00
|
|
|
.Fn uvm_grow "struct proc *p" "vaddr_t sp" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2004-12-08 17:12:43 +03:00
|
|
|
.Fn uvn_findpages "struct uvm_object *uobj" "voff_t offset" "int *npagesp" "struct vm_page **pps" "int flags" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.It Ft void
|
2009-08-03 23:08:48 +04:00
|
|
|
.Fn uvm_vnp_setsize "struct vnode *vp" "voff_t newsize" ;
|
2009-03-12 15:39:15 +03:00
|
|
|
.El
|
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
|
2003-11-13 06:45:01 +03:00
|
|
|
checks the access at address
|
1998-05-04 11:10:45 +04:00
|
|
|
.Fa addr
|
|
|
|
to
|
|
|
|
.Fa addr + len
|
|
|
|
for
|
|
|
|
.Fa rw
|
2003-11-13 06:45:01 +03:00
|
|
|
access in the kernel address space.
|
1998-05-04 11:10:45 +04:00
|
|
|
.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
|
2009-10-22 01:11:57 +04:00
|
|
|
calculates the load average.
|
1998-05-04 11:10:45 +04:00
|
|
|
.Pp
|
2009-10-22 01:11:57 +04:00
|
|
|
.Fn uvm_proc_fork
|
2004-01-08 00:58:27 +03:00
|
|
|
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,
|
|
|
|
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
|
|
|
|
fail in low memory conditions.
|
|
|
|
.Pp
|
|
|
|
.Fn uvm_grow
|
|
|
|
increases the stack segment of process
|
|
|
|
.Fa p
|
|
|
|
to include
|
|
|
|
.Fa sp .
|
|
|
|
.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.
|
2015-03-23 11:19:12 +03:00
|
|
|
The flags can be any bitwise inclusive-or of:
|
2004-01-08 00:58:27 +03:00
|
|
|
.Pp
|
2015-03-23 11:19:12 +03:00
|
|
|
.Bl -tag -offset abcd -compact -width UVM_ADV_SEQUENTIAL
|
|
|
|
.It Dv UFP_ALL
|
|
|
|
Zero pseudo-flag meaning return all pages.
|
|
|
|
.It Dv UFP_NOWAIT
|
2017-03-18 22:01:01 +03:00
|
|
|
Don't sleep \(em yield
|
2015-03-23 11:19:12 +03:00
|
|
|
.Dv NULL
|
|
|
|
for busy pages or for uncached pages for which allocation would sleep.
|
|
|
|
.It Dv UFP_NOALLOC
|
2017-03-18 22:01:01 +03:00
|
|
|
Don't allocate \(em yield
|
2015-03-23 11:19:12 +03:00
|
|
|
.Dv NULL
|
|
|
|
for uncached pages.
|
|
|
|
.It Dv UFP_NOCACHE
|
2017-03-18 22:01:01 +03:00
|
|
|
Don't use cached pages \(em yield
|
2015-03-23 11:19:12 +03:00
|
|
|
.Dv NULL
|
|
|
|
instead.
|
|
|
|
.It Dv UFP_NORDONLY
|
2017-03-18 22:01:01 +03:00
|
|
|
Don't yield read-only pages \(em yield
|
2015-03-23 11:19:12 +03:00
|
|
|
.Dv NULL
|
|
|
|
for pages marked
|
|
|
|
.Dv PG_READONLY .
|
|
|
|
.It Dv UFP_DIRTYONLY
|
2017-03-18 22:01:01 +03:00
|
|
|
Don't yield clean pages \(em stop early at the first clean one.
|
2015-03-23 11:19:12 +03:00
|
|
|
As a side effect, mark yielded dirty pages clean.
|
|
|
|
Caller must write them to permanent storage before unbusying.
|
|
|
|
.It Dv UFP_BACKWARD
|
|
|
|
Traverse pages in reverse order.
|
2015-03-23 11:00:33 +03:00
|
|
|
If
|
|
|
|
.Fn uvn_findpages
|
2015-03-23 11:19:12 +03:00
|
|
|
returns early, it will have filled
|
2015-03-23 11:00:33 +03:00
|
|
|
.Li * Ns Fa npagesp
|
2015-03-23 11:19:12 +03:00
|
|
|
entries at the end of
|
|
|
|
.Fa pps
|
|
|
|
rather than the beginning.
|
|
|
|
.El
|
2004-01-08 00:58:27 +03:00
|
|
|
.Pp
|
2009-08-03 23:08:48 +04:00
|
|
|
.Fn uvm_vnp_setsize
|
|
|
|
sets the size of vnode
|
|
|
|
.Fa vp
|
|
|
|
to
|
|
|
|
.Fa newsize .
|
|
|
|
Caller must hold a reference to the vnode.
|
|
|
|
If the vnode shrinks, pages no longer used are discarded.
|
2012-07-03 01:10:30 +04:00
|
|
|
.Sh MISCELLANEOUS MACROS
|
|
|
|
.Bl -ohang
|
|
|
|
.It Ft paddr_t
|
|
|
|
.Fn atop "paddr_t pa" ;
|
|
|
|
.It Ft paddr_t
|
|
|
|
.Fn ptoa "paddr_t pn" ;
|
|
|
|
.It Ft paddr_t
|
|
|
|
.Fn round_page "address" ;
|
|
|
|
.It Ft paddr_t
|
|
|
|
.Fn trunc_page "address" ;
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn atop
|
|
|
|
macro converts a physical address
|
|
|
|
.Fa pa
|
|
|
|
into a page number.
|
|
|
|
The
|
|
|
|
.Fn ptoa
|
|
|
|
macro does the opposite by converting a page number
|
|
|
|
.Fa pn
|
|
|
|
into a physical address.
|
|
|
|
.Pp
|
|
|
|
.Fn round_page
|
|
|
|
and
|
|
|
|
.Fn trunc_page
|
|
|
|
macros return a page address boundary from rounding
|
|
|
|
.Fa address
|
|
|
|
up and down, respectively, to the nearest page boundary.
|
|
|
|
These macros work for either addresses or byte counts.
|
2004-01-08 00:58:27 +03:00
|
|
|
.Sh SYSCTL
|
|
|
|
UVM provides support for the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv CTL_VM
|
|
|
|
domain of the
|
|
|
|
.Xr sysctl 3
|
|
|
|
hierarchy.
|
2004-01-08 00:58:27 +03:00
|
|
|
It handles the
|
1998-05-04 11:10:45 +04:00
|
|
|
.Dv VM_LOADAVG ,
|
2004-01-08 00:58:27 +03:00
|
|
|
.Dv VM_METER ,
|
|
|
|
.Dv VM_UVMEXP ,
|
1998-05-04 11:10:45 +04:00
|
|
|
and
|
2004-01-08 00:58:27 +03:00
|
|
|
.Dv VM_UVMEXP2
|
|
|
|
nodes, which return the current load averages, calculates current VM
|
|
|
|
totals, returns the uvmexp structure, and a kernel version independent
|
|
|
|
view of the uvmexp structure, respectively.
|
|
|
|
It also exports a number of tunables that control how much VM space is
|
|
|
|
allowed to be consumed by various tasks.
|
|
|
|
The load averages are typically 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 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 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 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
|
|
|
|
.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
|
2007-02-17 11:49:39 +03:00
|
|
|
.Xr swapctl 2 ,
|
2001-12-26 04:02:01 +03:00
|
|
|
.Xr getloadavg 3 ,
|
|
|
|
.Xr kvm 3 ,
|
2007-02-17 02:13:05 +03:00
|
|
|
.Xr sysctl 3 ,
|
2007-02-17 11:49:39 +03:00
|
|
|
.Xr ddb 4 ,
|
|
|
|
.Xr options 4 ,
|
|
|
|
.Xr memoryallocators 9 ,
|
2009-08-03 23:08:48 +04:00
|
|
|
.Xr pmap 9 ,
|
2011-06-01 06:22:18 +04:00
|
|
|
.Xr ubc 9 ,
|
|
|
|
.Xr uvm_km 9 ,
|
|
|
|
.Xr uvm_map 9
|
2010-04-17 10:38:13 +04:00
|
|
|
.Rs
|
|
|
|
.%A Charles D. Cranor
|
|
|
|
.%A Gurudatta M. Parulkar
|
|
|
|
.%T "The UVM Virtual Memory System"
|
|
|
|
.%I USENIX Association
|
|
|
|
.%B Proceedings of the USENIX Annual Technical Conference
|
|
|
|
.%P 117-130
|
|
|
|
.%D June 6-11, 1999
|
|
|
|
.%U http://www.usenix.org/event/usenix99/full_papers/cranor/cranor.pdf
|
|
|
|
.Re
|
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.).
|
2005-03-11 22:40:47 +03:00
|
|
|
UVM also includes a number of features 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
|
2015-03-23 11:11:10 +03:00
|
|
|
.An -nosplit
|
|
|
|
.An Charles D. Cranor
|
|
|
|
.Aq Mt chuck@ccrc.wustl.edu
|
2002-09-27 11:52:48 +04:00
|
|
|
designed and implemented UVM.
|
|
|
|
.Pp
|
2015-03-23 11:11:10 +03:00
|
|
|
.An Matthew Green
|
|
|
|
.Aq Mt mrg@eterna.com.au
|
2002-09-27 11:52:48 +04:00
|
|
|
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
|
2015-03-23 11:11:10 +03:00
|
|
|
.An Chuck Silvers
|
|
|
|
.Aq Mt chuq@chuq.com
|
2002-09-27 11:52:48 +04:00
|
|
|
implemented the aobj pager, thus allowing UVM to support System V shared
|
|
|
|
memory and process swapping.
|