Home | History | Annotate | Line # | Download | only in uvm
uvm.h revision 1.60
      1 /*	$NetBSD: uvm.h,v 1.60 2011/02/02 15:13:33 chuck Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * Copyright (c) 1997 Charles D. Cranor and Washington University.
     31  * All rights reserved.
     32  *
     33  * Redistribution and use in source and binary forms, with or without
     34  * modification, are permitted provided that the following conditions
     35  * are met:
     36  * 1. Redistributions of source code must retain the above copyright
     37  *    notice, this list of conditions and the following disclaimer.
     38  * 2. Redistributions in binary form must reproduce the above copyright
     39  *    notice, this list of conditions and the following disclaimer in the
     40  *    documentation and/or other materials provided with the distribution.
     41  *
     42  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     43  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     44  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     45  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     46  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     47  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     48  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     49  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     50  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     51  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     52  *
     53  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
     54  */
     55 
     56 #ifndef _UVM_UVM_H_
     57 #define _UVM_UVM_H_
     58 
     59 #if defined(_KERNEL_OPT)
     60 #include "opt_lockdebug.h"
     61 #include "opt_multiprocessor.h"
     62 #include "opt_uvmhist.h"
     63 #include "opt_uvm_page_trkown.h"
     64 #endif
     65 
     66 #include <uvm/uvm_extern.h>
     67 
     68 #include <uvm/uvm_stat.h>
     69 
     70 /*
     71  * pull in prototypes
     72  */
     73 
     74 #include <uvm/uvm_amap.h>
     75 #include <uvm/uvm_aobj.h>
     76 #include <uvm/uvm_fault.h>
     77 #include <uvm/uvm_glue.h>
     78 #include <uvm/uvm_km.h>
     79 #include <uvm/uvm_loan.h>
     80 #include <uvm/uvm_map.h>
     81 #include <uvm/uvm_object.h>
     82 #include <uvm/uvm_page.h>
     83 #include <uvm/uvm_pager.h>
     84 #include <uvm/uvm_pdaemon.h>
     85 #include <uvm/uvm_swap.h>
     86 
     87 #ifdef _KERNEL
     88 
     89 /*
     90  * pull in VM_NFREELIST
     91  */
     92 #include <machine/vmparam.h>
     93 
     94 struct workqueue;
     95 
     96 /*
     97  * per-cpu data
     98  */
     99 
    100 struct uvm_cpu {
    101 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
    102 	int page_free_nextcolor;	/* next color to allocate from */
    103 	int page_idlezero_next;		/* which color to zero next */
    104 	bool page_idle_zero;		/* TRUE if we should try to zero
    105 					   pages in the idle loop */
    106 	int pages[PGFL_NQUEUES];	/* total of pages in page_free */
    107 	u_int emap_gen;			/* emap generation number */
    108 };
    109 
    110 /*
    111  * uvm structure (vm global state: collected in one structure for ease
    112  * of reference...)
    113  */
    114 
    115 struct uvm {
    116 	/* vm_page related parameters */
    117 
    118 		/* vm_page queues */
    119 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
    120 	bool page_init_done;		/* TRUE if uvm_page_init() finished */
    121 
    122 		/* page daemon trigger */
    123 	int pagedaemon;			/* daemon sleeps on this */
    124 	struct lwp *pagedaemon_lwp;	/* daemon's lid */
    125 
    126 		/* aiodone daemon */
    127 	struct workqueue *aiodone_queue;
    128 
    129 	/* aio_done is locked by uvm.pagedaemon_lock and splbio! */
    130 	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
    131 
    132 	/* per-cpu data */
    133 	struct uvm_cpu *cpus[MAXCPUS];
    134 };
    135 
    136 /*
    137  * kernel object: to support anonymous pageable kernel memory
    138  */
    139 extern struct uvm_object *uvm_kernel_object;
    140 
    141 /*
    142  * locks (made globals for lockstat).
    143  */
    144 
    145 extern kmutex_t uvm_pageqlock;		/* lock for active/inactive page q */
    146 extern kmutex_t uvm_fpageqlock;		/* lock for free page q */
    147 extern kmutex_t uvm_kentry_lock;
    148 extern kmutex_t uvm_swap_data_lock;
    149 
    150 #endif /* _KERNEL */
    151 
    152 /*
    153  * vm_map_entry etype bits:
    154  */
    155 
    156 #define UVM_ET_OBJ		0x01	/* it is a uvm_object */
    157 #define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
    158 #define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
    159 #define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
    160 
    161 #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
    162 #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
    163 #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
    164 #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
    165 
    166 #ifdef _KERNEL
    167 
    168 /*
    169  * holds all the internal UVM data
    170  */
    171 extern struct uvm uvm;
    172 
    173 /*
    174  * historys
    175  */
    176 
    177 #ifdef UVMHIST
    178 UVMHIST_DECL(maphist);
    179 UVMHIST_DECL(pdhist);
    180 UVMHIST_DECL(ubchist);
    181 UVMHIST_DECL(loanhist);
    182 #endif
    183 
    184 extern struct evcnt uvm_ra_total;
    185 extern struct evcnt uvm_ra_hit;
    186 extern struct evcnt uvm_ra_miss;
    187 
    188 /*
    189  * UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
    190  * interlocked tsleep() function.
    191  */
    192 
    193 #define	UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo)		\
    194 do {									\
    195 	(void) mtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0),	\
    196 	    msg, timo, slock);						\
    197 } while (/*CONSTCOND*/ 0)
    198 
    199 void uvm_kick_pdaemon(void);
    200 
    201 /*
    202  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
    203  */
    204 
    205 #if defined(UVM_PAGE_TRKOWN)
    206 #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
    207 #else
    208 #define UVM_PAGE_OWN(PG, TAG) /* nothing */
    209 #endif /* UVM_PAGE_TRKOWN */
    210 
    211 #include <uvm/uvm_fault_i.h>
    212 
    213 #endif /* _KERNEL */
    214 
    215 #endif /* _UVM_UVM_H_ */
    216