vm_object.h revision 144501
120253Sjoerg/*-
220302Sjoerg * Copyright (c) 1991, 1993
320302Sjoerg *	The Regents of the University of California.  All rights reserved.
420253Sjoerg *
520253Sjoerg * This code is derived from software contributed to Berkeley by
620253Sjoerg * The Mach Operating System project at Carnegie-Mellon University.
720253Sjoerg *
820253Sjoerg * Redistribution and use in source and binary forms, with or without
920302Sjoerg * modification, are permitted provided that the following conditions
1020253Sjoerg * are met:
1120253Sjoerg * 1. Redistributions of source code must retain the above copyright
1220253Sjoerg *    notice, this list of conditions and the following disclaimer.
1320253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1420302Sjoerg *    notice, this list of conditions and the following disclaimer in the
1520253Sjoerg *    documentation and/or other materials provided with the distribution.
1620253Sjoerg * 4. Neither the name of the University nor the names of its contributors
1720302Sjoerg *    may be used to endorse or promote products derived from this software
1820253Sjoerg *    without specific prior written permission.
1920253Sjoerg *
2020253Sjoerg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2120253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2220253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2320253Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2420253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2520253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2620747Sdavidn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2720253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2820253Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2920253Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3020253Sjoerg * SUCH DAMAGE.
3120253Sjoerg *
3220253Sjoerg *	from: @(#)vm_object.h	8.3 (Berkeley) 1/12/94
3320253Sjoerg *
3420253Sjoerg *
3520253Sjoerg * Copyright (c) 1987, 1990 Carnegie-Mellon University.
3620555Sdavidn * All rights reserved.
3720555Sdavidn *
3820555Sdavidn * Authors: Avadis Tevanian, Jr., Michael Wayne Young
3920555Sdavidn *
4020253Sjoerg * Permission to use, copy, modify and distribute this software and
4120253Sjoerg * its documentation is hereby granted, provided that both the copyright
4220253Sjoerg * notice and this permission notice appear in all copies of the
4320253Sjoerg * software, derivative works or modified versions, and any portions
4420253Sjoerg * thereof, and that both notices appear in supporting documentation.
4520253Sjoerg *
4620253Sjoerg * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
4720253Sjoerg * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
4820253Sjoerg * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
4920253Sjoerg *
5020253Sjoerg * Carnegie Mellon requests users of this software to return to
5120253Sjoerg *
5220253Sjoerg *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
5320253Sjoerg *  School of Computer Science
5420747Sdavidn *  Carnegie Mellon University
5520253Sjoerg *  Pittsburgh PA 15213-3890
5620253Sjoerg *
5720253Sjoerg * any improvements or extensions that they make and grant Carnegie the
5820253Sjoerg * rights to redistribute these changes.
5920253Sjoerg *
6020253Sjoerg * $FreeBSD: head/sys/vm/vm_object.h 144501 2005-04-01 20:00:11Z jhb $
6120253Sjoerg */
6220253Sjoerg
6320253Sjoerg/*
6420253Sjoerg *	Virtual memory object module definitions.
6520253Sjoerg */
6620253Sjoerg
6720253Sjoerg#ifndef	_VM_OBJECT_
6820253Sjoerg#define	_VM_OBJECT_
6920253Sjoerg
7020253Sjoerg#include <sys/queue.h>
7120253Sjoerg#include <sys/_lock.h>
7220253Sjoerg#include <sys/_mutex.h>
7320253Sjoerg
7420253Sjoerg/*
7520253Sjoerg *	Types defined:
7620253Sjoerg *
7720253Sjoerg *	vm_object_t		Virtual memory object.
7820253Sjoerg *
7920253Sjoerg * List of locks
8020253Sjoerg *	(c)	const until freed
8120253Sjoerg *
8220253Sjoerg */
8320253Sjoerg
8420253Sjoergstruct vm_object {
8520253Sjoerg	struct mtx mtx;
8620253Sjoerg	TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
8720253Sjoerg	LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
8820253Sjoerg	LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
8920253Sjoerg	TAILQ_HEAD(, vm_page) memq;	/* list of resident pages */
9020253Sjoerg	vm_page_t root;			/* root of the resident page splay tree */
9120253Sjoerg	vm_pindex_t size;		/* Object size */
9220253Sjoerg	int generation;			/* generation ID */
9320253Sjoerg	int ref_count;			/* How many refs?? */
9420253Sjoerg	int shadow_count;		/* how many objects that this is a shadow for */
9520253Sjoerg	objtype_t type;			/* type of pager */
9620253Sjoerg	u_short flags;			/* see below */
9720747Sdavidn	u_short pg_color;		/* (c) color of first page in obj */
9820253Sjoerg	u_short paging_in_progress;	/* Paging (in or out) so don't collapse or destroy */
9920253Sjoerg	int resident_page_count;	/* number of resident pages */
10020253Sjoerg	struct vm_object *backing_object; /* object that I'm a shadow of */
10120253Sjoerg	vm_ooffset_t backing_object_offset;/* Offset in backing object */
10220253Sjoerg	TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */
10320253Sjoerg	void *handle;
10420253Sjoerg	union {
10520253Sjoerg		/*
10620253Sjoerg		 * VNode pager
10720253Sjoerg		 *
10820253Sjoerg		 *	vnp_size - current size of file
10920253Sjoerg		 */
11020253Sjoerg		struct {
11120253Sjoerg			off_t vnp_size;
11220253Sjoerg		} vnp;
11320253Sjoerg
11420267Sjoerg		/*
11520267Sjoerg		 * Device pager
11620267Sjoerg		 *
11720267Sjoerg		 *	devp_pglist - list of allocated pages
11820267Sjoerg		 */
11920267Sjoerg		struct {
12020267Sjoerg			TAILQ_HEAD(, vm_page) devp_pglist;
12120267Sjoerg		} devp;
12220267Sjoerg
12320267Sjoerg		/*
12420267Sjoerg		 * Swap pager
12520267Sjoerg		 *
12620267Sjoerg		 *	swp_bcount - number of swap 'swblock' metablocks, each
12720267Sjoerg		 *		     contains up to 16 swapblk assignments.
12820253Sjoerg		 *		     see vm/swap_pager.h
12920253Sjoerg		 */
13020253Sjoerg		struct {
13120253Sjoerg			int swp_bcount;
13220267Sjoerg		} swp;
13320267Sjoerg	} un_pager;
13420267Sjoerg};
13520253Sjoerg
13620253Sjoerg/*
13720253Sjoerg * Flags
13820253Sjoerg */
13920253Sjoerg#define OBJ_ACTIVE	0x0004		/* active objects */
14020253Sjoerg#define OBJ_DEAD	0x0008		/* dead objects (during rundown) */
14120253Sjoerg#define	OBJ_NOSPLIT	0x0010		/* dont split this object */
14220253Sjoerg#define OBJ_PIPWNT	0x0040		/* paging in progress wanted */
14320253Sjoerg#define	OBJ_WRITEABLE	0x0080		/* object has been made writable */
14420253Sjoerg#define OBJ_MIGHTBEDIRTY 0x0100		/* object might be dirty */
14520253Sjoerg#define OBJ_CLEANING	0x0200
14620267Sjoerg#define	OBJ_ONEMAPPING	0x2000		/* One USE (a single, non-forked) mapping flag */
14720253Sjoerg#define	OBJ_DISCONNECTWNT 0x4000	/* disconnect from vnode wanted */
14820253Sjoerg
14920253Sjoerg#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
15020253Sjoerg#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
15120679Sdavidn
15220253Sjoerg#ifdef	_KERNEL
15320253Sjoerg
15420253Sjoerg#define OBJPC_SYNC	0x1			/* sync I/O */
15520253Sjoerg#define OBJPC_INVAL	0x2			/* invalidate */
15620747Sdavidn#define OBJPC_NOSYNC	0x4			/* skip if PG_NOSYNC */
15720253Sjoerg
15820253SjoergTAILQ_HEAD(object_q, vm_object);
15920267Sjoerg
16020253Sjoergextern struct object_q vm_object_list;	/* list of allocated objects */
16120747Sdavidnextern struct mtx vm_object_list_mtx;	/* lock for object list and count */
16220747Sdavidn
16320253Sjoergextern struct vm_object kernel_object_store;
16420747Sdavidnextern struct vm_object kmem_object_store;
16520253Sjoerg
16620253Sjoerg#define	kernel_object	(&kernel_object_store)
16720253Sjoerg#define	kmem_object	(&kmem_object_store)
16820253Sjoerg
16920267Sjoerg#define	VM_OBJECT_LOCK(object)		mtx_lock(&(object)->mtx)
17020253Sjoerg#define	VM_OBJECT_LOCK_ASSERT(object, type) \
17120253Sjoerg					mtx_assert(&(object)->mtx, (type))
17220253Sjoerg#define	VM_OBJECT_LOCK_INIT(object, type) \
17320253Sjoerg					mtx_init(&(object)->mtx, "vm object", \
17420253Sjoerg					    (type), MTX_DEF | MTX_DUPOK)
17520253Sjoerg#define	VM_OBJECT_LOCKED(object)	mtx_owned(&(object)->mtx)
17620267Sjoerg#define	VM_OBJECT_MTX(object)		(&(object)->mtx)
17720253Sjoerg#define	VM_OBJECT_TRYLOCK(object)	mtx_trylock(&(object)->mtx)
17820253Sjoerg#define	VM_OBJECT_UNLOCK(object)	mtx_unlock(&(object)->mtx)
17920253Sjoerg
18020253Sjoerg/*
18120253Sjoerg *	The object must be locked or thread private.
18220253Sjoerg */
18320253Sjoergstatic __inline void
18420253Sjoergvm_object_set_flag(vm_object_t object, u_short bits)
18520253Sjoerg{
18620253Sjoerg
18720253Sjoerg	object->flags |= bits;
18820253Sjoerg}
18920253Sjoerg
19020253Sjoergvoid vm_object_clear_flag(vm_object_t object, u_short bits);
19120253Sjoergvoid vm_object_pip_add(vm_object_t object, short i);
19220253Sjoergvoid vm_object_pip_subtract(vm_object_t object, short i);
19320253Sjoergvoid vm_object_pip_wakeup(vm_object_t object);
19420267Sjoergvoid vm_object_pip_wakeupn(vm_object_t object, short i);
19520253Sjoergvoid vm_object_pip_wait(vm_object_t object, char *waitid);
19620267Sjoerg
19720253Sjoergvm_object_t vm_object_allocate (objtype_t, vm_pindex_t);
19820253Sjoergvoid _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t);
19920267Sjoergboolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t);
20020253Sjoergvoid vm_object_collapse (vm_object_t);
20120253Sjoergvoid vm_object_deallocate (vm_object_t);
20220253Sjoergvoid vm_object_terminate (vm_object_t);
20320253Sjoergvoid vm_object_vndeallocate (vm_object_t);
20420253Sjoergvoid vm_object_set_writeable_dirty (vm_object_t);
20520267Sjoergvoid vm_object_init (void);
20620253Sjoergvoid vm_object_page_clean (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t);
20720253Sjoergvoid vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t);
20820679Sdavidnvoid vm_object_reference (vm_object_t);
20920253Sjoergvoid vm_object_reference_locked(vm_object_t);
21020253Sjoergvoid vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t);
21120253Sjoergvoid vm_object_split(vm_map_entry_t);
21220253Sjoergvoid vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t,
21320267Sjoerg    boolean_t);
21420253Sjoergvoid vm_object_madvise (vm_object_t, vm_pindex_t, int, int);
21520253Sjoerg#endif				/* _KERNEL */
21620253Sjoerg
21720253Sjoerg#endif				/* _VM_OBJECT_ */
21820253Sjoerg