vm_object.h revision 188348
11558Srgrimes/*-
21558Srgrimes * Copyright (c) 1991, 1993
31558Srgrimes *	The Regents of the University of California.  All rights reserved.
41558Srgrimes *
51558Srgrimes * This code is derived from software contributed to Berkeley by
61558Srgrimes * The Mach Operating System project at Carnegie-Mellon University.
71558Srgrimes *
81558Srgrimes * Redistribution and use in source and binary forms, with or without
91558Srgrimes * modification, are permitted provided that the following conditions
101558Srgrimes * are met:
111558Srgrimes * 1. Redistributions of source code must retain the above copyright
121558Srgrimes *    notice, this list of conditions and the following disclaimer.
131558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141558Srgrimes *    notice, this list of conditions and the following disclaimer in the
151558Srgrimes *    documentation and/or other materials provided with the distribution.
161558Srgrimes * 4. Neither the name of the University nor the names of its contributors
171558Srgrimes *    may be used to endorse or promote products derived from this software
181558Srgrimes *    without specific prior written permission.
191558Srgrimes *
201558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301558Srgrimes * SUCH DAMAGE.
311558Srgrimes *
321558Srgrimes *	from: @(#)vm_object.h	8.3 (Berkeley) 1/12/94
331558Srgrimes *
341558Srgrimes *
3538039Scharnier * Copyright (c) 1987, 1990 Carnegie-Mellon University.
361558Srgrimes * All rights reserved.
371558Srgrimes *
381558Srgrimes * Authors: Avadis Tevanian, Jr., Michael Wayne Young
391558Srgrimes *
401558Srgrimes * Permission to use, copy, modify and distribute this software and
4138039Scharnier * its documentation is hereby granted, provided that both the copyright
421558Srgrimes * notice and this permission notice appear in all copies of the
4338039Scharnier * software, derivative works or modified versions, and any portions
4438039Scharnier * thereof, and that both notices appear in supporting documentation.
4550476Speter *
461558Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
471558Srgrimes * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48108375Sdillon * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49108375Sdillon *
50108375Sdillon * Carnegie Mellon requests users of this software to return to
51108375Sdillon *
52108375Sdillon *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
5338039Scharnier *  School of Computer Science
5438039Scharnier *  Carnegie Mellon University
551558Srgrimes *  Pittsburgh PA 15213-3890
561558Srgrimes *
5778732Sdd * any improvements or extensions that they make and grant Carnegie the
5838039Scharnier * rights to redistribute these changes.
596661Sphk *
60108375Sdillon * $FreeBSD: head/sys/vm/vm_object.h 188348 2009-02-08 22:17:24Z alc $
611558Srgrimes */
62108375Sdillon
63108375Sdillon/*
64108375Sdillon *	Virtual memory object module definitions.
656661Sphk */
66108375Sdillon
67108375Sdillon#ifndef	_VM_OBJECT_
686661Sphk#define	_VM_OBJECT_
696661Sphk
701558Srgrimes#include <sys/queue.h>
7192806Sobrien#include <sys/_lock.h>
72108375Sdillon#include <sys/_mutex.h>
7392806Sobrien
741558Srgrimes/*
75108375Sdillon *	Types defined:
761558Srgrimes *
77108375Sdillon *	vm_object_t		Virtual memory object.
78108375Sdillon *
79108375Sdillon * List of locks
80108375Sdillon *	(c)	const until freed
81108375Sdillon *
82108375Sdillon */
83108375Sdillon
84108375Sdillonstruct vm_object {
851558Srgrimes	struct mtx mtx;
86108375Sdillon	TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
87108375Sdillon	LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
88108375Sdillon	LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
89108375Sdillon	TAILQ_HEAD(, vm_page) memq;	/* list of resident pages */
90108375Sdillon	vm_page_t root;			/* root of the resident page splay tree */
91108375Sdillon	vm_pindex_t size;		/* Object size */
92108375Sdillon	int generation;			/* generation ID */
93108375Sdillon	int ref_count;			/* How many refs?? */
94108375Sdillon	int shadow_count;		/* how many objects that this is a shadow for */
95108375Sdillon	objtype_t type;			/* type of pager */
961558Srgrimes	u_short flags;			/* see below */
97108375Sdillon	u_short pg_color;		/* (c) color of first page in obj */
98108375Sdillon	u_short paging_in_progress;	/* Paging (in or out) so don't collapse or destroy */
99108375Sdillon	int resident_page_count;	/* number of resident pages */
100108375Sdillon	struct vm_object *backing_object; /* object that I'm a shadow of */
1011558Srgrimes	vm_ooffset_t backing_object_offset;/* Offset in backing object */
102108375Sdillon	TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */
103108375Sdillon	LIST_HEAD(, vm_reserv) rvq;	/* list of reservations */
104108375Sdillon	vm_page_t cache;		/* root of the cache page splay tree */
105108375Sdillon	void *handle;
106108375Sdillon	union {
107108375Sdillon		/*
108108375Sdillon		 * VNode pager
109108375Sdillon		 *
110108375Sdillon		 *	vnp_size - current size of file
111108375Sdillon		 */
112108375Sdillon		struct {
113108375Sdillon			off_t vnp_size;
114108375Sdillon		} vnp;
115108375Sdillon
116108375Sdillon		/*
117108375Sdillon		 * Device pager
118108375Sdillon		 *
119108375Sdillon		 *	devp_pglist - list of allocated pages
120108375Sdillon		 */
121108375Sdillon		struct {
122108375Sdillon			TAILQ_HEAD(, vm_page) devp_pglist;
123108375Sdillon		} devp;
124108375Sdillon
125108375Sdillon		/*
126108375Sdillon		 * Swap pager
127108375Sdillon		 *
1281558Srgrimes		 *	swp_bcount - number of swap 'swblock' metablocks, each
1291558Srgrimes		 *		     contains up to 16 swapblk assignments.
130108375Sdillon		 *		     see vm/swap_pager.h
1311558Srgrimes		 */
132108375Sdillon		struct {
1331558Srgrimes			int swp_bcount;
1341558Srgrimes		} swp;
1351558Srgrimes	} un_pager;
136108375Sdillon};
137108375Sdillon
138108375Sdillon/*
139108375Sdillon * Flags
140108375Sdillon */
141108375Sdillon#define OBJ_ACTIVE	0x0004		/* active objects */
142108375Sdillon#define OBJ_DEAD	0x0008		/* dead objects (during rundown) */
143108375Sdillon#define	OBJ_NOSPLIT	0x0010		/* dont split this object */
144108375Sdillon#define OBJ_PIPWNT	0x0040		/* paging in progress wanted */
145108375Sdillon#define OBJ_MIGHTBEDIRTY 0x0100		/* object might be dirty */
146108375Sdillon#define OBJ_CLEANING	0x0200
147108375Sdillon#define	OBJ_COLORED	0x1000		/* pg_color is defined */
148108375Sdillon#define	OBJ_ONEMAPPING	0x2000		/* One USE (a single, non-forked) mapping flag */
149108375Sdillon#define	OBJ_DISCONNECTWNT 0x4000	/* disconnect from vnode wanted */
150108375Sdillon
151108375Sdillon#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
152108375Sdillon#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
153108375Sdillon
154108375Sdillon#ifdef	_KERNEL
155108375Sdillon
1561558Srgrimes#define OBJPC_SYNC	0x1			/* sync I/O */
157108375Sdillon#define OBJPC_INVAL	0x2			/* invalidate */
158107913Sdillon#define OBJPC_NOSYNC	0x4			/* skip if PG_NOSYNC */
159108375Sdillon
160108375SdillonTAILQ_HEAD(object_q, vm_object);
161108375Sdillon
1621558Srgrimesextern struct object_q vm_object_list;	/* list of allocated objects */
163108375Sdillonextern struct mtx vm_object_list_mtx;	/* lock for object list and count */
164108375Sdillon
165108375Sdillonextern struct vm_object kernel_object_store;
166108375Sdillonextern struct vm_object kmem_object_store;
167108375Sdillon
168108375Sdillon#define	kernel_object	(&kernel_object_store)
1691558Srgrimes#define	kmem_object	(&kmem_object_store)
1701558Srgrimes
1711558Srgrimes#define	VM_OBJECT_LOCK(object)		mtx_lock(&(object)->mtx)
172108375Sdillon#define	VM_OBJECT_LOCK_ASSERT(object, type) \
173108375Sdillon					mtx_assert(&(object)->mtx, (type))
1741558Srgrimes#define	VM_OBJECT_LOCK_INIT(object, type) \
175108375Sdillon					mtx_init(&(object)->mtx, "vm object", \
1761558Srgrimes					    (type), MTX_DEF | MTX_DUPOK)
1771558Srgrimes#define	VM_OBJECT_LOCKED(object)	mtx_owned(&(object)->mtx)
1781558Srgrimes#define	VM_OBJECT_MTX(object)		(&(object)->mtx)
17926740Scharnier#define	VM_OBJECT_TRYLOCK(object)	mtx_trylock(&(object)->mtx)
1801558Srgrimes#define	VM_OBJECT_UNLOCK(object)	mtx_unlock(&(object)->mtx)
1811558Srgrimes
18226740Scharnier/*
1831558Srgrimes *	The object must be locked or thread private.
1841558Srgrimes */
1851558Srgrimesstatic __inline void
1861558Srgrimesvm_object_set_flag(vm_object_t object, u_short bits)
1871558Srgrimes{
1881558Srgrimes
1891558Srgrimes	object->flags |= bits;
19026740Scharnier}
191108375Sdillon
1921558Srgrimesvoid vm_object_clear_flag(vm_object_t object, u_short bits);
193108375Sdillonvoid vm_object_pip_add(vm_object_t object, short i);
194108375Sdillonvoid vm_object_pip_subtract(vm_object_t object, short i);
195108375Sdillonvoid vm_object_pip_wakeup(vm_object_t object);
196108375Sdillonvoid vm_object_pip_wakeupn(vm_object_t object, short i);
197108375Sdillonvoid vm_object_pip_wait(vm_object_t object, char *waitid);
198108375Sdillon
199108375Sdillonvm_object_t vm_object_allocate (objtype_t, vm_pindex_t);
200108375Sdillonvoid _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t);
201108375Sdillonboolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t);
202108375Sdillonvoid vm_object_collapse (vm_object_t);
203108375Sdillonvoid vm_object_deallocate (vm_object_t);
204108375Sdillonvoid vm_object_destroy (vm_object_t);
2051558Srgrimesvoid vm_object_terminate (vm_object_t);
2061558Srgrimesvoid vm_object_set_writeable_dirty (vm_object_t);
207107913Sdillonvoid vm_object_init (void);
208108375Sdillonvoid vm_object_page_clean (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t);
209108375Sdillonvoid vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t);
210107913Sdillonvoid vm_object_reference (vm_object_t);
211108375Sdillonvoid vm_object_reference_locked(vm_object_t);
212108375Sdillonvoid vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t);
213108425Smikevoid vm_object_split(vm_map_entry_t);
214108375Sdillonvoid vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t,
215108375Sdillon    boolean_t);
216108375Sdillonvoid vm_object_madvise (vm_object_t, vm_pindex_t, int, int);
217108375Sdillon#endif				/* _KERNEL */
218108375Sdillon
219108375Sdillon#endif				/* _VM_OBJECT_ */
220108375Sdillon