vm_object.h revision 18942
1155408Srwatson/*
2155408Srwatson * Copyright (c) 1991, 1993
3155408Srwatson *	The Regents of the University of California.  All rights reserved.
4155408Srwatson *
5155408Srwatson * This code is derived from software contributed to Berkeley by
6155408Srwatson * The Mach Operating System project at Carnegie-Mellon University.
7155408Srwatson *
8155408Srwatson * Redistribution and use in source and binary forms, with or without
9155408Srwatson * modification, are permitted provided that the following conditions
10155408Srwatson * are met:
11155408Srwatson * 1. Redistributions of source code must retain the above copyright
12155408Srwatson *    notice, this list of conditions and the following disclaimer.
13155408Srwatson * 2. Redistributions in binary form must reproduce the above copyright
14155408Srwatson *    notice, this list of conditions and the following disclaimer in the
15155408Srwatson *    documentation and/or other materials provided with the distribution.
16155408Srwatson * 3. All advertising materials mentioning features or use of this software
17155408Srwatson *    must display the following acknowledgement:
18155408Srwatson *	This product includes software developed by the University of
19155408Srwatson *	California, Berkeley and its contributors.
20155408Srwatson * 4. Neither the name of the University nor the names of its contributors
21155408Srwatson *    may be used to endorse or promote products derived from this software
22155408Srwatson *    without specific prior written permission.
23155408Srwatson *
24155408Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25155408Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26155408Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27155408Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28155408Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29155408Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30155408Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31155408Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32155408Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33155408Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34155408Srwatson * SUCH DAMAGE.
35155408Srwatson *
36155408Srwatson *	from: @(#)vm_object.h	8.3 (Berkeley) 1/12/94
37155408Srwatson *
38155408Srwatson *
39155408Srwatson * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40155408Srwatson * All rights reserved.
41155408Srwatson *
42155408Srwatson * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43155408Srwatson *
44155408Srwatson * Permission to use, copy, modify and distribute this software and
45155408Srwatson * its documentation is hereby granted, provided that both the copyright
46155408Srwatson * notice and this permission notice appear in all copies of the
47155408Srwatson * software, derivative works or modified versions, and any portions
48155408Srwatson * thereof, and that both notices appear in supporting documentation.
49155408Srwatson *
50155408Srwatson * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51156880Srwatson * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52155408Srwatson * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53155408Srwatson *
54155408Srwatson * Carnegie Mellon requests users of this software to return to
55155408Srwatson *
56155408Srwatson *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57155408Srwatson *  School of Computer Science
58159269Srwatson *  Carnegie Mellon University
59159269Srwatson *  Pittsburgh PA 15213-3890
60155408Srwatson *
61155408Srwatson * any improvements or extensions that they make and grant Carnegie the
62155408Srwatson * rights to redistribute these changes.
63155408Srwatson *
64155408Srwatson * $Id: vm_object.h,v 1.31 1996/09/28 03:33:31 dyson Exp $
65155408Srwatson */
66155408Srwatson
67155408Srwatson/*
68159269Srwatson *	Virtual memory object module definitions.
69159269Srwatson */
70155408Srwatson
71155408Srwatson#ifndef	_VM_OBJECT_
72155408Srwatson#define	_VM_OBJECT_
73155408Srwatson
74156883Srwatson#include <sys/queue.h>
75156880Srwatson
76155408Srwatsonenum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE };
77155408Srwatsontypedef enum obj_type objtype_t;
78155408Srwatson
79155408Srwatson/*
80155408Srwatson *	Types defined:
81155408Srwatson *
82155408Srwatson *	vm_object_t		Virtual memory object.
83155408Srwatson */
84155408Srwatson
85155408Srwatsonstruct vm_object {
86155408Srwatson	TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
87155408Srwatson	TAILQ_ENTRY(vm_object) cached_list; /* list of cached (persistent) objects */
88159269Srwatson	TAILQ_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
89159269Srwatson	TAILQ_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
90159269Srwatson	TAILQ_HEAD(, vm_page) memq;	/* list of resident pages */
91159269Srwatson	objtype_t type;			/* type of pager */
92159269Srwatson	vm_size_t size;			/* Object size */
93159269Srwatson	int ref_count;			/* How many refs?? */
94159269Srwatson	int shadow_count;		/* how many objects that this is a shadow for */
95159269Srwatson	int pg_color;			/* color of first page in obj */
96159269Srwatson	u_short flags;			/* see below */
97159269Srwatson	u_short paging_in_progress;	/* Paging (in or out) so don't collapse or destroy */
98159269Srwatson	u_short	behavior;		/* see below */
99159269Srwatson	int resident_page_count;	/* number of resident pages */
100159269Srwatson	vm_ooffset_t paging_offset;	/* Offset into paging space */
101159269Srwatson	struct vm_object *backing_object; /* object that I'm a shadow of */
102159269Srwatson	vm_ooffset_t backing_object_offset;/* Offset in backing object */
103159269Srwatson	vm_offset_t last_read;		/* last read in object -- detect seq behavior */
104159269Srwatson	vm_page_t page_hint;		/* hint for last looked-up or allocated page */
105155408Srwatson	TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */
106155408Srwatson	void *handle;
107155408Srwatson	union {
108155408Srwatson		struct {
109155408Srwatson			off_t vnp_size; /* Current size of file */
110155408Srwatson		} vnp;
111155408Srwatson		struct {
112155408Srwatson			TAILQ_HEAD(, vm_page) devp_pglist; /* list of pages allocated */
113155408Srwatson		} devp;
114155408Srwatson		struct {
115155408Srwatson			int swp_nblocks;
116155408Srwatson			int swp_allocsize;
117155408Srwatson			struct swblock *swp_blocks;
118155408Srwatson			short swp_poip;
119155408Srwatson		} swp;
120155408Srwatson	} un_pager;
121155408Srwatson};
122155408Srwatson
123155408Srwatson/*
124155408Srwatson * Flags
125159269Srwatson */
126159269Srwatson#define OBJ_CANPERSIST	0x0001		/* allow to persist */
127159269Srwatson#define OBJ_ACTIVE	0x0004		/* active objects */
128159269Srwatson#define OBJ_DEAD	0x0008		/* dead objects (during rundown) */
129159269Srwatson#define	OBJ_PIPWNT	0x0040		/* paging in progress wanted */
130159269Srwatson#define	OBJ_WRITEABLE	0x0080		/* object has been made writable */
131159269Srwatson#define	OBJ_MIGHTBEDIRTY	0x0100	/* object might be dirty */
132159269Srwatson#define OBJ_CLEANING	0x0200
133159269Srwatson#define	OBJ_VFS_REF	0x0400		/* object is refed by vfs layer */
134159269Srwatson
135159269Srwatson
136159269Srwatson#define OBJ_NORMAL	0x0		/* default behavior */
137159269Srwatson#define OBJ_SEQUENTIAL	0x1		/* expect sequential accesses */
138155408Srwatson#define OBJ_RANDOM	0x2		/* expect random accesses */
139155408Srwatson
140159269Srwatson#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
141159269Srwatson#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
142159269Srwatson
143155408Srwatson#ifdef	KERNEL
144155408Srwatsonextern int vm_object_cache_max;
145155408Srwatson
146155408SrwatsonTAILQ_HEAD(object_q, vm_object);
147159269Srwatson
148155408Srwatsonextern struct object_q vm_object_cached_list; /* list of objects persisting */
149155408Srwatsonextern int vm_object_cached;		/* size of cached list */
150155408Srwatson
151155408Srwatsonextern struct object_q vm_object_list;	/* list of allocated objects */
152155408Srwatsonextern long vm_object_count;		/* count of all objects */
153155408Srwatson
154159269Srwatson /* lock for object list and count */
155159269Srwatson
156159269Srwatsonextern vm_object_t kernel_object;	/* the single kernel object */
157155408Srwatsonextern vm_object_t kmem_object;
158155408Srwatson
159155408Srwatson#endif				/* KERNEL */
160155408Srwatson
161155408Srwatson#ifdef KERNEL
162155408Srwatsonstatic __inline void
163155408Srwatsonvm_object_pip_wakeup(vm_object_t object)
164155408Srwatson{
165155408Srwatson	object->paging_in_progress--;
166155408Srwatson	if ((object->flags & OBJ_PIPWNT) && object->paging_in_progress == 0) {
167155408Srwatson		object->flags &= ~OBJ_PIPWNT;
168155408Srwatson		wakeup(object);
169155408Srwatson	}
170155408Srwatson}
171155408Srwatson
172155408Srwatsonvm_object_t vm_object_allocate __P((objtype_t, vm_size_t));
173155408Srwatsonvoid vm_object_cache_clear __P((void));
174155408Srwatsonboolean_t vm_object_coalesce __P((vm_object_t, vm_pindex_t, vm_size_t, vm_size_t));
175161582Srwatsonvoid vm_object_collapse __P((vm_object_t));
176155408Srwatsonvoid vm_object_copy __P((vm_object_t, vm_pindex_t, vm_object_t *, vm_pindex_t *, boolean_t *));
177155408Srwatsonvoid vm_object_deallocate __P((vm_object_t));
178155408Srwatsonvoid vm_object_init __P((void));
179159269Srwatsonvoid vm_object_page_clean __P((vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t, boolean_t));
180155408Srwatsonvoid vm_object_page_remove __P((vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t));
181155408Srwatsonvoid vm_object_pmap_copy __P((vm_object_t, vm_pindex_t, vm_pindex_t));
182155408Srwatsonvoid vm_object_pmap_remove __P((vm_object_t, vm_pindex_t, vm_pindex_t));
183155408Srwatsonvoid vm_object_reference __P((vm_object_t));
184155408Srwatsonvoid vm_object_shadow __P((vm_object_t *, vm_ooffset_t *, vm_size_t));
185161582Srwatsonvoid vm_object_madvise __P((vm_object_t, vm_pindex_t, int, int));
186155408Srwatson#endif				/* KERNEL */
187155408Srwatson
188155408Srwatson#endif				/* _VM_OBJECT_ */
189161582Srwatson