vm_object.h revision 32585
1292920Sdim/*
2292920Sdim * Copyright (c) 1991, 1993
3353358Sdim *	The Regents of the University of California.  All rights reserved.
4353358Sdim *
5353358Sdim * This code is derived from software contributed to Berkeley by
6292920Sdim * The Mach Operating System project at Carnegie-Mellon University.
7292920Sdim *
8292920Sdim * Redistribution and use in source and binary forms, with or without
9292920Sdim * modification, are permitted provided that the following conditions
10292920Sdim * are met:
11292920Sdim * 1. Redistributions of source code must retain the above copyright
12292920Sdim *    notice, this list of conditions and the following disclaimer.
13292920Sdim * 2. Redistributions in binary form must reproduce the above copyright
14292920Sdim *    notice, this list of conditions and the following disclaimer in the
15292920Sdim *    documentation and/or other materials provided with the distribution.
16292920Sdim * 3. All advertising materials mentioning features or use of this software
17344779Sdim *    must display the following acknowledgement:
18292920Sdim *	This product includes software developed by the University of
19292920Sdim *	California, Berkeley and its contributors.
20292920Sdim * 4. Neither the name of the University nor the names of its contributors
21314564Sdim *    may be used to endorse or promote products derived from this software
22314564Sdim *    without specific prior written permission.
23314564Sdim *
24292920Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25292920Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26292920Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27292920Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28292920Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29292920Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30292920Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31292920Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32292920Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33292920Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34292920Sdim * SUCH DAMAGE.
35292920Sdim *
36292920Sdim *	from: @(#)vm_object.h	8.3 (Berkeley) 1/12/94
37292920Sdim *
38292920Sdim *
39292920Sdim * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40292920Sdim * All rights reserved.
41292920Sdim *
42292920Sdim * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43292920Sdim *
44292920Sdim * Permission to use, copy, modify and distribute this software and
45292920Sdim * its documentation is hereby granted, provided that both the copyright
46292920Sdim * notice and this permission notice appear in all copies of the
47292920Sdim * software, derivative works or modified versions, and any portions
48292920Sdim * thereof, and that both notices appear in supporting documentation.
49292920Sdim *
50292920Sdim * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51292920Sdim * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52292920Sdim * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53292920Sdim *
54292920Sdim * Carnegie Mellon requests users of this software to return to
55292920Sdim *
56292920Sdim *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57292920Sdim *  School of Computer Science
58292920Sdim *  Carnegie Mellon University
59321369Sdim *  Pittsburgh PA 15213-3890
60292920Sdim *
61292920Sdim * any improvements or extensions that they make and grant Carnegie the
62292920Sdim * rights to redistribute these changes.
63292920Sdim *
64292920Sdim * $Id: vm_object.h,v 1.41 1998/01/06 05:26:07 dyson Exp $
65292920Sdim */
66292920Sdim
67292920Sdim/*
68292920Sdim *	Virtual memory object module definitions.
69292920Sdim */
70292920Sdim
71292920Sdim#ifndef	_VM_OBJECT_
72292920Sdim#define	_VM_OBJECT_
73292920Sdim
74292920Sdim#include <sys/queue.h>
75292920Sdim
76292920Sdimenum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE, OBJT_DEAD };
77292920Sdimtypedef enum obj_type objtype_t;
78292920Sdim
79292920Sdim/*
80292920Sdim *	Types defined:
81321369Sdim *
82321369Sdim *	vm_object_t		Virtual memory object.
83321369Sdim */
84321369Sdim
85292920Sdimstruct vm_object {
86292920Sdim	TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
87292920Sdim	TAILQ_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
88292920Sdim	TAILQ_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
89292920Sdim	TAILQ_HEAD(, vm_page) memq;	/* list of resident pages */
90292920Sdim	objtype_t type;			/* type of pager */
91292920Sdim	vm_size_t size;			/* Object size */
92292920Sdim	int ref_count;			/* How many refs?? */
93292920Sdim	int shadow_count;		/* how many objects that this is a shadow for */
94292920Sdim	int pg_color;			/* color of first page in obj */
95292920Sdim	u_short flags;			/* see below */
96292920Sdim	u_short paging_in_progress;	/* Paging (in or out) so don't collapse or destroy */
97292920Sdim	u_short	behavior;		/* see below */
98292920Sdim	int resident_page_count;	/* number of resident pages */
99292920Sdim	vm_ooffset_t paging_offset;	/* Offset into paging space */
100321369Sdim	struct vm_object *backing_object; /* object that I'm a shadow of */
101292920Sdim	vm_ooffset_t backing_object_offset;/* Offset in backing object */
102292920Sdim	vm_offset_t last_read;		/* last read in object -- detect seq behavior */
103292920Sdim	vm_page_t page_hint;		/* hint for last looked-up or allocated page */
104292920Sdim	TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */
105292920Sdim	void *handle;
106292920Sdim	union {
107292920Sdim		struct {
108292920Sdim			off_t vnp_size; /* Current size of file */
109292920Sdim		} vnp;
110292920Sdim		struct {
111292920Sdim			TAILQ_HEAD(, vm_page) devp_pglist; /* list of pages allocated */
112292920Sdim		} devp;
113292920Sdim		struct {
114309124Sdim			int swp_nblocks;
115341825Sdim			int swp_allocsize;
116309124Sdim			struct swblock *swp_blocks;
117309124Sdim			short swp_poip;
118309124Sdim		} swp;
119309124Sdim	} un_pager;
120309124Sdim};
121309124Sdim
122309124Sdim/*
123360784Sdim * Flags
124309124Sdim */
125309124Sdim#define OBJ_ACTIVE	0x0004		/* active objects */
126360784Sdim#define OBJ_DEAD	0x0008		/* dead objects (during rundown) */
127360784Sdim#define OBJ_PIPWNT	0x0040		/* paging in progress wanted */
128360784Sdim#define	OBJ_WRITEABLE	0x0080		/* object has been made writable */
129309124Sdim#define OBJ_MIGHTBEDIRTY	0x0100	/* object might be dirty */
130309124Sdim#define OBJ_CLEANING	0x0200
131309124Sdim#define OBJ_OPT		0x1000		/* I/O optimization */
132309124Sdim
133309124Sdim#define OBJ_NORMAL	0x0		/* default behavior */
134309124Sdim#define OBJ_SEQUENTIAL	0x1		/* expect sequential accesses */
135309124Sdim#define OBJ_RANDOM	0x2		/* expect random accesses */
136292920Sdim
137292920Sdim#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
138292920Sdim#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
139292920Sdim
140292920Sdim#ifdef	KERNEL
141292920Sdim
142292920SdimTAILQ_HEAD(object_q, vm_object);
143292920Sdim
144292920Sdimextern struct object_q vm_object_list;	/* list of allocated objects */
145292920Sdim
146292920Sdim /* lock for object list and count */
147292920Sdim
148292920Sdimextern vm_object_t kernel_object;	/* the single kernel object */
149292920Sdimextern vm_object_t kmem_object;
150292920Sdim
151292920Sdim#endif				/* KERNEL */
152292920Sdim
153292920Sdim#ifdef KERNEL
154292920Sdimstatic __inline void
155292920Sdimvm_object_pip_wakeup(vm_object_t object)
156292920Sdim{
157292920Sdim	object->paging_in_progress--;
158292920Sdim	if ((object->flags & OBJ_PIPWNT) && object->paging_in_progress == 0) {
159292920Sdim		object->flags &= ~OBJ_PIPWNT;
160292920Sdim		wakeup(object);
161292920Sdim	}
162292920Sdim}
163292920Sdim
164292920Sdimvm_object_t vm_object_allocate __P((objtype_t, vm_size_t));
165292920Sdimvoid _vm_object_allocate __P((objtype_t, vm_size_t, vm_object_t));
166292920Sdimboolean_t vm_object_coalesce __P((vm_object_t, vm_pindex_t, vm_size_t, vm_size_t));
167292920Sdimvoid vm_object_collapse __P((vm_object_t));
168292920Sdimvoid vm_object_copy __P((vm_object_t, vm_pindex_t, vm_object_t *, vm_pindex_t *, boolean_t *));
169292920Sdimvoid vm_object_deallocate __P((vm_object_t));
170292920Sdimvoid vm_object_terminate __P((vm_object_t));
171292920Sdimvoid vm_object_vndeallocate __P((vm_object_t));
172292920Sdimvoid vm_object_init __P((void));
173292920Sdimvoid vm_object_page_clean __P((vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t));
174292920Sdimvoid vm_object_page_remove __P((vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t));
175292920Sdimvoid vm_object_pmap_copy __P((vm_object_t, vm_pindex_t, vm_pindex_t));
176292920Sdimvoid vm_object_pmap_copy_1 __P((vm_object_t, vm_pindex_t, vm_pindex_t));
177292920Sdimvoid vm_object_pmap_remove __P((vm_object_t, vm_pindex_t, vm_pindex_t));
178292920Sdimvoid vm_object_reference __P((vm_object_t));
179292920Sdimvoid vm_object_shadow __P((vm_object_t *, vm_ooffset_t *, vm_size_t));
180292920Sdimvoid vm_object_madvise __P((vm_object_t, vm_pindex_t, int, int));
181292920Sdimvoid vm_object_init2 __P((void));
182292920Sdim#endif				/* KERNEL */
183292920Sdim
184292920Sdim#endif				/* _VM_OBJECT_ */
185292920Sdim