160727d8bSWarner Losh /*- 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 * 4. Neither the name of the University nor the names of its contributors 17df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 18df8bae1dSRodney W. Grimes * without specific prior written permission. 19df8bae1dSRodney W. Grimes * 20df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30df8bae1dSRodney W. Grimes * SUCH DAMAGE. 31df8bae1dSRodney W. Grimes * 323c4dd356SDavid Greenman * from: @(#)vm_object.h 8.3 (Berkeley) 1/12/94 33df8bae1dSRodney W. Grimes * 34df8bae1dSRodney W. Grimes * 35df8bae1dSRodney W. Grimes * Copyright (c) 1987, 1990 Carnegie-Mellon University. 36df8bae1dSRodney W. Grimes * All rights reserved. 37df8bae1dSRodney W. Grimes * 38df8bae1dSRodney W. Grimes * Authors: Avadis Tevanian, Jr., Michael Wayne Young 39df8bae1dSRodney W. Grimes * 40df8bae1dSRodney W. Grimes * Permission to use, copy, modify and distribute this software and 41df8bae1dSRodney W. Grimes * its documentation is hereby granted, provided that both the copyright 42df8bae1dSRodney W. Grimes * notice and this permission notice appear in all copies of the 43df8bae1dSRodney W. Grimes * software, derivative works or modified versions, and any portions 44df8bae1dSRodney W. Grimes * thereof, and that both notices appear in supporting documentation. 45df8bae1dSRodney W. Grimes * 46df8bae1dSRodney W. Grimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 47df8bae1dSRodney W. Grimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 48df8bae1dSRodney W. Grimes * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 49df8bae1dSRodney W. Grimes * 50df8bae1dSRodney W. Grimes * Carnegie Mellon requests users of this software to return to 51df8bae1dSRodney W. Grimes * 52df8bae1dSRodney W. Grimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 53df8bae1dSRodney W. Grimes * School of Computer Science 54df8bae1dSRodney W. Grimes * Carnegie Mellon University 55df8bae1dSRodney W. Grimes * Pittsburgh PA 15213-3890 56df8bae1dSRodney W. Grimes * 57df8bae1dSRodney W. Grimes * any improvements or extensions that they make and grant Carnegie the 58df8bae1dSRodney W. Grimes * rights to redistribute these changes. 593c4dd356SDavid Greenman * 60c3aac50fSPeter Wemm * $FreeBSD$ 61df8bae1dSRodney W. Grimes */ 62df8bae1dSRodney W. Grimes 63df8bae1dSRodney W. Grimes /* 64df8bae1dSRodney W. Grimes * Virtual memory object module definitions. 65df8bae1dSRodney W. Grimes */ 66df8bae1dSRodney W. Grimes 67df8bae1dSRodney W. Grimes #ifndef _VM_OBJECT_ 68df8bae1dSRodney W. Grimes #define _VM_OBJECT_ 69df8bae1dSRodney W. Grimes 70aad9af2bSBruce Evans #include <sys/queue.h> 714b420d50SAlan Cox #include <sys/_lock.h> 724b420d50SAlan Cox #include <sys/_mutex.h> 73b5e8ce9fSBruce Evans 74df8bae1dSRodney W. Grimes /* 75df8bae1dSRodney W. Grimes * Types defined: 76df8bae1dSRodney W. Grimes * 77df8bae1dSRodney W. Grimes * vm_object_t Virtual memory object. 781c7c3c6aSMatthew Dillon * 79ffdd0c7dSAttilio Rao * The root of cached pages pool is protected by both the per-object mutex 80ffdd0c7dSAttilio Rao * and the free pages queue mutex. 81ffdd0c7dSAttilio Rao * On insert in the cache splay tree, the per-object mutex is expected 82ffdd0c7dSAttilio Rao * to be already held and the free pages queue mutex will be 83ffdd0c7dSAttilio Rao * acquired during the operation too. 84ffdd0c7dSAttilio Rao * On remove and lookup from the cache splay tree, only the free 85ffdd0c7dSAttilio Rao * pages queue mutex is expected to be locked. 86ffdd0c7dSAttilio Rao * These rules allow for reliably checking for the presence of cached 87ffdd0c7dSAttilio Rao * pages with only the per-object lock held, thereby reducing contention 88ffdd0c7dSAttilio Rao * for the free pages queue mutex. 89ffdd0c7dSAttilio Rao * 9079660d83SAlan Cox * List of locks 9179660d83SAlan Cox * (c) const until freed 92ffdd0c7dSAttilio Rao * (o) per-object mutex 93ffdd0c7dSAttilio Rao * (f) free pages queue mutex 9479660d83SAlan Cox * 95df8bae1dSRodney W. Grimes */ 96df8bae1dSRodney W. Grimes 97df8bae1dSRodney W. Grimes struct vm_object { 984b420d50SAlan Cox struct mtx mtx; 99e3975643SJake Burkholder TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ 1001c500307SAlan Cox LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */ 1011c500307SAlan Cox LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */ 102e3975643SJake Burkholder TAILQ_HEAD(, vm_page) memq; /* list of resident pages */ 103b86ec922SMatthew Dillon vm_page_t root; /* root of the resident page splay tree */ 1046395da54SIan Dowse vm_pindex_t size; /* Object size */ 105c759a3caSAlan Cox int generation; /* generation ID */ 106df8bae1dSRodney W. Grimes int ref_count; /* How many refs?? */ 107de5f6a77SJohn Dyson int shadow_count; /* how many objects that this is a shadow for */ 1083153e878SAlan Cox vm_memattr_t memattr; /* default memory attribute for pages */ 1096877f580SAlan Cox objtype_t type; /* type of pager */ 110a1f6d91cSDavid Greenman u_short flags; /* see below */ 11179660d83SAlan Cox u_short pg_color; /* (c) color of first page in obj */ 1125dda2db9SKonstantin Belousov u_int paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ 113a1f6d91cSDavid Greenman int resident_page_count; /* number of resident pages */ 11424a1cce3SDavid Greenman struct vm_object *backing_object; /* object that I'm a shadow of */ 115a316d390SJohn Dyson vm_ooffset_t backing_object_offset;/* Offset in backing object */ 116e3975643SJake Burkholder TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */ 1173df92083SAlan Cox LIST_HEAD(, vm_reserv) rvq; /* list of reservations */ 118ffdd0c7dSAttilio Rao vm_page_t cache; /* (o + f) root of the cache page splay tree */ 11924a1cce3SDavid Greenman void *handle; 12024a1cce3SDavid Greenman union { 1211c7c3c6aSMatthew Dillon /* 1221c7c3c6aSMatthew Dillon * VNode pager 1231c7c3c6aSMatthew Dillon * 1241c7c3c6aSMatthew Dillon * vnp_size - current size of file 1251c7c3c6aSMatthew Dillon */ 12624a1cce3SDavid Greenman struct { 1271c7c3c6aSMatthew Dillon off_t vnp_size; 12884110e7eSKonstantin Belousov vm_ooffset_t writemappings; 12924a1cce3SDavid Greenman } vnp; 1301c7c3c6aSMatthew Dillon 1311c7c3c6aSMatthew Dillon /* 1321c7c3c6aSMatthew Dillon * Device pager 1331c7c3c6aSMatthew Dillon * 1341c7c3c6aSMatthew Dillon * devp_pglist - list of allocated pages 1351c7c3c6aSMatthew Dillon */ 13624a1cce3SDavid Greenman struct { 137e3975643SJake Burkholder TAILQ_HEAD(, vm_page) devp_pglist; 138286790a7SKonstantin Belousov struct cdev_pager_ops *ops; 13943ab9660SKenneth D. Merry struct cdev *dev; 14024a1cce3SDavid Greenman } devp; 1411c7c3c6aSMatthew Dillon 14224964514SPeter Wemm /* 14301381811SJohn Baldwin * SG pager 14401381811SJohn Baldwin * 14501381811SJohn Baldwin * sgp_pglist - list of allocated pages 14601381811SJohn Baldwin */ 14701381811SJohn Baldwin struct { 14801381811SJohn Baldwin TAILQ_HEAD(, vm_page) sgp_pglist; 14901381811SJohn Baldwin } sgp; 15001381811SJohn Baldwin 15101381811SJohn Baldwin /* 1521c7c3c6aSMatthew Dillon * Swap pager 1531c7c3c6aSMatthew Dillon * 1541c7c3c6aSMatthew Dillon * swp_bcount - number of swap 'swblock' metablocks, each 1551c7c3c6aSMatthew Dillon * contains up to 16 swapblk assignments. 1561c7c3c6aSMatthew Dillon * see vm/swap_pager.h 1571c7c3c6aSMatthew Dillon */ 1582a4895f4SDavid Greenman struct { 1591c7c3c6aSMatthew Dillon int swp_bcount; 1602a4895f4SDavid Greenman } swp; 16124a1cce3SDavid Greenman } un_pager; 162ef694c1aSEdward Tomasz Napierala struct ucred *cred; 1633364c323SKonstantin Belousov vm_ooffset_t charge; 164df8bae1dSRodney W. Grimes }; 1650d94caffSDavid Greenman 166df8bae1dSRodney W. Grimes /* 167df8bae1dSRodney W. Grimes * Flags 168df8bae1dSRodney W. Grimes */ 16928634820SAlan Cox #define OBJ_FICTITIOUS 0x0001 /* (c) contains fictitious pages */ 17028634820SAlan Cox #define OBJ_UNMANAGED 0x0002 /* (c) contains unmanaged pages */ 17124a1cce3SDavid Greenman #define OBJ_ACTIVE 0x0004 /* active objects */ 17224a1cce3SDavid Greenman #define OBJ_DEAD 0x0008 /* dead objects (during rundown) */ 17396fb8cf2SJohn Dyson #define OBJ_NOSPLIT 0x0010 /* dont split this object */ 174c0503609SDavid Greenman #define OBJ_PIPWNT 0x0040 /* paging in progress wanted */ 17549e3050eSKonstantin Belousov #define OBJ_MIGHTBEDIRTY 0x0100 /* object might be dirty, only for vnode */ 1763df92083SAlan Cox #define OBJ_COLORED 0x1000 /* pg_color is defined */ 177c0877f10SJohn Dyson #define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */ 17819187819SAlan Cox #define OBJ_DISCONNECTWNT 0x4000 /* disconnect from vnode wanted */ 1791efb74fbSJohn Dyson 180a316d390SJohn Dyson #define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT) 181a316d390SJohn Dyson #define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT)) 182df8bae1dSRodney W. Grimes 183c4473420SPeter Wemm #ifdef _KERNEL 184b5e8ce9fSBruce Evans 1858f9110f6SJohn Dyson #define OBJPC_SYNC 0x1 /* sync I/O */ 1868f9110f6SJohn Dyson #define OBJPC_INVAL 0x2 /* invalidate */ 1874f79d873SMatthew Dillon #define OBJPC_NOSYNC 0x4 /* skip if PG_NOSYNC */ 1888f9110f6SJohn Dyson 1896bbee8e2SAlan Cox /* 1906bbee8e2SAlan Cox * The following options are supported by vm_object_page_remove(). 1916bbee8e2SAlan Cox */ 1926bbee8e2SAlan Cox #define OBJPR_CLEANONLY 0x1 /* Don't remove dirty pages. */ 1936bbee8e2SAlan Cox #define OBJPR_NOTMAPPED 0x2 /* Don't unmap pages. */ 1946bbee8e2SAlan Cox 195e3975643SJake Burkholder TAILQ_HEAD(object_q, vm_object); 196df8bae1dSRodney W. Grimes 19728f8db14SBruce Evans extern struct object_q vm_object_list; /* list of allocated objects */ 198a5698387SAlan Cox extern struct mtx vm_object_list_mtx; /* lock for object list and count */ 1990d94caffSDavid Greenman 200cccf11b8SAlan Cox extern struct vm_object kernel_object_store; 201cccf11b8SAlan Cox extern struct vm_object kmem_object_store; 202cccf11b8SAlan Cox 203cccf11b8SAlan Cox #define kernel_object (&kernel_object_store) 204cccf11b8SAlan Cox #define kmem_object (&kmem_object_store) 205df8bae1dSRodney W. Grimes 206fdff4160SAlan Cox #define VM_OBJECT_LOCK(object) mtx_lock(&(object)->mtx) 2070d420ad3SAlan Cox #define VM_OBJECT_LOCK_ASSERT(object, type) \ 2080d420ad3SAlan Cox mtx_assert(&(object)->mtx, (type)) 2095285558aSAlan Cox #define VM_OBJECT_LOCK_INIT(object, type) \ 2105285558aSAlan Cox mtx_init(&(object)->mtx, "vm object", \ 2115285558aSAlan Cox (type), MTX_DEF | MTX_DUPOK) 2121c067f7eSAlan Cox #define VM_OBJECT_LOCKED(object) mtx_owned(&(object)->mtx) 213*0dde287bSAttilio Rao #define VM_OBJECT_SLEEP(object, wchan, pri, wmesg, timo) \ 214*0dde287bSAttilio Rao msleep((wchan), &(object)->mtx, (pri), \ 215*0dde287bSAttilio Rao (wmesg), (timo)) 216bc73ee3fSAlan Cox #define VM_OBJECT_TRYLOCK(object) mtx_trylock(&(object)->mtx) 217fdff4160SAlan Cox #define VM_OBJECT_UNLOCK(object) mtx_unlock(&(object)->mtx) 218fdff4160SAlan Cox 2193b9a4cb6SAlan Cox /* 2203b9a4cb6SAlan Cox * The object must be locked or thread private. 2213b9a4cb6SAlan Cox */ 2223b9a4cb6SAlan Cox static __inline void 2233b9a4cb6SAlan Cox vm_object_set_flag(vm_object_t object, u_short bits) 2243b9a4cb6SAlan Cox { 2253b9a4cb6SAlan Cox 2263b9a4cb6SAlan Cox object->flags |= bits; 2273b9a4cb6SAlan Cox } 2283b9a4cb6SAlan Cox 2291b40f8c0SMatthew Dillon void vm_object_clear_flag(vm_object_t object, u_short bits); 2301b40f8c0SMatthew Dillon void vm_object_pip_add(vm_object_t object, short i); 2311b40f8c0SMatthew Dillon void vm_object_pip_subtract(vm_object_t object, short i); 2321b40f8c0SMatthew Dillon void vm_object_pip_wakeup(vm_object_t object); 2331b40f8c0SMatthew Dillon void vm_object_pip_wakeupn(vm_object_t object, short i); 2341b40f8c0SMatthew Dillon void vm_object_pip_wait(vm_object_t object, char *waitid); 235069e9bc1SDoug Rabson 2366395da54SIan Dowse vm_object_t vm_object_allocate (objtype_t, vm_pindex_t); 2376395da54SIan Dowse void _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t); 2383364c323SKonstantin Belousov boolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t, 2393364c323SKonstantin Belousov boolean_t); 2401b40f8c0SMatthew Dillon void vm_object_collapse (vm_object_t); 2411b40f8c0SMatthew Dillon void vm_object_deallocate (vm_object_t); 2422ac78f0eSStephan Uphoff void vm_object_destroy (vm_object_t); 2431b40f8c0SMatthew Dillon void vm_object_terminate (vm_object_t); 244245df27cSMatthew Dillon void vm_object_set_writeable_dirty (vm_object_t); 2451b40f8c0SMatthew Dillon void vm_object_init (void); 24692a59946SJohn Baldwin void vm_object_madvise(vm_object_t, vm_pindex_t, vm_pindex_t, int); 247936c09acSJohn Baldwin void vm_object_page_cache(vm_object_t object, vm_pindex_t start, 248936c09acSJohn Baldwin vm_pindex_t end); 249126d6082SKonstantin Belousov boolean_t vm_object_page_clean(vm_object_t object, vm_ooffset_t start, 25017f3095dSAlan Cox vm_ooffset_t end, int flags); 2516bbee8e2SAlan Cox void vm_object_page_remove(vm_object_t object, vm_pindex_t start, 2526bbee8e2SAlan Cox vm_pindex_t end, int options); 253387aabc5SAlan Cox boolean_t vm_object_populate(vm_object_t, vm_pindex_t, vm_pindex_t); 2544de22619SAlan Cox void vm_object_print(long addr, boolean_t have_addr, long count, char *modif); 2551b40f8c0SMatthew Dillon void vm_object_reference (vm_object_t); 256b921a12bSAlan Cox void vm_object_reference_locked(vm_object_t); 2573153e878SAlan Cox int vm_object_set_memattr(vm_object_t object, vm_memattr_t memattr); 2581b40f8c0SMatthew Dillon void vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); 259c5aaa06dSAlan Cox void vm_object_split(vm_map_entry_t); 260126d6082SKonstantin Belousov boolean_t vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t, 261950f8459SAlan Cox boolean_t); 262c4473420SPeter Wemm #endif /* _KERNEL */ 2630d94caffSDavid Greenman 264df8bae1dSRodney W. Grimes #endif /* _VM_OBJECT_ */ 265