1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1991, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 6df8bae1dSRodney W. Grimes * The Mach Operating System project at Carnegie-Mellon University. 7df8bae1dSRodney W. Grimes * 8df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 9df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 10df8bae1dSRodney W. Grimes * are met: 11df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 12df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 13df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 15df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 16df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 17df8bae1dSRodney W. Grimes * must display the following acknowledgement: 18df8bae1dSRodney W. Grimes * This product includes software developed by the University of 19df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 20df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 21df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 22df8bae1dSRodney W. Grimes * without specific prior written permission. 23df8bae1dSRodney W. Grimes * 24df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34df8bae1dSRodney W. Grimes * SUCH DAMAGE. 35df8bae1dSRodney W. Grimes * 363c4dd356SDavid Greenman * from: @(#)vm_object.h 8.3 (Berkeley) 1/12/94 37df8bae1dSRodney W. Grimes * 38df8bae1dSRodney W. Grimes * 39df8bae1dSRodney W. Grimes * Copyright (c) 1987, 1990 Carnegie-Mellon University. 40df8bae1dSRodney W. Grimes * All rights reserved. 41df8bae1dSRodney W. Grimes * 42df8bae1dSRodney W. Grimes * Authors: Avadis Tevanian, Jr., Michael Wayne Young 43df8bae1dSRodney W. Grimes * 44df8bae1dSRodney W. Grimes * Permission to use, copy, modify and distribute this software and 45df8bae1dSRodney W. Grimes * its documentation is hereby granted, provided that both the copyright 46df8bae1dSRodney W. Grimes * notice and this permission notice appear in all copies of the 47df8bae1dSRodney W. Grimes * software, derivative works or modified versions, and any portions 48df8bae1dSRodney W. Grimes * thereof, and that both notices appear in supporting documentation. 49df8bae1dSRodney W. Grimes * 50df8bae1dSRodney W. Grimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 51df8bae1dSRodney W. Grimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 52df8bae1dSRodney W. Grimes * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 53df8bae1dSRodney W. Grimes * 54df8bae1dSRodney W. Grimes * Carnegie Mellon requests users of this software to return to 55df8bae1dSRodney W. Grimes * 56df8bae1dSRodney W. Grimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57df8bae1dSRodney W. Grimes * School of Computer Science 58df8bae1dSRodney W. Grimes * Carnegie Mellon University 59df8bae1dSRodney W. Grimes * Pittsburgh PA 15213-3890 60df8bae1dSRodney W. Grimes * 61df8bae1dSRodney W. Grimes * any improvements or extensions that they make and grant Carnegie the 62df8bae1dSRodney W. Grimes * rights to redistribute these changes. 633c4dd356SDavid Greenman * 640d94caffSDavid Greenman * $Id: vm_object.h,v 1.3 1994/11/06 05:07:52 davidg Exp $ 65df8bae1dSRodney W. Grimes */ 66df8bae1dSRodney W. Grimes 67df8bae1dSRodney W. Grimes /* 68df8bae1dSRodney W. Grimes * Virtual memory object module definitions. 69df8bae1dSRodney W. Grimes */ 70df8bae1dSRodney W. Grimes 71df8bae1dSRodney W. Grimes #ifndef _VM_OBJECT_ 72df8bae1dSRodney W. Grimes #define _VM_OBJECT_ 73df8bae1dSRodney W. Grimes 74df8bae1dSRodney W. Grimes #include <vm/vm_page.h> 75df8bae1dSRodney W. Grimes #include <vm/vm_pager.h> 76df8bae1dSRodney W. Grimes 77df8bae1dSRodney W. Grimes /* 78df8bae1dSRodney W. Grimes * Types defined: 79df8bae1dSRodney W. Grimes * 80df8bae1dSRodney W. Grimes * vm_object_t Virtual memory object. 81df8bae1dSRodney W. Grimes */ 82df8bae1dSRodney W. Grimes 83df8bae1dSRodney W. Grimes struct vm_object { 84df8bae1dSRodney W. Grimes struct pglist memq; /* Resident memory */ 85df8bae1dSRodney W. Grimes TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ 86df8bae1dSRodney W. Grimes u_short flags; /* see below */ 870d94caffSDavid Greenman u_short paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ 88df8bae1dSRodney W. Grimes int ref_count; /* How many refs?? */ 890d94caffSDavid Greenman struct { 900d94caffSDavid Greenman int recursion; /* object locking */ 910d94caffSDavid Greenman struct proc *proc; /* process owned */ 920d94caffSDavid Greenman } lock; 93df8bae1dSRodney W. Grimes vm_size_t size; /* Object size */ 94df8bae1dSRodney W. Grimes int resident_page_count; 95df8bae1dSRodney W. Grimes /* number of resident pages */ 960d94caffSDavid Greenman struct vm_object *copy; /* Object that holds copies of my changed pages */ 97df8bae1dSRodney W. Grimes vm_pager_t pager; /* Where to get data */ 98df8bae1dSRodney W. Grimes vm_offset_t paging_offset; /* Offset into paging space */ 99df8bae1dSRodney W. Grimes struct vm_object *shadow; /* My shadow */ 100df8bae1dSRodney W. Grimes vm_offset_t shadow_offset; /* Offset in shadow */ 101df8bae1dSRodney W. Grimes TAILQ_ENTRY(vm_object) cached_list; /* for persistence */ 1022fe6e4d7SDavid Greenman TAILQ_ENTRY(vm_object) reverse_shadow_list; /* chain of objects that are shadowed */ 1032fe6e4d7SDavid Greenman TAILQ_HEAD(rslist, vm_object) reverse_shadow_head; /* objects that this is a shadow for */ 104df8bae1dSRodney W. Grimes }; 1050d94caffSDavid Greenman 106df8bae1dSRodney W. Grimes /* 107df8bae1dSRodney W. Grimes * Flags 108df8bae1dSRodney W. Grimes */ 109df8bae1dSRodney W. Grimes #define OBJ_CANPERSIST 0x0001 /* allow to persist */ 110df8bae1dSRodney W. Grimes #define OBJ_INTERNAL 0x0002 /* internally created object */ 111df8bae1dSRodney W. Grimes #define OBJ_ACTIVE 0x0004 /* used to mark active objects */ 1120d94caffSDavid Greenman #define OBJ_DEAD 0x0008 /* used to mark dead objects during rundown */ 1130d94caffSDavid Greenman #define OBJ_ILOCKED 0x0010 /* lock from modification */ 1140d94caffSDavid Greenman #define OBJ_ILOCKWT 0x0020 /* wait for lock from modification */ 115df8bae1dSRodney W. Grimes 116df8bae1dSRodney W. Grimes TAILQ_HEAD(vm_object_hash_head, vm_object_hash_entry); 117df8bae1dSRodney W. Grimes 118df8bae1dSRodney W. Grimes struct vm_object_hash_entry { 119df8bae1dSRodney W. Grimes TAILQ_ENTRY(vm_object_hash_entry) hash_links; /* hash chain links */ 120df8bae1dSRodney W. Grimes vm_object_t object; /* object represened */ 121df8bae1dSRodney W. Grimes }; 122df8bae1dSRodney W. Grimes 123df8bae1dSRodney W. Grimes typedef struct vm_object_hash_entry *vm_object_hash_entry_t; 124df8bae1dSRodney W. Grimes 125df8bae1dSRodney W. Grimes #ifdef KERNEL 126df8bae1dSRodney W. Grimes TAILQ_HEAD(object_q, vm_object); 127df8bae1dSRodney W. Grimes 128df8bae1dSRodney W. Grimes struct object_q vm_object_cached_list; /* list of objects persisting */ 129df8bae1dSRodney W. Grimes int vm_object_cached; /* size of cached list */ 130df8bae1dSRodney W. Grimes simple_lock_data_t vm_cache_lock; /* lock for object cache */ 131df8bae1dSRodney W. Grimes 132df8bae1dSRodney W. Grimes struct object_q vm_object_list; /* list of allocated objects */ 133df8bae1dSRodney W. Grimes long vm_object_count; /* count of all objects */ 134df8bae1dSRodney W. Grimes simple_lock_data_t vm_object_list_lock; 1350d94caffSDavid Greenman 136df8bae1dSRodney W. Grimes /* lock for object list and count */ 137df8bae1dSRodney W. Grimes 138df8bae1dSRodney W. Grimes vm_object_t kernel_object; /* the single kernel object */ 139df8bae1dSRodney W. Grimes vm_object_t kmem_object; 140df8bae1dSRodney W. Grimes 141df8bae1dSRodney W. Grimes #define vm_object_cache_lock() simple_lock(&vm_cache_lock) 142df8bae1dSRodney W. Grimes #define vm_object_cache_unlock() simple_unlock(&vm_cache_lock) 143df8bae1dSRodney W. Grimes #endif /* KERNEL */ 144df8bae1dSRodney W. Grimes 1450d94caffSDavid Greenman #define vm_object_sleep(event, object, interruptible) \ 1460d94caffSDavid Greenman thread_sleep((event), &(object)->Lock, (interruptible)) 1470d94caffSDavid Greenman #if 0 148df8bae1dSRodney W. Grimes #define vm_object_lock_init(object) simple_lock_init(&(object)->Lock) 149df8bae1dSRodney W. Grimes #define vm_object_lock(object) simple_lock(&(object)->Lock) 150df8bae1dSRodney W. Grimes #define vm_object_unlock(object) simple_unlock(&(object)->Lock) 151df8bae1dSRodney W. Grimes #define vm_object_lock_try(object) simple_lock_try(&(object)->Lock) 1520d94caffSDavid Greenman #endif 1530d94caffSDavid Greenman #define vm_object_lock_init(object) (object->flags &= ~OBJ_ILOCKED, object->lock.recursion = 0, object->lock.proc = 0) 1540d94caffSDavid Greenman 1550d94caffSDavid Greenman static __inline void 1560d94caffSDavid Greenman vm_object_lock(vm_object_t obj) 1570d94caffSDavid Greenman { 1580d94caffSDavid Greenman if (obj->flags & OBJ_ILOCKED) { 1590d94caffSDavid Greenman ++obj->lock.recursion; 1600d94caffSDavid Greenman return; 1610d94caffSDavid Greenman } 1620d94caffSDavid Greenman obj->flags |= OBJ_ILOCKED; 1630d94caffSDavid Greenman obj->lock.recursion = 1; 1640d94caffSDavid Greenman } 1650d94caffSDavid Greenman 1660d94caffSDavid Greenman static __inline void 1670d94caffSDavid Greenman vm_object_unlock(vm_object_t obj) 1680d94caffSDavid Greenman { 1690d94caffSDavid Greenman --obj->lock.recursion; 1700d94caffSDavid Greenman if (obj->lock.recursion != 0) 1710d94caffSDavid Greenman return; 1720d94caffSDavid Greenman obj->flags &= ~OBJ_ILOCKED; 1730d94caffSDavid Greenman } 1740d94caffSDavid Greenman 1750d94caffSDavid Greenman static __inline int 1760d94caffSDavid Greenman vm_object_lock_try(vm_object_t obj) 1770d94caffSDavid Greenman { 1780d94caffSDavid Greenman if (obj->flags & OBJ_ILOCKED) { 1790d94caffSDavid Greenman ++obj->lock.recursion; 1800d94caffSDavid Greenman return 1; 1810d94caffSDavid Greenman } 1820d94caffSDavid Greenman obj->flags |= OBJ_ILOCKED; 1830d94caffSDavid Greenman obj->lock.recursion = 1; 1840d94caffSDavid Greenman return 1; 1850d94caffSDavid Greenman } 186df8bae1dSRodney W. Grimes 187df8bae1dSRodney W. Grimes #ifdef KERNEL 188df8bae1dSRodney W. Grimes vm_object_t vm_object_allocate __P((vm_size_t)); 189df8bae1dSRodney W. Grimes void vm_object_cache_clear __P((void)); 190df8bae1dSRodney W. Grimes void vm_object_cache_trim __P((void)); 1910d94caffSDavid Greenman boolean_t vm_object_coalesce __P((vm_object_t, vm_object_t, vm_offset_t, vm_offset_t, vm_offset_t, vm_size_t)); 192df8bae1dSRodney W. Grimes void vm_object_collapse __P((vm_object_t)); 1930d94caffSDavid Greenman void vm_object_copy __P((vm_object_t, vm_offset_t, vm_size_t, vm_object_t *, vm_offset_t *, boolean_t *)); 194df8bae1dSRodney W. Grimes void vm_object_deactivate_pages __P((vm_object_t)); 195df8bae1dSRodney W. Grimes void vm_object_deallocate __P((vm_object_t)); 196df8bae1dSRodney W. Grimes void vm_object_enter __P((vm_object_t, vm_pager_t)); 197df8bae1dSRodney W. Grimes void vm_object_init __P((vm_size_t)); 198df8bae1dSRodney W. Grimes vm_object_t vm_object_lookup __P((vm_pager_t)); 1990d94caffSDavid Greenman boolean_t vm_object_page_clean __P((vm_object_t, vm_offset_t, vm_offset_t, boolean_t, boolean_t)); 2000d94caffSDavid Greenman void vm_object_page_remove __P((vm_object_t, vm_offset_t, vm_offset_t)); 2010d94caffSDavid Greenman void vm_object_pmap_copy __P((vm_object_t, vm_offset_t, vm_offset_t)); 2020d94caffSDavid Greenman void vm_object_pmap_remove __P((vm_object_t, vm_offset_t, vm_offset_t)); 203df8bae1dSRodney W. Grimes void vm_object_print __P((vm_object_t, boolean_t)); 204df8bae1dSRodney W. Grimes void vm_object_reference __P((vm_object_t)); 205df8bae1dSRodney W. Grimes void vm_object_remove __P((vm_pager_t)); 2060d94caffSDavid Greenman void vm_object_setpager __P((vm_object_t, vm_pager_t, vm_offset_t, boolean_t)); 2070d94caffSDavid Greenman void vm_object_shadow __P((vm_object_t *, vm_offset_t *, vm_size_t)); 208df8bae1dSRodney W. Grimes void vm_object_terminate __P((vm_object_t)); 2090d94caffSDavid Greenman 210df8bae1dSRodney W. Grimes #endif 211df8bae1dSRodney W. Grimes #endif /* _VM_OBJECT_ */ 212