vm_object.h revision 218345
14Srgrimes/*- 24Srgrimes * Copyright (c) 1991, 1993 34Srgrimes * The Regents of the University of California. All rights reserved. 44Srgrimes * 54Srgrimes * This code is derived from software contributed to Berkeley by 64Srgrimes * The Mach Operating System project at Carnegie-Mellon University. 74Srgrimes * 84Srgrimes * Redistribution and use in source and binary forms, with or without 94Srgrimes * modification, are permitted provided that the following conditions 104Srgrimes * are met: 114Srgrimes * 1. Redistributions of source code must retain the above copyright 124Srgrimes * notice, this list of conditions and the following disclaimer. 134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 144Srgrimes * notice, this list of conditions and the following disclaimer in the 154Srgrimes * documentation and/or other materials provided with the distribution. 164Srgrimes * 4. Neither the name of the University nor the names of its contributors 174Srgrimes * may be used to endorse or promote products derived from this software 184Srgrimes * without specific prior written permission. 194Srgrimes * 204Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304Srgrimes * SUCH DAMAGE. 314Srgrimes * 32556Srgrimes * from: @(#)vm_object.h 8.3 (Berkeley) 1/12/94 3350477Speter * 3415392Sphk * 35757Sdg * Copyright (c) 1987, 1990 Carnegie-Mellon University. 36757Sdg * All rights reserved. 37757Sdg * 3815392Sphk * Authors: Avadis Tevanian, Jr., Michael Wayne Young 3915392Sphk * 404Srgrimes * Permission to use, copy, modify and distribute this software and 414Srgrimes * its documentation is hereby granted, provided that both the copyright 42131840Sbrian * notice and this permission notice appear in all copies of the 4390132Sbde * software, derivative works or modified versions, and any portions 4437272Sjmg * thereof, and that both notices appear in supporting documentation. 45120690Speter * 4614835Sbde * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 4714835Sbde * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 485908Sbde * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 494Srgrimes * 5014835Sbde * Carnegie Mellon requests users of this software to return to 5114835Sbde * 5214835Sbde * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 5315543Sphk * School of Computer Science 5414835Sbde * Carnegie Mellon University 5514835Sbde * Pittsburgh PA 15213-3890 5614835Sbde * 5714835Sbde * any improvements or extensions that they make and grant Carnegie the 584Srgrimes * rights to redistribute these changes. 59757Sdg * 60757Sdg * $FreeBSD: head/sys/vm/vm_object.h 218345 2011-02-05 21:21:27Z alc $ 614Srgrimes */ 624Srgrimes 634Srgrimes/* 644Srgrimes * Virtual memory object module definitions. 654Srgrimes */ 66200Sdg 674Srgrimes#ifndef _VM_OBJECT_ 684Srgrimes#define _VM_OBJECT_ 694Srgrimes 7073011Sjake#include <sys/queue.h> 7173011Sjake#include <sys/_lock.h> 7273011Sjake#include <sys/_mutex.h> 7373011Sjake 74592Srgrimes/* 7570928Sjake * Types defined: 764Srgrimes * 7770928Sjake * vm_object_t Virtual memory object. 7870928Sjake * 7970928Sjake * List of locks 8070928Sjake * (c) const until freed 81121986Sjhb * 8273011Sjake */ 8370928Sjake 8470928Sjakestruct vm_object { 8570928Sjake struct mtx mtx; 86120654Speter TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ 8782262Speter LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */ 8882262Speter LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */ 8982262Speter TAILQ_HEAD(, vm_page) memq; /* list of resident pages */ 90120654Speter vm_page_t root; /* root of the resident page splay tree */ 91120654Speter vm_pindex_t size; /* Object size */ 9282262Speter int generation; /* generation ID */ 9382262Speter int ref_count; /* How many refs?? */ 94556Srgrimes int shadow_count; /* how many objects that this is a shadow for */ 95556Srgrimes vm_memattr_t memattr; /* default memory attribute for pages */ 96556Srgrimes objtype_t type; /* type of pager */ 9799741Sobrien u_short flags; /* see below */ 98134Sdg u_short pg_color; /* (c) color of first page in obj */ 9999741Sobrien u_short paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ 100118154Sbde int resident_page_count; /* number of resident pages */ 1013842Sdg struct vm_object *backing_object; /* object that I'm a shadow of */ 10282957Speter vm_ooffset_t backing_object_offset;/* Offset in backing object */ 10399741Sobrien TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */ 1044Srgrimes LIST_HEAD(, vm_reserv) rvq; /* list of reservations */ 10599862Speter vm_page_t cache; /* root of the cache page splay tree */ 10699741Sobrien void *handle; 10799741Sobrien union { 108757Sdg /* 10926812Speter * VNode pager 11073011Sjake * 11199741Sobrien * vnp_size - current size of file 11299741Sobrien */ 11325164Speter struct { 11473011Sjake off_t vnp_size; 11599741Sobrien } vnp; 11699741Sobrien 11726812Speter /* 11825164Speter * Device pager 11973011Sjake * 12099741Sobrien * devp_pglist - list of allocated pages 1213861Sbde */ 122112841Sjake struct { 123112841Sjake TAILQ_HEAD(, vm_page) devp_pglist; 124112841Sjake } devp; 125112841Sjake 126112841Sjake /* 12726812Speter * SG pager 12873011Sjake * 12926812Speter * sgp_pglist - list of allocated pages 13099741Sobrien */ 1314Srgrimes struct { 132137912Sdas TAILQ_HEAD(, vm_page) sgp_pglist; 133137912Sdas } sgp; 13499741Sobrien 135137912Sdas /* 13699741Sobrien * Swap pager 137134Sdg * 13899741Sobrien * swp_bcount - number of swap 'swblock' metablocks, each 13937889Sjlemon * contains up to 16 swapblk assignments. 14073011Sjake * see vm/swap_pager.h 14199741Sobrien */ 14299741Sobrien struct { 14334840Sjlemon int swp_bcount; 14443434Skato } swp; 14573011Sjake } un_pager; 14673011Sjake struct ucred *cred; 14743434Skato vm_ooffset_t charge; 14843434Skato}; 14915428Sphk 15015392Sphk/* 15115392Sphk * Flags 15215392Sphk */ 15315392Sphk#define OBJ_ACTIVE 0x0004 /* active objects */ 154556Srgrimes#define OBJ_DEAD 0x0008 /* dead objects (during rundown) */ 155134Sdg#define OBJ_NOSPLIT 0x0010 /* dont split this object */ 15615392Sphk#define OBJ_PIPWNT 0x0040 /* paging in progress wanted */ 15715392Sphk#define OBJ_MIGHTBEDIRTY 0x0100 /* object might be dirty, only for vnode */ 15815392Sphk#define OBJ_COLORED 0x1000 /* pg_color is defined */ 15915392Sphk#define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */ 16015543Sphk#define OBJ_DISCONNECTWNT 0x4000 /* disconnect from vnode wanted */ 16115392Sphk 16215392Sphk#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT) 16315392Sphk#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT)) 16415543Sphk 16515392Sphk#ifdef _KERNEL 16615428Sphk 16715428Sphk#define OBJPC_SYNC 0x1 /* sync I/O */ 16815428Sphk#define OBJPC_INVAL 0x2 /* invalidate */ 16915392Sphk#define OBJPC_NOSYNC 0x4 /* skip if PG_NOSYNC */ 170134Sdg 17115392SphkTAILQ_HEAD(object_q, vm_object); 17215565Sphk 17315565Sphkextern struct object_q vm_object_list; /* list of allocated objects */ 17415392Sphkextern struct mtx vm_object_list_mtx; /* lock for object list and count */ 17515565Sphk 17615565Sphkextern struct vm_object kernel_object_store; 177134Sdgextern struct vm_object kmem_object_store; 17815565Sphk 179111299Sjake#define kernel_object (&kernel_object_store) 18019621Sdyson#define kmem_object (&kmem_object_store) 18119621Sdyson 18219621Sdyson#define VM_OBJECT_LOCK(object) mtx_lock(&(object)->mtx) 18315565Sphk#define VM_OBJECT_LOCK_ASSERT(object, type) \ 18415565Sphk mtx_assert(&(object)->mtx, (type)) 185111299Sjake#define VM_OBJECT_LOCK_INIT(object, type) \ 18615428Sphk mtx_init(&(object)->mtx, "vm object", \ 18715392Sphk (type), MTX_DEF | MTX_DUPOK) 18815565Sphk#define VM_OBJECT_LOCKED(object) mtx_owned(&(object)->mtx) 18915565Sphk#define VM_OBJECT_MTX(object) (&(object)->mtx) 19015565Sphk#define VM_OBJECT_TRYLOCK(object) mtx_trylock(&(object)->mtx) 19115565Sphk#define VM_OBJECT_UNLOCK(object) mtx_unlock(&(object)->mtx) 19215565Sphk 19315565Sphk/* 19415565Sphk * The object must be locked or thread private. 19515565Sphk */ 19615565Sphkstatic __inline void 19773011Sjakevm_object_set_flag(vm_object_t object, u_short bits) 19815565Sphk{ 19915392Sphk 20015392Sphk object->flags |= bits; 20115392Sphk} 20215392Sphk 20315392Sphkvoid vm_object_clear_flag(vm_object_t object, u_short bits); 20415392Sphkvoid vm_object_pip_add(vm_object_t object, short i); 2051321Sdgvoid vm_object_pip_subtract(vm_object_t object, short i); 2064Srgrimesvoid vm_object_pip_wakeup(vm_object_t object); 20724112Skatovoid vm_object_pip_wakeupn(vm_object_t object, short i); 20824112Skatovoid vm_object_pip_wait(vm_object_t object, char *waitid); 20943434Skato 21073011Sjakevm_object_t vm_object_allocate (objtype_t, vm_pindex_t); 21143434Skatovoid _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t); 21224112Skatoboolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t, 21324112Skato boolean_t); 21424112Skatovoid vm_object_collapse (vm_object_t); 21524112Skatovoid vm_object_deallocate (vm_object_t); 21615392Sphkvoid vm_object_destroy (vm_object_t); 21715392Sphkvoid vm_object_terminate (vm_object_t); 21854128Skatovoid vm_object_set_writeable_dirty (vm_object_t); 21915392Sphkvoid vm_object_init (void); 22015428Sphkvoid vm_object_page_clean(vm_object_t object, vm_ooffset_t start, 2213384Srgrimes vm_ooffset_t end, int flags); 2223384Srgrimesvoid vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); 2233384Srgrimesboolean_t vm_object_populate(vm_object_t, vm_pindex_t, vm_pindex_t); 22415392Sphkvoid vm_object_print(long addr, boolean_t have_addr, long count, char *modif); 2255603Sbdevoid vm_object_reference (vm_object_t); 2262486Sdgvoid vm_object_reference_locked(vm_object_t); 22715428Sphkint vm_object_set_memattr(vm_object_t object, vm_memattr_t memattr); 22815428Sphkvoid vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); 22915428Sphkvoid vm_object_split(vm_map_entry_t); 23015428Sphkvoid vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t, 23115428Sphk boolean_t); 23215428Sphkvoid vm_object_madvise (vm_object_t, vm_pindex_t, int, int); 2334217Sphk#endif /* _KERNEL */ 2344217Sphk 2354217Sphk#endif /* _VM_OBJECT_ */ 236118186Sbde