/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
* 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.
*
* from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
*/
/*-
* Copyright (c) 1991, 1992, 1993
* The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)vm_extern.h 8.5 (Berkeley) 5/3/95
*/
/*
* uvm_extern.h: this file defines the external interface to the VM system.
*
* this should be the only file included by non-VM parts of the kernel
* which need access to VM services. if you want to know the interface
* to the MI VM layer without knowing the details, this is the file to
* learn.
*
* NOTE: vm system calls are prototyped in syscallargs.h
*/
#include <sys/types.h>
/*
* defines
*/
/*
* the following defines are for uvm_map and functions which call it.
*/
/* magic offset value: offset not known(obj) or don't care(!obj) */
#define UVM_UNKNOWN_OFFSET ((voff_t) -1)
/*
* the following defines are for uvm_km_alloc/free's flags
*/
#define UVM_KMF_WIRED 0x1 /* allocation type: wired */
#define UVM_KMF_PAGEABLE 0x2 /* allocation type: pageable */
#define UVM_KMF_VAONLY 0x4 /* allocation type: VA only */
#define UVM_KMF_TYPEMASK (UVM_KMF_VAONLY | UVM_KMF_PAGEABLE | UVM_KMF_WIRED)
#define UVM_KMF_CANFAIL 0x8 /* caller handles failure */
#define UVM_KMF_ZERO 0x10 /* want zero filled memory */
#define UVM_KMF_EXEC 0x20 /* need executable mapping */
#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
#define UVM_KMF_NOWAIT UVM_FLAG_NOWAIT /* not allowed to sleep */
#define UVM_KMF_WAITVA UVM_FLAG_WAITVA /* sleep for va */
#define UVM_KMF_COLORMATCH UVM_FLAG_COLORMATCH /* start at color in align */
/*
* the following defines the strategies for uvm_pagealloc_strat()
*/
#define UVM_PGA_STRAT_NORMAL 0 /* priority (low id to high) walk */
#define UVM_PGA_STRAT_ONLY 1 /* only specified free list */
#define UVM_PGA_STRAT_FALLBACK 2 /* ONLY falls back on NORMAL */
#define UVM_PGA_STRAT_NUMA 3 /* strongly prefer ideal bucket */
/*
* flags for uvm_pagealloc_strat()
*/
#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */
#define UVM_PGA_ZERO 0x0002 /* returned page must be zero'd */
/*
* flags for ubc_uiomove()
*/
#define UBC_READ 0x001 /* reading from object */
#define UBC_WRITE 0x002 /* writing to object */
#define UBC_FAULTBUSY 0x004 /* nobody else is using these pages, so busy
* them at alloc and unbusy at release (e.g.,
* for writes extending a file) */
#define UBC_ISMAPPED 0x008 /* object may be mapped by a process */
/*
* flags for ubc_release()
*/
#define UBC_UNMAP 0x010 /* unmap pages now -- don't leave the
* mappings cached indefinitely */
/*
* flags for ubc_uiomove()
*/
#define UBC_PARTIALOK 0x100 /* return early on error; otherwise, zero all
* remaining bytes after error */
/*
* lockflags that control the locking behavior of various functions.
*/
#define UVM_LK_ENTER 0x00000001 /* map locked on entry */
#define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */
/*
* Default number of pages to allocate on the stack
*/
#define UBC_MAX_PAGES 8
/*
* Value representing inactive emap.
*/
#define UVM_EMAP_INACTIVE (0)
/*
* uvm_pctparam: parameter to be shown as percentage to user.
*/
#define UVM_PCTPARAM_SHIFT 8
#define UVM_PCTPARAM_SCALE (1 << UVM_PCTPARAM_SHIFT)
#define UVM_PCTPARAM_APPLY(pct, x) \
(((x) * (pct)->pct_scaled) >> UVM_PCTPARAM_SHIFT)
struct uvm_pctparam {
int pct_pct; /* percent [0, 100] */ /* should be the first member */
int pct_scaled;
int (*pct_check)(struct uvm_pctparam *, int);
};
/*
* uvmexp: global data structures that are exported to parts of the kernel
* other than the vm system.
*/
struct uvmexp {
/* 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 */
/*
* Adding anything before this line will break binary compatibility
* with top(1) on NetBSD 1.5.
*/
int ncolors; /* number of page color buckets: must be p-o-2 */
int colormask; /* color bucket mask */
int zeropages; /* number of zero'd pages */
int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
int reserve_kernel; /* number of pages reserved for kernel */
unsigned anonpages; /* number of pages used by anon mappings */
unsigned filepages; /* number of pages used by cached file data */
unsigned execpages; /* number of pages used by cached exec data */
/* pageout params */
int freemin; /* min number of free pages */
int freetarg; /* target number of free 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 swpgavail; /* number of swap pages currently available */
int swpginuse; /* number of swap pages in use */
int swpgonly; /* number of swap pages in use, not also in RAM */
int nswget; /* number of times fault calls uvm_swap_get() */
/* stat counters. XXX: should be 64-bit 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 _unused1;
int _unused2;
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 */
int pga_zerohit; /* pagealloc where zero wanted and zero
was available */
int pga_zeromiss; /* pagealloc where zero wanted and zero
not available */
int zeroaborts; /* number of times page zeroing was
aborted */
int colorhit; /* pagealloc where we got optimal color */
int colormiss; /* pagealloc where we didn't */
int cpuhit; /* pagealloc where we allocated locally */
int cpumiss; /* pagealloc where we didn't */
/* fault subcounters. XXX: should be 64-bit counters */
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. XXX: should be 64-bit counters */
int pdwoke; /* number of times daemon woke up */
int pdrevs; /* number of times daemon rev'd clock hand */
int _unused3;
int pdfreed; /* number of pages daemon freed since boot */
int pdscans; /* number of pages daemon scanned since boot */
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 */
int pdpending; /* number of times daemon got a pending pagout */
int pddeact; /* number of pages daemon deactivates */
int pdreanon; /* anon pages reactivated due to thresholds */
int pdrefile; /* file pages reactivated due to thresholds */
int pdreexec; /* executable pages reactivated due to thresholds */
int bootpages; /* number of pages stolen at boot */
};
#ifdef _KERNEL
/*
* Include the uvm_hotplug(9) API unconditionally until
* uvm_page_physload() et. al. are obsoleted
*
* After this, MD code will have to explicitly include it if needed.
*/
#include <uvm/uvm_physseg.h>
#endif
#if defined(_KERNEL) || defined(_KMEMUSER)
/*
* Shareable process virtual address space.
* May eventually be merged with vm_map.
* Several fields are temporary (text, data stuff).
*/
struct vmspace {
struct vm_map vm_map; /* VM address map */
volatile int vm_refcnt; /* number of references */
void * vm_shm; /* SYS5 shared memory private data XXX */
/* we copy from vm_startcopy to the end of the structure on fork */
#define vm_startcopy vm_rssize
segsz_t vm_rssize; /* current resident set size in pages */
segsz_t vm_rssmax; /* max resident size in pages */
segsz_t vm_tsize; /* text size (pages) XXX */
segsz_t vm_dsize; /* data size (pages) XXX */
segsz_t vm_ssize; /* stack size (pages) */
segsz_t vm_issize; /* initial unmapped stack size (pages) */
void * vm_taddr; /* user virtual address of text XXX */
void * vm_daddr; /* user virtual address of data XXX */
void *vm_maxsaddr; /* user VA at max stack growth */
void *vm_minsaddr; /* user VA at top of stack */
size_t vm_aslr_delta_mmap; /* mmap() random delta for ASLR */
};
#define VMSPACE_IS_KERNEL_P(vm) VM_MAP_IS_KERNEL(&(vm)->vm_map)
#endif
#ifdef _KERNEL
/*
* used to keep state while iterating over the map for a core dump.
*/
struct uvm_coredump_state {
void *cookie; /* opaque for the caller */
vaddr_t start; /* start of region */
vaddr_t realend; /* real end of region */
vaddr_t end; /* virtual end of region */
vm_prot_t prot; /* protection of region */
int flags; /* flags; see below */
};
#define UVM_COREDUMP_STACK 0x01 /* region is user stack */
/*
* the various kernel maps, owned by MD code
*/
extern struct vm_map *kernel_map;
extern struct vm_map *phys_map;
/*
* uvm_voaddr:
*
* This structure encapsulates UVM's unique virtual object address
* for an individual byte inside a pageable page. Pageable pages can
* be owned by either a uvm_object or a vm_anon.
*
* In each case, the byte offset into the owning object
* (uvm_object or vm_anon) is included in the ID, so that
* two different offsets into the same page have distinct
* IDs.
*
* Note that the page does not necessarily have to be resident
* in order to know the virtual object address. However, it
* is required that any pending copy-on-write is resolved.
*
* When someone wants a virtual object address, an extra reference
* is taken on the owner while the caller uses the ID. This
* ensures that the identity is stable for the duration of its
* use.
*/
struct uvm_voaddr {
uintptr_t object;
voff_t offset;
};