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 * %sccs.include.redist.c% 9 * 10 * @(#)vm_page.h 7.8 (Berkeley) 10/01/92 11 * 12 * 13 * Copyright (c) 1987, 1990 Carnegie-Mellon University. 14 * All rights reserved. 15 * 16 * Authors: Avadis Tevanian, Jr., Michael Wayne Young 17 * 18 * Permission to use, copy, modify and distribute this software and 19 * its documentation is hereby granted, provided that both the copyright 20 * notice and this permission notice appear in all copies of the 21 * software, derivative works or modified versions, and any portions 22 * thereof, and that both notices appear in supporting documentation. 23 * 24 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 25 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 26 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 27 * 28 * Carnegie Mellon requests users of this software to return to 29 * 30 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 31 * School of Computer Science 32 * Carnegie Mellon University 33 * Pittsburgh PA 15213-3890 34 * 35 * any improvements or extensions that they make and grant Carnegie the 36 * rights to redistribute these changes. 37 */ 38 39 /* 40 * Resident memory system definitions. 41 */ 42 43 #ifndef _VM_PAGE_ 44 #define _VM_PAGE_ 45 46 /* 47 * Management of resident (logical) pages. 48 * 49 * A small structure is kept for each resident 50 * page, indexed by page number. Each structure 51 * is an element of several lists: 52 * 53 * A hash table bucket used to quickly 54 * perform object/offset lookups 55 * 56 * A list of all pages for a given object, 57 * so they can be quickly deactivated at 58 * time of deallocation. 59 * 60 * An ordered list of pages due for pageout. 61 * 62 * In addition, the structure contains the object 63 * and offset to which this page belongs (for pageout), 64 * and sundry status bits. 65 * 66 * Fields in this structure are locked either by the lock on the 67 * object that the page belongs to (O) or by the lock on the page 68 * queues (P). 69 */ 70 71 struct vm_page { 72 queue_chain_t pageq; /* queue info for FIFO 73 * queue or free list (P) */ 74 queue_chain_t hashq; /* hash table links (O)*/ 75 queue_chain_t listq; /* all pages in same object (O)*/ 76 77 vm_object_t object; /* which object am I in (O,P)*/ 78 vm_offset_t offset; /* offset into that object (O,P) */ 79 80 u_short wire_count; /* number wired down maps use me? (P) */ 81 u_short flags; /* see below */ 82 83 vm_offset_t phys_addr; /* physical address of page */ 84 vm_prot_t page_lock; /* Uses prohibited by data manager */ 85 vm_prot_t unlock_request; /* Outstanding unlock request */ 86 }; 87 88 /* 89 * These are the flags defined for vm_page. 90 */ 91 #define PG_INACTIVE 0x0001 /* page is in inactive list (P) */ 92 #define PG_ACTIVE 0x0002 /* page is in active list (P) */ 93 #define PG_LAUNDRY 0x0004 /* page is being cleaned now (P)*/ 94 #define PG_CLEAN 0x0008 /* page has not been modified */ 95 #define PG_BUSY 0x0010 /* page is in transit (O) */ 96 #define PG_WANTED 0x0020 /* someone is waiting for page (O) */ 97 #define PG_TABLED 0x0040 /* page is in VP table (O) */ 98 #define PG_COPYONWRITE 0x0080 /* must copy page before changing (O) */ 99 #define PG_FICTITIOUS 0x0100 /* physical page doesn't exist (O) */ 100 #define PG_ABSENT 0x0200 /* virtual page doesn't exist (O) */ 101 #define PG_FAKE 0x0400 /* page is placeholder for pagein (O) */ 102 #define PG_PAGEROWNED 0x4000 /* DEBUG: async paging op in progress */ 103 #define PG_PTPAGE 0x8000 /* DEBUG: is a user page table page */ 104 105 #if VM_PAGE_DEBUG 106 #define VM_PAGE_CHECK(mem) { \ 107 if ((((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \ 108 (((unsigned int) mem) > \ 109 ((unsigned int) &vm_page_array[last_page-first_page])) || \ 110 ((mem->flags & (PG_ACTIVE | PG_INACTIVE)) == \ 111 (PG_ACTIVE | PG_INACTIVE))) \ 112 panic("vm_page_check: not valid!"); \ 113 } 114 #else VM_PAGE_DEBUG 115 #define VM_PAGE_CHECK(mem) 116 #endif VM_PAGE_DEBUG 117 118 #ifdef KERNEL 119 /* 120 * Each pageable resident page falls into one of three lists: 121 * 122 * free 123 * Available for allocation now. 124 * inactive 125 * Not referenced in any map, but still has an 126 * object/offset-page mapping, and may be dirty. 127 * This is the list of pages that should be 128 * paged out next. 129 * active 130 * A list of pages which have been placed in 131 * at least one physical map. This list is 132 * ordered, in LRU-like fashion. 133 */ 134 135 extern 136 queue_head_t vm_page_queue_free; /* memory free queue */ 137 extern 138 queue_head_t vm_page_queue_active; /* active memory queue */ 139 extern 140 queue_head_t vm_page_queue_inactive; /* inactive memory queue */ 141 142 extern 143 vm_page_t vm_page_array; /* First resident page in table */ 144 extern 145 long first_page; /* first physical page number */ 146 /* ... represented in vm_page_array */ 147 extern 148 long last_page; /* last physical page number */ 149 /* ... represented in vm_page_array */ 150 /* [INCLUSIVE] */ 151 extern 152 vm_offset_t first_phys_addr; /* physical address for first_page */ 153 extern 154 vm_offset_t last_phys_addr; /* physical address for last_page */ 155 156 #define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr) 157 158 #define IS_VM_PHYSADDR(pa) \ 159 ((pa) >= first_phys_addr && (pa) <= last_phys_addr) 160 161 #define PHYS_TO_VM_PAGE(pa) \ 162 (&vm_page_array[atop(pa) - first_page ]) 163 164 extern 165 simple_lock_data_t vm_page_queue_lock; /* lock on active and inactive 166 page queues */ 167 extern /* lock on free page queue */ 168 simple_lock_data_t vm_page_queue_free_lock; 169 170 /* 171 * Functions implemented as macros 172 */ 173 174 #define PAGE_ASSERT_WAIT(m, interruptible) { \ 175 (m)->flags |= PG_WANTED; \ 176 assert_wait((int) (m), (interruptible)); \ 177 } 178 179 #define PAGE_WAKEUP(m) { \ 180 (m)->flags &= ~PG_BUSY; \ 181 if ((m)->flags & PG_WANTED) { \ 182 (m)->flags &= ~PG_WANTED; \ 183 thread_wakeup((int) (m)); \ 184 } \ 185 } 186 187 #define vm_page_lock_queues() simple_lock(&vm_page_queue_lock) 188 #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock) 189 190 #define vm_page_set_modified(m) { (m)->flags &= ~PG_CLEAN; } 191 192 #ifdef DEBUG 193 #define VM_PAGE_DEBUG_INIT(m) 194 #else 195 #define VM_PAGE_DEBUG_INIT(m) 196 #endif 197 198 #define VM_PAGE_INIT(mem, object, offset) { \ 199 (mem)->flags = PG_BUSY | PG_CLEAN | PG_FAKE; \ 200 vm_page_insert((mem), (object), (offset)); \ 201 (mem)->page_lock = VM_PROT_NONE; \ 202 (mem)->unlock_request = VM_PROT_NONE; \ 203 (mem)->wire_count = 0; \ 204 VM_PAGE_DEBUG_INIT(mem); \ 205 } 206 207 void vm_page_activate __P((vm_page_t)); 208 vm_page_t vm_page_alloc __P((vm_object_t, vm_offset_t)); 209 void vm_page_copy __P((vm_page_t, vm_page_t)); 210 void vm_page_deactivate __P((vm_page_t)); 211 void vm_page_free __P((vm_page_t)); 212 void vm_page_insert __P((vm_page_t, vm_object_t, vm_offset_t)); 213 vm_page_t vm_page_lookup __P((vm_object_t, vm_offset_t)); 214 void vm_page_remove __P((vm_page_t)); 215 void vm_page_rename __P((vm_page_t, vm_object_t, vm_offset_t)); 216 void vm_page_startup __P((vm_offset_t *, vm_offset_t *)); 217 void vm_page_unwire __P((vm_page_t)); 218 void vm_page_wire __P((vm_page_t)); 219 boolean_t vm_page_zero_fill __P((vm_page_t)); 220 221 #endif /* KERNEL */ 222 #endif /* !_VM_PAGE_ */ 223