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 * 64c3aac50fSPeter Wemm * $FreeBSD$ 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 74aad9af2bSBruce Evans #include <sys/queue.h> 754b420d50SAlan Cox #include <sys/_lock.h> 764b420d50SAlan Cox #include <sys/_mutex.h> 77b5e8ce9fSBruce Evans 7824964514SPeter Wemm enum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE, OBJT_PHYS, 7924964514SPeter Wemm OBJT_DEAD }; 806877f580SAlan Cox typedef u_char objtype_t; 81df8bae1dSRodney W. Grimes 82df8bae1dSRodney W. Grimes /* 83df8bae1dSRodney W. Grimes * Types defined: 84df8bae1dSRodney W. Grimes * 85df8bae1dSRodney W. Grimes * vm_object_t Virtual memory object. 861c7c3c6aSMatthew Dillon * 8779660d83SAlan Cox * List of locks 8879660d83SAlan Cox * (c) const until freed 8979660d83SAlan Cox * 90df8bae1dSRodney W. Grimes */ 91df8bae1dSRodney W. Grimes 92df8bae1dSRodney W. Grimes struct vm_object { 934b420d50SAlan Cox struct mtx mtx; 94e3975643SJake Burkholder TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ 95e3975643SJake Burkholder TAILQ_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */ 96e3975643SJake Burkholder TAILQ_ENTRY(vm_object) shadow_list; /* chain of shadow objects */ 97e3975643SJake Burkholder TAILQ_HEAD(, vm_page) memq; /* list of resident pages */ 98b86ec922SMatthew Dillon vm_page_t root; /* root of the resident page splay tree */ 992d8acc0fSJohn Dyson int generation; /* generation ID */ 1006395da54SIan Dowse vm_pindex_t size; /* Object size */ 101df8bae1dSRodney W. Grimes int ref_count; /* How many refs?? */ 102de5f6a77SJohn Dyson int shadow_count; /* how many objects that this is a shadow for */ 1036877f580SAlan Cox objtype_t type; /* type of pager */ 104a1f6d91cSDavid Greenman u_short flags; /* see below */ 10579660d83SAlan Cox u_short pg_color; /* (c) color of first page in obj */ 106a1f6d91cSDavid Greenman u_short paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ 107a1f6d91cSDavid Greenman int resident_page_count; /* number of resident pages */ 10824a1cce3SDavid Greenman struct vm_object *backing_object; /* object that I'm a shadow of */ 109a316d390SJohn Dyson vm_ooffset_t backing_object_offset;/* Offset in backing object */ 110e3975643SJake Burkholder TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */ 11124a1cce3SDavid Greenman void *handle; 11224a1cce3SDavid Greenman union { 1131c7c3c6aSMatthew Dillon /* 1141c7c3c6aSMatthew Dillon * VNode pager 1151c7c3c6aSMatthew Dillon * 1161c7c3c6aSMatthew Dillon * vnp_size - current size of file 1171c7c3c6aSMatthew Dillon */ 11824a1cce3SDavid Greenman struct { 1191c7c3c6aSMatthew Dillon off_t vnp_size; 12024a1cce3SDavid Greenman } vnp; 1211c7c3c6aSMatthew Dillon 1221c7c3c6aSMatthew Dillon /* 1231c7c3c6aSMatthew Dillon * Device pager 1241c7c3c6aSMatthew Dillon * 1251c7c3c6aSMatthew Dillon * devp_pglist - list of allocated pages 1261c7c3c6aSMatthew Dillon */ 12724a1cce3SDavid Greenman struct { 128e3975643SJake Burkholder TAILQ_HEAD(, vm_page) devp_pglist; 12924a1cce3SDavid Greenman } devp; 1301c7c3c6aSMatthew Dillon 13124964514SPeter Wemm /* 1321c7c3c6aSMatthew Dillon * Swap pager 1331c7c3c6aSMatthew Dillon * 1341c7c3c6aSMatthew Dillon * swp_bcount - number of swap 'swblock' metablocks, each 1351c7c3c6aSMatthew Dillon * contains up to 16 swapblk assignments. 1361c7c3c6aSMatthew Dillon * see vm/swap_pager.h 1371c7c3c6aSMatthew Dillon */ 1382a4895f4SDavid Greenman struct { 1391c7c3c6aSMatthew Dillon int swp_bcount; 1402a4895f4SDavid Greenman } swp; 14124a1cce3SDavid Greenman } un_pager; 142df8bae1dSRodney W. Grimes }; 1430d94caffSDavid Greenman 144df8bae1dSRodney W. Grimes /* 145df8bae1dSRodney W. Grimes * Flags 146df8bae1dSRodney W. Grimes */ 14724a1cce3SDavid Greenman #define OBJ_ACTIVE 0x0004 /* active objects */ 14824a1cce3SDavid Greenman #define OBJ_DEAD 0x0008 /* dead objects (during rundown) */ 14996fb8cf2SJohn Dyson #define OBJ_NOSPLIT 0x0010 /* dont split this object */ 150c0503609SDavid Greenman #define OBJ_PIPWNT 0x0040 /* paging in progress wanted */ 15124a1cce3SDavid Greenman #define OBJ_WRITEABLE 0x0080 /* object has been made writable */ 152aef922f5SJohn Dyson #define OBJ_MIGHTBEDIRTY 0x0100 /* object might be dirty */ 153aef922f5SJohn Dyson #define OBJ_CLEANING 0x0200 1541efb74fbSJohn Dyson #define OBJ_OPT 0x1000 /* I/O optimization */ 155c0877f10SJohn Dyson #define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */ 1561efb74fbSJohn Dyson 157a316d390SJohn Dyson #define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT) 158a316d390SJohn Dyson #define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT)) 159df8bae1dSRodney W. Grimes 160c4473420SPeter Wemm #ifdef _KERNEL 161b5e8ce9fSBruce Evans 1628f9110f6SJohn Dyson #define OBJPC_SYNC 0x1 /* sync I/O */ 1638f9110f6SJohn Dyson #define OBJPC_INVAL 0x2 /* invalidate */ 1644f79d873SMatthew Dillon #define OBJPC_NOSYNC 0x4 /* skip if PG_NOSYNC */ 1658f9110f6SJohn Dyson 166e3975643SJake Burkholder TAILQ_HEAD(object_q, vm_object); 167df8bae1dSRodney W. Grimes 16828f8db14SBruce Evans extern struct object_q vm_object_list; /* list of allocated objects */ 169a5698387SAlan Cox extern struct mtx vm_object_list_mtx; /* lock for object list and count */ 1700d94caffSDavid Greenman 17128f8db14SBruce Evans extern vm_object_t kernel_object; /* the single kernel object */ 17228f8db14SBruce Evans extern vm_object_t kmem_object; 173df8bae1dSRodney W. Grimes 174c4473420SPeter Wemm #endif /* _KERNEL */ 175df8bae1dSRodney W. Grimes 176c4473420SPeter Wemm #ifdef _KERNEL 1774b420d50SAlan Cox #define vm_object_lock(object) \ 1784b420d50SAlan Cox mtx_lock((object) == kmem_object ? &kmem_object->mtx : &Giant) 1794b420d50SAlan Cox #define vm_object_unlock(object) \ 1804b420d50SAlan Cox mtx_unlock((object) == kmem_object ? &kmem_object->mtx : &Giant) 181d52bc343SAlan Cox 182e86256c1SAlan Cox void vm_freeze_copyopts(vm_object_t, vm_pindex_t, vm_pindex_t); 183d474eaaaSDoug Rabson 1841b40f8c0SMatthew Dillon void vm_object_set_flag(vm_object_t object, u_short bits); 1851b40f8c0SMatthew Dillon void vm_object_clear_flag(vm_object_t object, u_short bits); 1861b40f8c0SMatthew Dillon void vm_object_pip_add(vm_object_t object, short i); 1871b40f8c0SMatthew Dillon void vm_object_pip_subtract(vm_object_t object, short i); 1881b40f8c0SMatthew Dillon void vm_object_pip_wakeup(vm_object_t object); 1891b40f8c0SMatthew Dillon void vm_object_pip_wakeupn(vm_object_t object, short i); 1901b40f8c0SMatthew Dillon void vm_object_pip_sleep(vm_object_t object, char *waitid); 1911b40f8c0SMatthew Dillon void vm_object_pip_wait(vm_object_t object, char *waitid); 192069e9bc1SDoug Rabson 1936395da54SIan Dowse vm_object_t vm_object_allocate (objtype_t, vm_pindex_t); 19498cb733cSKenneth D. Merry vm_object_t vm_object_allocate_wait (objtype_t, vm_pindex_t, int); 1956395da54SIan Dowse void _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t); 1961b40f8c0SMatthew Dillon boolean_t vm_object_coalesce (vm_object_t, vm_pindex_t, vm_size_t, vm_size_t); 1971b40f8c0SMatthew Dillon void vm_object_collapse (vm_object_t); 1981b40f8c0SMatthew Dillon void vm_object_deallocate (vm_object_t); 1991b40f8c0SMatthew Dillon void vm_object_terminate (vm_object_t); 2001b40f8c0SMatthew Dillon void vm_object_vndeallocate (vm_object_t); 201245df27cSMatthew Dillon void vm_object_set_writeable_dirty (vm_object_t); 2021b40f8c0SMatthew Dillon void vm_object_init (void); 2031b40f8c0SMatthew Dillon void vm_object_page_clean (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); 2041b40f8c0SMatthew Dillon void vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); 2051b40f8c0SMatthew Dillon void vm_object_pmap_copy_1 (vm_object_t, vm_pindex_t, vm_pindex_t); 2061b40f8c0SMatthew Dillon void vm_object_reference (vm_object_t); 2071b40f8c0SMatthew Dillon void vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); 208c5aaa06dSAlan Cox void vm_object_split(vm_map_entry_t); 2091b40f8c0SMatthew Dillon void vm_object_madvise (vm_object_t, vm_pindex_t, int, int); 2101b40f8c0SMatthew Dillon void vm_object_init2 (void); 211c4473420SPeter Wemm #endif /* _KERNEL */ 2120d94caffSDavid Greenman 213df8bae1dSRodney W. Grimes #endif /* _VM_OBJECT_ */ 214