vm_object.h revision 229383
159024Sobrien/*- 277298Sobrien * Copyright (c) 1991, 1993 359024Sobrien * The Regents of the University of California. All rights reserved. 459024Sobrien * 559024Sobrien * This code is derived from software contributed to Berkeley by 659024Sobrien * The Mach Operating System project at Carnegie-Mellon University. 759024Sobrien * 859024Sobrien * Redistribution and use in source and binary forms, with or without 959024Sobrien * modification, are permitted provided that the following conditions 1059024Sobrien * are met: 1159024Sobrien * 1. Redistributions of source code must retain the above copyright 1259024Sobrien * notice, this list of conditions and the following disclaimer. 1359024Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1459024Sobrien * notice, this list of conditions and the following disclaimer in the 1559024Sobrien * documentation and/or other materials provided with the distribution. 1659024Sobrien * 4. Neither the name of the University nor the names of its contributors 1759024Sobrien * may be used to endorse or promote products derived from this software 1859024Sobrien * without specific prior written permission. 1959024Sobrien * 2059024Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2159024Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2259024Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2359024Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2459024Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2559024Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2659024Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2760484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2859024Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2959024Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3059024Sobrien * SUCH DAMAGE. 3159024Sobrien * 3259024Sobrien * from: @(#)vm_object.h 8.3 (Berkeley) 1/12/94 3359024Sobrien * 3459024Sobrien * 3559024Sobrien * Copyright (c) 1987, 1990 Carnegie-Mellon University. 3659024Sobrien * All rights reserved. 3759024Sobrien * 3877298Sobrien * Authors: Avadis Tevanian, Jr., Michael Wayne Young 3959024Sobrien * 4059024Sobrien * Permission to use, copy, modify and distribute this software and 4159024Sobrien * its documentation is hereby granted, provided that both the copyright 4259024Sobrien * notice and this permission notice appear in all copies of the 4377298Sobrien * software, derivative works or modified versions, and any portions 4459024Sobrien * thereof, and that both notices appear in supporting documentation. 4559024Sobrien * 4677298Sobrien * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 4759024Sobrien * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 4877298Sobrien * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 4959024Sobrien * 5059024Sobrien * Carnegie Mellon requests users of this software to return to 5159024Sobrien * 5259024Sobrien * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 5359024Sobrien * School of Computer Science 5459024Sobrien * Carnegie Mellon University 5577298Sobrien * Pittsburgh PA 15213-3890 5677298Sobrien * 5759024Sobrien * any improvements or extensions that they make and grant Carnegie the 5859024Sobrien * rights to redistribute these changes. 5977298Sobrien * 6077298Sobrien * $FreeBSD: stable/9/sys/vm/vm_object.h 229383 2012-01-03 10:36:38Z kib $ 6177298Sobrien */ 6259024Sobrien 6359024Sobrien/* 6459024Sobrien * Virtual memory object module definitions. 6559024Sobrien */ 6659024Sobrien 6759024Sobrien#ifndef _VM_OBJECT_ 6859024Sobrien#define _VM_OBJECT_ 6959024Sobrien 7059024Sobrien#include <sys/queue.h> 7159024Sobrien#include <sys/_lock.h> 7259024Sobrien#include <sys/_mutex.h> 7359024Sobrien 7459024Sobrien/* 7559024Sobrien * Types defined: 7659024Sobrien * 7759024Sobrien * vm_object_t Virtual memory object. 7859024Sobrien * 7959024Sobrien * List of locks 8059024Sobrien * (c) const until freed 8159024Sobrien * 8277298Sobrien */ 8377298Sobrien 8459024Sobrienstruct vm_object { 8559024Sobrien struct mtx mtx; 8659024Sobrien TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ 8759024Sobrien LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */ 8859024Sobrien LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */ 8959024Sobrien TAILQ_HEAD(, vm_page) memq; /* list of resident pages */ 9059024Sobrien vm_page_t root; /* root of the resident page splay tree */ 9159024Sobrien vm_pindex_t size; /* Object size */ 9259024Sobrien int generation; /* generation ID */ 9359024Sobrien int ref_count; /* How many refs?? */ 9459024Sobrien int shadow_count; /* how many objects that this is a shadow for */ 9559024Sobrien vm_memattr_t memattr; /* default memory attribute for pages */ 9659024Sobrien objtype_t type; /* type of pager */ 9759024Sobrien u_short flags; /* see below */ 9859024Sobrien u_short pg_color; /* (c) color of first page in obj */ 9959024Sobrien u_short paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ 10059024Sobrien int resident_page_count; /* number of resident pages */ 10159024Sobrien struct vm_object *backing_object; /* object that I'm a shadow of */ 10259024Sobrien vm_ooffset_t backing_object_offset;/* Offset in backing object */ 10359024Sobrien TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */ 10459024Sobrien LIST_HEAD(, vm_reserv) rvq; /* list of reservations */ 10559024Sobrien vm_page_t cache; /* root of the cache page splay tree */ 10659024Sobrien void *handle; 10759024Sobrien union { 10859024Sobrien /* 10959024Sobrien * VNode pager 11059024Sobrien * 11159024Sobrien * vnp_size - current size of file 11259024Sobrien */ 11359024Sobrien struct { 11459024Sobrien off_t vnp_size; 11559024Sobrien } vnp; 11659024Sobrien 11759024Sobrien /* 11859024Sobrien * Device pager 11959024Sobrien * 12059024Sobrien * devp_pglist - list of allocated pages 12159024Sobrien */ 12259024Sobrien struct { 12359024Sobrien TAILQ_HEAD(, vm_page) devp_pglist; 12459024Sobrien struct cdev_pager_ops *ops; 12559024Sobrien } devp; 12659024Sobrien 12759024Sobrien /* 12859024Sobrien * SG pager 12959024Sobrien * 13059024Sobrien * sgp_pglist - list of allocated pages 13159024Sobrien */ 13259024Sobrien struct { 13359024Sobrien TAILQ_HEAD(, vm_page) sgp_pglist; 13459024Sobrien } sgp; 13559024Sobrien 13659024Sobrien /* 13759024Sobrien * Swap pager 13859024Sobrien * 13959024Sobrien * swp_bcount - number of swap 'swblock' metablocks, each 14059024Sobrien * contains up to 16 swapblk assignments. 14159024Sobrien * see vm/swap_pager.h 14259024Sobrien */ 14359024Sobrien struct { 14459024Sobrien int swp_bcount; 14559024Sobrien } swp; 14659024Sobrien } un_pager; 14759024Sobrien struct ucred *cred; 14859024Sobrien vm_ooffset_t charge; 14959024Sobrien}; 15059024Sobrien 15159024Sobrien/* 15259024Sobrien * Flags 15359024Sobrien */ 15459024Sobrien#define OBJ_ACTIVE 0x0004 /* active objects */ 15559024Sobrien#define OBJ_DEAD 0x0008 /* dead objects (during rundown) */ 15659024Sobrien#define OBJ_NOSPLIT 0x0010 /* dont split this object */ 15759024Sobrien#define OBJ_PIPWNT 0x0040 /* paging in progress wanted */ 15859024Sobrien#define OBJ_MIGHTBEDIRTY 0x0100 /* object might be dirty, only for vnode */ 15959024Sobrien#define OBJ_COLORED 0x1000 /* pg_color is defined */ 16059024Sobrien#define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */ 16159024Sobrien#define OBJ_DISCONNECTWNT 0x4000 /* disconnect from vnode wanted */ 16259024Sobrien 16359024Sobrien#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT) 16459024Sobrien#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT)) 16559024Sobrien 16659024Sobrien#ifdef _KERNEL 16759024Sobrien 16859024Sobrien#define OBJPC_SYNC 0x1 /* sync I/O */ 16959024Sobrien#define OBJPC_INVAL 0x2 /* invalidate */ 17059024Sobrien#define OBJPC_NOSYNC 0x4 /* skip if PG_NOSYNC */ 17159024Sobrien 17259024Sobrien/* 17359024Sobrien * The following options are supported by vm_object_page_remove(). 17459024Sobrien */ 17559024Sobrien#define OBJPR_CLEANONLY 0x1 /* Don't remove dirty pages. */ 17659024Sobrien#define OBJPR_NOTMAPPED 0x2 /* Don't unmap pages. */ 17759024Sobrien 17859024SobrienTAILQ_HEAD(object_q, vm_object); 17959024Sobrien 18059024Sobrienextern struct object_q vm_object_list; /* list of allocated objects */ 18159024Sobrienextern struct mtx vm_object_list_mtx; /* lock for object list and count */ 18259024Sobrien 18359024Sobrienextern struct vm_object kernel_object_store; 18459024Sobrienextern struct vm_object kmem_object_store; 18559024Sobrien 18659024Sobrien#define kernel_object (&kernel_object_store) 18759024Sobrien#define kmem_object (&kmem_object_store) 18859024Sobrien 18959024Sobrien#define VM_OBJECT_LOCK(object) mtx_lock(&(object)->mtx) 19059024Sobrien#define VM_OBJECT_LOCK_ASSERT(object, type) \ 19159024Sobrien mtx_assert(&(object)->mtx, (type)) 19259024Sobrien#define VM_OBJECT_LOCK_INIT(object, type) \ 19359024Sobrien mtx_init(&(object)->mtx, "vm object", \ 19459024Sobrien (type), MTX_DEF | MTX_DUPOK) 19559024Sobrien#define VM_OBJECT_LOCKED(object) mtx_owned(&(object)->mtx) 19659024Sobrien#define VM_OBJECT_MTX(object) (&(object)->mtx) 19759024Sobrien#define VM_OBJECT_TRYLOCK(object) mtx_trylock(&(object)->mtx) 19859024Sobrien#define VM_OBJECT_UNLOCK(object) mtx_unlock(&(object)->mtx) 19959024Sobrien 20059024Sobrien/* 20159024Sobrien * The object must be locked or thread private. 20259024Sobrien */ 20359024Sobrienstatic __inline void 20459024Sobrienvm_object_set_flag(vm_object_t object, u_short bits) 20559024Sobrien{ 20659024Sobrien 20759024Sobrien object->flags |= bits; 20859024Sobrien} 20959024Sobrien 21059024Sobrienvoid vm_object_clear_flag(vm_object_t object, u_short bits); 21159024Sobrienvoid vm_object_pip_add(vm_object_t object, short i); 21259024Sobrienvoid vm_object_pip_subtract(vm_object_t object, short i); 21359024Sobrienvoid vm_object_pip_wakeup(vm_object_t object); 21459024Sobrienvoid vm_object_pip_wakeupn(vm_object_t object, short i); 21559024Sobrienvoid vm_object_pip_wait(vm_object_t object, char *waitid); 21659024Sobrien 21759024Sobrienvm_object_t vm_object_allocate (objtype_t, vm_pindex_t); 21859024Sobrienvoid _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t); 21959024Sobrienboolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t, 22059024Sobrien boolean_t); 22159024Sobrienvoid vm_object_collapse (vm_object_t); 22259024Sobrienvoid vm_object_deallocate (vm_object_t); 22359024Sobrienvoid vm_object_destroy (vm_object_t); 22459024Sobrienvoid vm_object_terminate (vm_object_t); 22559024Sobrienvoid vm_object_set_writeable_dirty (vm_object_t); 22659024Sobrienvoid vm_object_init (void); 22759024Sobrienvoid vm_object_page_clean(vm_object_t object, vm_ooffset_t start, 22859024Sobrien vm_ooffset_t end, int flags); 22959024Sobrienvoid vm_object_page_remove(vm_object_t object, vm_pindex_t start, 23059024Sobrien vm_pindex_t end, int options); 23159024Sobrienboolean_t vm_object_populate(vm_object_t, vm_pindex_t, vm_pindex_t); 23259024Sobrienvoid vm_object_print(long addr, boolean_t have_addr, long count, char *modif); 23359024Sobrienvoid vm_object_reference (vm_object_t); 23459024Sobrienvoid vm_object_reference_locked(vm_object_t); 23559024Sobrienint vm_object_set_memattr(vm_object_t object, vm_memattr_t memattr); 23659024Sobrienvoid vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); 23759024Sobrienvoid vm_object_split(vm_map_entry_t); 23859024Sobrienvoid vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t, 23959024Sobrien boolean_t); 24059024Sobrienvoid vm_object_madvise (vm_object_t, vm_pindex_t, int, int); 24159024Sobrien#endif /* _KERNEL */ 24259024Sobrien 24359024Sobrien#endif /* _VM_OBJECT_ */ 24459024Sobrien