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