| 1 | /* |
| 2 | * Copyright (c) 1991 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This code is derived from software contributed to Berkeley by |
| 6 | * The Mach Operating System project at Carnegie-Mellon University. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. All advertising materials mentioning features or use of this software |
| 17 | * must display the following acknowledgement: |
| 18 | * This product includes software developed by the University of |
| 19 | * California, Berkeley and its contributors. |
| 20 | * 4. Neither the name of the University nor the names of its contributors |
| 21 | * may be used to endorse or promote products derived from this software |
| 22 | * without specific prior written permission. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | * SUCH DAMAGE. |
| 35 | * |
| 36 | * @(#)vm_page.h 7.3 (Berkeley) 4/21/91 |
| 37 | * |
| 38 | * |
| 39 | * Copyright (c) 1987, 1990 Carnegie-Mellon University. |
| 40 | * All rights reserved. |
| 41 | * |
| 42 | * Authors: Avadis Tevanian, Jr., Michael Wayne Young |
| 43 | * |
| 44 | * Permission to use, copy, modify and distribute this software and |
| 45 | * its documentation is hereby granted, provided that both the copyright |
| 46 | * notice and this permission notice appear in all copies of the |
| 47 | * software, derivative works or modified versions, and any portions |
| 48 | * thereof, and that both notices appear in supporting documentation. |
| 49 | * |
| 50 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 51 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND |
| 52 | * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 53 | * |
| 54 | * Carnegie Mellon requests users of this software to return to |
| 55 | * |
| 56 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
| 57 | * School of Computer Science |
| 58 | * Carnegie Mellon University |
| 59 | * Pittsburgh PA 15213-3890 |
| 60 | * |
| 61 | * any improvements or extensions that they make and grant Carnegie the |
| 62 | * rights to redistribute these changes. |
| 63 | */ |
| 64 | |
| 65 | /* |
| 66 | * Resident memory system definitions. |
| 67 | */ |
| 68 | |
| 69 | #ifndef _VM_PAGE_ |
| 70 | #define _VM_PAGE_ |
| 71 | |
| 72 | /* |
| 73 | * Management of resident (logical) pages. |
| 74 | * |
| 75 | * A small structure is kept for each resident |
| 76 | * page, indexed by page number. Each structure |
| 77 | * is an element of several lists: |
| 78 | * |
| 79 | * A hash table bucket used to quickly |
| 80 | * perform object/offset lookups |
| 81 | * |
| 82 | * A list of all pages for a given object, |
| 83 | * so they can be quickly deactivated at |
| 84 | * time of deallocation. |
| 85 | * |
| 86 | * An ordered list of pages due for pageout. |
| 87 | * |
| 88 | * In addition, the structure contains the object |
| 89 | * and offset to which this page belongs (for pageout), |
| 90 | * and sundry status bits. |
| 91 | * |
| 92 | * Fields in this structure are locked either by the lock on the |
| 93 | * object that the page belongs to (O) or by the lock on the page |
| 94 | * queues (P). |
| 95 | */ |
| 96 | |
| 97 | struct vm_page { |
| 98 | queue_chain_t pageq; /* queue info for FIFO |
| 99 | * queue or free list (P) */ |
| 100 | queue_chain_t hashq; /* hash table links (O)*/ |
| 101 | queue_chain_t listq; /* all pages in same object (O)*/ |
| 102 | |
| 103 | vm_object_t object; /* which object am I in (O,P)*/ |
| 104 | vm_offset_t offset; /* offset into that object (O,P) */ |
| 105 | |
| 106 | unsigned int wire_count:16, /* how many wired down maps use me? |
| 107 | (P) */ |
| 108 | /* boolean_t */ inactive:1, /* page is in inactive list (P) */ |
| 109 | active:1, /* page is in active list (P) */ |
| 110 | laundry:1, /* page is being cleaned now (P)*/ |
| 111 | #ifdef DEBUG |
| 112 | pagerowned:1, /* async paging op in progress */ |
| 113 | ptpage:1, /* is a user page table page */ |
| 114 | #endif |
| 115 | :0; /* (force to 'long' boundary) */ |
| 116 | #ifdef ns32000 |
| 117 | int pad; /* extra space for ns32000 bit ops */ |
| 118 | #endif ns32000 |
| 119 | boolean_t clean; /* page has not been modified */ |
| 120 | unsigned int |
| 121 | /* boolean_t */ busy:1, /* page is in transit (O) */ |
| 122 | wanted:1, /* someone is waiting for page (O) */ |
| 123 | tabled:1, /* page is in VP table (O) */ |
| 124 | copy_on_write:1,/* page must be copied before being |
| 125 | changed (O) */ |
| 126 | fictitious:1, /* physical page doesn't exist (O) */ |
| 127 | absent:1, /* virtual page doesn't exist (O) */ |
| 128 | fake:1, /* page is a placeholder for page-in |
| 129 | (O) */ |
| 130 | :0; |
| 131 | |
| 132 | vm_offset_t phys_addr; /* physical address of page */ |
| 133 | vm_prot_t page_lock; /* Uses prohibited by data manager */ |
| 134 | vm_prot_t unlock_request; /* Outstanding unlock request */ |
| 135 | }; |
| 136 | |
| 137 | typedef struct vm_page *vm_page_t; |
| 138 | |
| 139 | #if VM_PAGE_DEBUG |
| 140 | #define VM_PAGE_CHECK(mem) { \ |
| 141 | if ( (((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \ |
| 142 | (((unsigned int) mem) > ((unsigned int) &vm_page_array[last_page-first_page])) || \ |
| 143 | (mem->active && mem->inactive) \ |
| 144 | ) panic("vm_page_check: not valid!"); \ |
| 145 | } |
| 146 | #else VM_PAGE_DEBUG |
| 147 | #define VM_PAGE_CHECK(mem) |
| 148 | #endif VM_PAGE_DEBUG |
| 149 | |
| 150 | #ifdef KERNEL |
| 151 | /* |
| 152 | * Each pageable resident page falls into one of three lists: |
| 153 | * |
| 154 | * free |
| 155 | * Available for allocation now. |
| 156 | * inactive |
| 157 | * Not referenced in any map, but still has an |
| 158 | * object/offset-page mapping, and may be dirty. |
| 159 | * This is the list of pages that should be |
| 160 | * paged out next. |
| 161 | * active |
| 162 | * A list of pages which have been placed in |
| 163 | * at least one physical map. This list is |
| 164 | * ordered, in LRU-like fashion. |
| 165 | */ |
| 166 | |
| 167 | extern |
| 168 | queue_head_t vm_page_queue_free; /* memory free queue */ |
| 169 | extern |
| 170 | queue_head_t vm_page_queue_active; /* active memory queue */ |
| 171 | extern |
| 172 | queue_head_t vm_page_queue_inactive; /* inactive memory queue */ |
| 173 | |
| 174 | extern |
| 175 | vm_page_t vm_page_array; /* First resident page in table */ |
| 176 | extern |
| 177 | long first_page; /* first physical page number */ |
| 178 | /* ... represented in vm_page_array */ |
| 179 | extern |
| 180 | long last_page; /* last physical page number */ |
| 181 | /* ... represented in vm_page_array */ |
| 182 | /* [INCLUSIVE] */ |
| 183 | extern |
| 184 | vm_offset_t first_phys_addr; /* physical address for first_page */ |
| 185 | extern |
| 186 | vm_offset_t last_phys_addr; /* physical address for last_page */ |
| 187 | |
| 188 | extern |
| 189 | int vm_page_free_count; /* How many pages are free? */ |
| 190 | extern |
| 191 | int vm_page_active_count; /* How many pages are active? */ |
| 192 | extern |
| 193 | int vm_page_inactive_count; /* How many pages are inactive? */ |
| 194 | extern |
| 195 | int vm_page_wire_count; /* How many pages are wired? */ |
| 196 | extern |
| 197 | int vm_page_free_target; /* How many do we want free? */ |
| 198 | extern |
| 199 | int vm_page_free_min; /* When to wakeup pageout */ |
| 200 | extern |
| 201 | int vm_page_inactive_target;/* How many do we want inactive? */ |
| 202 | extern |
| 203 | int vm_page_free_reserved; /* How many pages reserved to do pageout */ |
| 204 | extern |
| 205 | int vm_page_laundry_count; /* How many pages being laundered? */ |
| 206 | |
| 207 | #define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr) |
| 208 | |
| 209 | #define IS_VM_PHYSADDR(pa) \ |
| 210 | ((pa) >= first_phys_addr && (pa) <= last_phys_addr) |
| 211 | |
| 212 | #define PHYS_TO_VM_PAGE(pa) \ |
| 213 | (&vm_page_array[atop(pa) - first_page ]) |
| 214 | |
| 215 | extern |
| 216 | simple_lock_data_t vm_page_queue_lock; /* lock on active and inactive |
| 217 | page queues */ |
| 218 | extern |
| 219 | simple_lock_data_t vm_page_queue_free_lock; |
| 220 | /* lock on free page queue */ |
| 221 | vm_offset_t vm_page_startup(); |
| 222 | vm_page_t vm_page_lookup(); |
| 223 | vm_page_t vm_page_alloc(); |
| 224 | void vm_page_init(); |
| 225 | void vm_page_free(); |
| 226 | void vm_page_activate(); |
| 227 | void vm_page_deactivate(); |
| 228 | void vm_page_rename(); |
| 229 | void vm_page_replace(); |
| 230 | |
| 231 | boolean_t vm_page_zero_fill(); |
| 232 | void vm_page_copy(); |
| 233 | |
| 234 | void vm_page_wire(); |
| 235 | void vm_page_unwire(); |
| 236 | |
| 237 | void vm_set_page_size(); |
| 238 | |
| 239 | /* |
| 240 | * Functions implemented as macros |
| 241 | */ |
| 242 | |
| 243 | #define PAGE_ASSERT_WAIT(m, interruptible) { \ |
| 244 | (m)->wanted = TRUE; \ |
| 245 | assert_wait((int) (m), (interruptible)); \ |
| 246 | } |
| 247 | |
| 248 | #define PAGE_WAKEUP(m) { \ |
| 249 | (m)->busy = FALSE; \ |
| 250 | if ((m)->wanted) { \ |
| 251 | (m)->wanted = FALSE; \ |
| 252 | thread_wakeup((int) (m)); \ |
| 253 | } \ |
| 254 | } |
| 255 | |
| 256 | #define vm_page_lock_queues() simple_lock(&vm_page_queue_lock) |
| 257 | #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock) |
| 258 | |
| 259 | #define vm_page_set_modified(m) { (m)->clean = FALSE; } |
| 260 | #endif KERNEL |
| 261 | #endif _VM_PAGE_ |