xref: /freebsd/sys/vm/vm_object.h (revision bdfd1adc9908db7e346002769589bbadc29d344d)
160727d8bSWarner Losh /*-
2796df753SPedro F. Giffuni  * SPDX-License-Identifier: (BSD-3-Clause AND MIT-CMU)
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
8df8bae1dSRodney W. Grimes  * The Mach Operating System project at Carnegie-Mellon University.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
19df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
20df8bae1dSRodney W. Grimes  *    without specific prior written permission.
21df8bae1dSRodney W. Grimes  *
22df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
33df8bae1dSRodney W. Grimes  *
343c4dd356SDavid Greenman  *	from: @(#)vm_object.h	8.3 (Berkeley) 1/12/94
35df8bae1dSRodney W. Grimes  *
36df8bae1dSRodney W. Grimes  *
37df8bae1dSRodney W. Grimes  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
38df8bae1dSRodney W. Grimes  * All rights reserved.
39df8bae1dSRodney W. Grimes  *
40df8bae1dSRodney W. Grimes  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
41df8bae1dSRodney W. Grimes  *
42df8bae1dSRodney W. Grimes  * Permission to use, copy, modify and distribute this software and
43df8bae1dSRodney W. Grimes  * its documentation is hereby granted, provided that both the copyright
44df8bae1dSRodney W. Grimes  * notice and this permission notice appear in all copies of the
45df8bae1dSRodney W. Grimes  * software, derivative works or modified versions, and any portions
46df8bae1dSRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
47df8bae1dSRodney W. Grimes  *
48df8bae1dSRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
49df8bae1dSRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
50df8bae1dSRodney W. Grimes  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
51df8bae1dSRodney W. Grimes  *
52df8bae1dSRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
53df8bae1dSRodney W. Grimes  *
54df8bae1dSRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
55df8bae1dSRodney W. Grimes  *  School of Computer Science
56df8bae1dSRodney W. Grimes  *  Carnegie Mellon University
57df8bae1dSRodney W. Grimes  *  Pittsburgh PA 15213-3890
58df8bae1dSRodney W. Grimes  *
59df8bae1dSRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
60df8bae1dSRodney W. Grimes  * rights to redistribute these changes.
613c4dd356SDavid Greenman  *
62c3aac50fSPeter Wemm  * $FreeBSD$
63df8bae1dSRodney W. Grimes  */
64df8bae1dSRodney W. Grimes 
65df8bae1dSRodney W. Grimes /*
66df8bae1dSRodney W. Grimes  *	Virtual memory object module definitions.
67df8bae1dSRodney W. Grimes  */
68df8bae1dSRodney W. Grimes 
69df8bae1dSRodney W. Grimes #ifndef	_VM_OBJECT_
70df8bae1dSRodney W. Grimes #define	_VM_OBJECT_
71df8bae1dSRodney W. Grimes 
72aad9af2bSBruce Evans #include <sys/queue.h>
73c99d0c58SMark Johnston #include <sys/_blockcount.h>
744b420d50SAlan Cox #include <sys/_lock.h>
754b420d50SAlan Cox #include <sys/_mutex.h>
76f425ab8eSKonstantin Belousov #include <sys/_pctrie.h>
7789f6b863SAttilio Rao #include <sys/_rwlock.h>
783f289c3fSJeff Roberson #include <sys/_domainset.h>
79b5e8ce9fSBruce Evans 
80774d251dSAttilio Rao #include <vm/_vm_radix.h>
81774d251dSAttilio Rao 
82df8bae1dSRodney W. Grimes /*
83df8bae1dSRodney W. Grimes  *	Types defined:
84df8bae1dSRodney W. Grimes  *
85df8bae1dSRodney W. Grimes  *	vm_object_t		Virtual memory object.
861c7c3c6aSMatthew Dillon  *
8779660d83SAlan Cox  * List of locks
88205be21dSJeff Roberson  *	(a)	atomic
8979660d83SAlan Cox  *	(c)	const until freed
9089f6b863SAttilio Rao  *	(o)	per-object lock
91ffdd0c7dSAttilio Rao  *	(f)	free pages queue mutex
9279660d83SAlan Cox  *
93df8bae1dSRodney W. Grimes  */
94df8bae1dSRodney W. Grimes 
95b9e8fb64SKonstantin Belousov #ifndef VM_PAGE_HAVE_PGLIST
96b9e8fb64SKonstantin Belousov TAILQ_HEAD(pglist, vm_page);
97b9e8fb64SKonstantin Belousov #define VM_PAGE_HAVE_PGLIST
98b9e8fb64SKonstantin Belousov #endif
99b9e8fb64SKonstantin Belousov 
100df8bae1dSRodney W. Grimes struct vm_object {
10189f6b863SAttilio Rao 	struct rwlock lock;
102e3975643SJake Burkholder 	TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
1031c500307SAlan Cox 	LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
1041c500307SAlan Cox 	LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
105b9e8fb64SKonstantin Belousov 	struct pglist memq;		/* list of resident pages */
106774d251dSAttilio Rao 	struct vm_radix rtree;		/* root of the resident page radix trie*/
1076395da54SIan Dowse 	vm_pindex_t size;		/* Object size */
1083f289c3fSJeff Roberson 	struct domainset_ref domain;	/* NUMA policy. */
10967d0e293SJeff Roberson 	volatile int generation;	/* generation ID */
11067d0e293SJeff Roberson 	int cleangeneration;		/* Generation at clean time */
11151df5321SJeff Roberson 	volatile u_int ref_count;	/* How many refs?? */
112de5f6a77SJohn Dyson 	int shadow_count;		/* how many objects that this is a shadow for */
1133153e878SAlan Cox 	vm_memattr_t memattr;		/* default memory attribute for pages */
1146877f580SAlan Cox 	objtype_t type;			/* type of pager */
115a1f6d91cSDavid Greenman 	u_short flags;			/* see below */
11679660d83SAlan Cox 	u_short pg_color;		/* (c) color of first page in obj */
117c99d0c58SMark Johnston 	blockcount_t paging_in_progress; /* (a) Paging (in or out) so don't collapse or destroy */
118c99d0c58SMark Johnston 	blockcount_t busy;		/* (a) object is busy, disallow page busy. */
119a1f6d91cSDavid Greenman 	int resident_page_count;	/* number of resident pages */
12024a1cce3SDavid Greenman 	struct vm_object *backing_object; /* object that I'm a shadow of */
121a316d390SJohn Dyson 	vm_ooffset_t backing_object_offset;/* Offset in backing object */
122e3975643SJake Burkholder 	TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */
1233df92083SAlan Cox 	LIST_HEAD(, vm_reserv) rvq;	/* list of reservations */
12424a1cce3SDavid Greenman 	void *handle;
12524a1cce3SDavid Greenman 	union {
1261c7c3c6aSMatthew Dillon 		/*
1271c7c3c6aSMatthew Dillon 		 * VNode pager
1281c7c3c6aSMatthew Dillon 		 *
1291c7c3c6aSMatthew Dillon 		 *	vnp_size - current size of file
1301c7c3c6aSMatthew Dillon 		 */
13124a1cce3SDavid Greenman 		struct {
1321c7c3c6aSMatthew Dillon 			off_t vnp_size;
13384110e7eSKonstantin Belousov 			vm_ooffset_t writemappings;
13424a1cce3SDavid Greenman 		} vnp;
1351c7c3c6aSMatthew Dillon 
1361c7c3c6aSMatthew Dillon 		/*
1371c7c3c6aSMatthew Dillon 		 * Device pager
1381c7c3c6aSMatthew Dillon 		 *
1391c7c3c6aSMatthew Dillon 		 *	devp_pglist - list of allocated pages
1401c7c3c6aSMatthew Dillon 		 */
14124a1cce3SDavid Greenman 		struct {
142e3975643SJake Burkholder 			TAILQ_HEAD(, vm_page) devp_pglist;
143d474440aSKonstantin Belousov 			const struct cdev_pager_ops *ops;
14443ab9660SKenneth D. Merry 			struct cdev *dev;
14524a1cce3SDavid Greenman 		} devp;
1461c7c3c6aSMatthew Dillon 
14724964514SPeter Wemm 		/*
14801381811SJohn Baldwin 		 * SG pager
14901381811SJohn Baldwin 		 *
15001381811SJohn Baldwin 		 *	sgp_pglist - list of allocated pages
15101381811SJohn Baldwin 		 */
15201381811SJohn Baldwin 		struct {
15301381811SJohn Baldwin 			TAILQ_HEAD(, vm_page) sgp_pglist;
15401381811SJohn Baldwin 		} sgp;
15501381811SJohn Baldwin 
15601381811SJohn Baldwin 		/*
1571c7c3c6aSMatthew Dillon 		 * Swap pager
1581c7c3c6aSMatthew Dillon 		 *
159d9dc64f1SKonstantin Belousov 		 *	swp_priv - pager-private.
160f425ab8eSKonstantin Belousov 		 *	swp_blks - pc-trie of the allocated swap blocks.
161d9dc64f1SKonstantin Belousov 		 *	writemappings - count of bytes mapped for write
162f425ab8eSKonstantin Belousov 		 *
1631c7c3c6aSMatthew Dillon 		 */
1642a4895f4SDavid Greenman 		struct {
165d9dc64f1SKonstantin Belousov 			void *swp_priv;
166f425ab8eSKonstantin Belousov 			struct pctrie swp_blks;
167fe7bcbafSKyle Evans 			vm_ooffset_t writemappings;
1682a4895f4SDavid Greenman 		} swp;
169a720b31cSKonstantin Belousov 
170a720b31cSKonstantin Belousov 		/*
171a720b31cSKonstantin Belousov 		 * Phys pager
172a720b31cSKonstantin Belousov 		 */
173a720b31cSKonstantin Belousov 		struct {
174d474440aSKonstantin Belousov 			const struct phys_pager_ops *ops;
175a720b31cSKonstantin Belousov 			union {
176a720b31cSKonstantin Belousov 				void *data_ptr;
177a720b31cSKonstantin Belousov 				uintptr_t data_val;
178a720b31cSKonstantin Belousov 			};
179a720b31cSKonstantin Belousov 		} phys;
18024a1cce3SDavid Greenman 	} un_pager;
181ef694c1aSEdward Tomasz Napierala 	struct ucred *cred;
1823364c323SKonstantin Belousov 	vm_ooffset_t charge;
1831bdbd705SKonstantin Belousov 	void *umtx_data;
184df8bae1dSRodney W. Grimes };
1850d94caffSDavid Greenman 
186df8bae1dSRodney W. Grimes /*
187df8bae1dSRodney W. Grimes  * Flags
188df8bae1dSRodney W. Grimes  */
18928634820SAlan Cox #define	OBJ_FICTITIOUS	0x0001		/* (c) contains fictitious pages */
19028634820SAlan Cox #define	OBJ_UNMANAGED	0x0002		/* (c) contains unmanaged pages */
191c42b43a0SKonstantin Belousov #define	OBJ_POPULATE	0x0004		/* pager implements populate() */
19224a1cce3SDavid Greenman #define	OBJ_DEAD	0x0008		/* dead objects (during rundown) */
19363967687SJeff Roberson #define	OBJ_ANON	0x0010		/* (c) contains anonymous memory */
1941bdbd705SKonstantin Belousov #define	OBJ_UMTXDEAD	0x0020		/* umtx pshared was terminated */
195208b81bbSKonstantin Belousov #define	OBJ_SIZEVNLOCK	0x0040		/* lock vnode to check obj size */
1967bbdb843SRuslan Bukin #define	OBJ_PG_DTOR	0x0080		/* dont reset object, leave that for dtor */
197128e2584SMateusz Guzik #define	OBJ_SHADOWLIST	0x0100		/* Object is on the shadow list. */
1985d32157dSMark Johnston #define	OBJ_SWAP	0x0200		/* object swaps, type will be OBJT_SWAP
1995d32157dSMark Johnston 					   or dynamically registered */
20098087a06SJeff Roberson #define	OBJ_SPLIT	0x0400		/* object is being split */
20198087a06SJeff Roberson #define	OBJ_COLLAPSING	0x0800		/* Parent of collapse. */
2023df92083SAlan Cox #define	OBJ_COLORED	0x1000		/* pg_color is defined */
203c0877f10SJohn Dyson #define	OBJ_ONEMAPPING	0x2000		/* One USE (a single, non-forked) mapping flag */
204128e2584SMateusz Guzik #define	OBJ_PAGERPRIV1	0x4000		/* Pager private */
205128e2584SMateusz Guzik #define	OBJ_PAGERPRIV2	0x8000		/* Pager private */
2061efb74fbSJohn Dyson 
207987ff181SKonstantin Belousov /*
208987ff181SKonstantin Belousov  * Helpers to perform conversion between vm_object page indexes and offsets.
209987ff181SKonstantin Belousov  * IDX_TO_OFF() converts an index into an offset.
21010d9120cSKonstantin Belousov  * OFF_TO_IDX() converts an offset into an index.
211987ff181SKonstantin Belousov  * OBJ_MAX_SIZE specifies the maximum page index corresponding to the
212987ff181SKonstantin Belousov  *   maximum unsigned offset.
213987ff181SKonstantin Belousov  */
214a316d390SJohn Dyson #define	IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
215a316d390SJohn Dyson #define	OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
21610d9120cSKonstantin Belousov #define	OBJ_MAX_SIZE	(OFF_TO_IDX(UINT64_MAX) + 1)
217df8bae1dSRodney W. Grimes 
218c4473420SPeter Wemm #ifdef	_KERNEL
219b5e8ce9fSBruce Evans 
2208f9110f6SJohn Dyson #define OBJPC_SYNC	0x1			/* sync I/O */
2218f9110f6SJohn Dyson #define OBJPC_INVAL	0x2			/* invalidate */
222fff5403fSJeff Roberson #define OBJPC_NOSYNC	0x4			/* skip if PGA_NOSYNC */
2238f9110f6SJohn Dyson 
2246bbee8e2SAlan Cox /*
2256bbee8e2SAlan Cox  * The following options are supported by vm_object_page_remove().
2266bbee8e2SAlan Cox  */
2276bbee8e2SAlan Cox #define	OBJPR_CLEANONLY	0x1		/* Don't remove dirty pages. */
2286bbee8e2SAlan Cox #define	OBJPR_NOTMAPPED	0x2		/* Don't unmap pages. */
229d28af1abSMark Johnston #define	OBJPR_VALIDONLY	0x4		/* Ignore invalid pages. */
2306bbee8e2SAlan Cox 
231e3975643SJake Burkholder TAILQ_HEAD(object_q, vm_object);
232df8bae1dSRodney W. Grimes 
23328f8db14SBruce Evans extern struct object_q vm_object_list;	/* list of allocated objects */
234a5698387SAlan Cox extern struct mtx vm_object_list_mtx;	/* lock for object list and count */
2350d94caffSDavid Greenman 
236cccf11b8SAlan Cox extern struct vm_object kernel_object_store;
237cccf11b8SAlan Cox 
2382e47807cSJeff Roberson /* kernel and kmem are aliased for backwards KPI compat. */
239cccf11b8SAlan Cox #define	kernel_object	(&kernel_object_store)
2402e47807cSJeff Roberson #define	kmem_object	(&kernel_object_store)
241df8bae1dSRodney W. Grimes 
24289f6b863SAttilio Rao #define	VM_OBJECT_ASSERT_LOCKED(object)					\
24389f6b863SAttilio Rao 	rw_assert(&(object)->lock, RA_LOCKED)
24489f6b863SAttilio Rao #define	VM_OBJECT_ASSERT_RLOCKED(object)				\
24589f6b863SAttilio Rao 	rw_assert(&(object)->lock, RA_RLOCKED)
24689f6b863SAttilio Rao #define	VM_OBJECT_ASSERT_WLOCKED(object)				\
24789f6b863SAttilio Rao 	rw_assert(&(object)->lock, RA_WLOCKED)
248faaf5447SKonstantin Belousov #define	VM_OBJECT_ASSERT_UNLOCKED(object)				\
249faaf5447SKonstantin Belousov 	rw_assert(&(object)->lock, RA_UNLOCKED)
2509af6d512SAttilio Rao #define	VM_OBJECT_LOCK_DOWNGRADE(object)				\
2519af6d512SAttilio Rao 	rw_downgrade(&(object)->lock)
25289f6b863SAttilio Rao #define	VM_OBJECT_RLOCK(object)						\
25389f6b863SAttilio Rao 	rw_rlock(&(object)->lock)
25489f6b863SAttilio Rao #define	VM_OBJECT_RUNLOCK(object)					\
25589f6b863SAttilio Rao 	rw_runlock(&(object)->lock)
2560dde287bSAttilio Rao #define	VM_OBJECT_SLEEP(object, wchan, pri, wmesg, timo)		\
25789f6b863SAttilio Rao 	rw_sleep((wchan), &(object)->lock, (pri), (wmesg), (timo))
25889f6b863SAttilio Rao #define	VM_OBJECT_TRYRLOCK(object)					\
25989f6b863SAttilio Rao 	rw_try_rlock(&(object)->lock)
26089f6b863SAttilio Rao #define	VM_OBJECT_TRYWLOCK(object)					\
26189f6b863SAttilio Rao 	rw_try_wlock(&(object)->lock)
262faaf5447SKonstantin Belousov #define	VM_OBJECT_TRYUPGRADE(object)					\
263faaf5447SKonstantin Belousov 	rw_try_upgrade(&(object)->lock)
26489f6b863SAttilio Rao #define	VM_OBJECT_WLOCK(object)						\
26589f6b863SAttilio Rao 	rw_wlock(&(object)->lock)
266b0cd2017SGleb Smirnoff #define	VM_OBJECT_WOWNED(object)					\
267b0cd2017SGleb Smirnoff 	rw_wowned(&(object)->lock)
26889f6b863SAttilio Rao #define	VM_OBJECT_WUNLOCK(object)					\
26989f6b863SAttilio Rao 	rw_wunlock(&(object)->lock)
270*bdfd1adcSMateusz Guzik #define	VM_OBJECT_UNLOCK(object)					\
271*bdfd1adcSMateusz Guzik 	rw_unlock(&(object)->lock)
2724153054aSJeff Roberson #define	VM_OBJECT_DROP(object)						\
2734153054aSJeff Roberson 	lock_class_rw.lc_unlock(&(object)->lock.lock_object)
2744153054aSJeff Roberson #define	VM_OBJECT_PICKUP(object, state)					\
2754153054aSJeff Roberson 	lock_class_rw.lc_lock(&(object)->lock.lock_object, (state))
276fdff4160SAlan Cox 
277d6e13f3bSJeff Roberson #define	VM_OBJECT_ASSERT_PAGING(object)					\
278c99d0c58SMark Johnston 	KASSERT(blockcount_read(&(object)->paging_in_progress) != 0,	\
279d6e13f3bSJeff Roberson 	    ("vm_object %p is not paging", object))
280d6e13f3bSJeff Roberson #define	VM_OBJECT_ASSERT_REFERENCE(object)				\
281d6e13f3bSJeff Roberson 	KASSERT((object)->reference_count != 0,				\
282d6e13f3bSJeff Roberson 	    ("vm_object %p is not referenced", object))
283d6e13f3bSJeff Roberson 
2845e38e3f5SEric van Gyzen struct vnode;
2855e38e3f5SEric van Gyzen 
2863b9a4cb6SAlan Cox /*
2873b9a4cb6SAlan Cox  *	The object must be locked or thread private.
2883b9a4cb6SAlan Cox  */
2893b9a4cb6SAlan Cox static __inline void
2903b9a4cb6SAlan Cox vm_object_set_flag(vm_object_t object, u_short bits)
2913b9a4cb6SAlan Cox {
2923b9a4cb6SAlan Cox 
2933b9a4cb6SAlan Cox 	object->flags |= bits;
2943b9a4cb6SAlan Cox }
2953b9a4cb6SAlan Cox 
2963d653db0SAlan Cox /*
2973d653db0SAlan Cox  *	Conditionally set the object's color, which (1) enables the allocation
2983d653db0SAlan Cox  *	of physical memory reservations for anonymous objects and larger-than-
2993d653db0SAlan Cox  *	superpage-sized named objects and (2) determines the first page offset
3003d653db0SAlan Cox  *	within the object at which a reservation may be allocated.  In other
3013d653db0SAlan Cox  *	words, the color determines the alignment of the object with respect
3023d653db0SAlan Cox  *	to the largest superpage boundary.  When mapping named objects, like
3033d653db0SAlan Cox  *	files or POSIX shared memory objects, the color should be set to zero
3043d653db0SAlan Cox  *	before a virtual address is selected for the mapping.  In contrast,
3053d653db0SAlan Cox  *	for anonymous objects, the color may be set after the virtual address
3063d653db0SAlan Cox  *	is selected.
3073d653db0SAlan Cox  *
3083d653db0SAlan Cox  *	The object must be locked.
3093d653db0SAlan Cox  */
3103d653db0SAlan Cox static __inline void
3113d653db0SAlan Cox vm_object_color(vm_object_t object, u_short color)
3123d653db0SAlan Cox {
3133d653db0SAlan Cox 
3143d653db0SAlan Cox 	if ((object->flags & OBJ_COLORED) == 0) {
3153d653db0SAlan Cox 		object->pg_color = color;
316630f633fSMark Johnston 		vm_object_set_flag(object, OBJ_COLORED);
3173d653db0SAlan Cox 	}
3183d653db0SAlan Cox }
3193d653db0SAlan Cox 
320e2068d0bSJeff Roberson static __inline bool
321e2068d0bSJeff Roberson vm_object_reserv(vm_object_t object)
322e2068d0bSJeff Roberson {
323e2068d0bSJeff Roberson 
324e2068d0bSJeff Roberson 	if (object != NULL &&
325e2068d0bSJeff Roberson 	    (object->flags & (OBJ_COLORED | OBJ_FICTITIOUS)) == OBJ_COLORED) {
326e2068d0bSJeff Roberson 		return (true);
327e2068d0bSJeff Roberson 	}
328e2068d0bSJeff Roberson 	return (false);
329e2068d0bSJeff Roberson }
330e2068d0bSJeff Roberson 
3311b40f8c0SMatthew Dillon void vm_object_clear_flag(vm_object_t object, u_short bits);
3321b40f8c0SMatthew Dillon void vm_object_pip_add(vm_object_t object, short i);
3331b40f8c0SMatthew Dillon void vm_object_pip_wakeup(vm_object_t object);
3341b40f8c0SMatthew Dillon void vm_object_pip_wakeupn(vm_object_t object, short i);
335eaa17d42SRyan Libby void vm_object_pip_wait(vm_object_t object, const char *waitid);
336eaa17d42SRyan Libby void vm_object_pip_wait_unlocked(vm_object_t object, const char *waitid);
337069e9bc1SDoug Rabson 
338205be21dSJeff Roberson void vm_object_busy(vm_object_t object);
339205be21dSJeff Roberson void vm_object_unbusy(vm_object_t object);
340205be21dSJeff Roberson void vm_object_busy_wait(vm_object_t object, const char *wmesg);
341205be21dSJeff Roberson 
342205be21dSJeff Roberson static inline bool
343205be21dSJeff Roberson vm_object_busied(vm_object_t object)
344205be21dSJeff Roberson {
345205be21dSJeff Roberson 
346c99d0c58SMark Johnston 	return (blockcount_read(&object->busy) != 0);
347205be21dSJeff Roberson }
348205be21dSJeff Roberson #define	VM_OBJECT_ASSERT_BUSY(object)	MPASS(vm_object_busied((object)))
349205be21dSJeff Roberson 
3501bdbd705SKonstantin Belousov void umtx_shm_object_init(vm_object_t object);
3511bdbd705SKonstantin Belousov void umtx_shm_object_terminated(vm_object_t object);
3522a339d9eSKonstantin Belousov extern int umtx_shm_vnobj_persistent;
3531bdbd705SKonstantin Belousov 
3546395da54SIan Dowse vm_object_t vm_object_allocate (objtype_t, vm_pindex_t);
35567388836SKonstantin Belousov vm_object_t vm_object_allocate_anon(vm_pindex_t, vm_object_t, struct ucred *,
35667388836SKonstantin Belousov    vm_size_t);
357b730fd30SKonstantin Belousov vm_object_t vm_object_allocate_dyn(objtype_t, vm_pindex_t, u_short);
3583364c323SKonstantin Belousov boolean_t vm_object_coalesce(vm_object_t, vm_ooffset_t, vm_size_t, vm_size_t,
3593364c323SKonstantin Belousov    boolean_t);
3601b40f8c0SMatthew Dillon void vm_object_collapse (vm_object_t);
3611b40f8c0SMatthew Dillon void vm_object_deallocate (vm_object_t);
3622ac78f0eSStephan Uphoff void vm_object_destroy (vm_object_t);
3631b40f8c0SMatthew Dillon void vm_object_terminate (vm_object_t);
364245df27cSMatthew Dillon void vm_object_set_writeable_dirty (vm_object_t);
365180bcaa4SKonstantin Belousov void vm_object_set_writeable_dirty_(vm_object_t object);
366c23c555bSKonstantin Belousov bool vm_object_mightbedirty(vm_object_t object);
367c23c555bSKonstantin Belousov bool vm_object_mightbedirty_(vm_object_t object);
3681b40f8c0SMatthew Dillon void vm_object_init (void);
3695e38e3f5SEric van Gyzen int  vm_object_kvme_type(vm_object_t object, struct vnode **vpp);
37092a59946SJohn Baldwin void vm_object_madvise(vm_object_t, vm_pindex_t, vm_pindex_t, int);
371126d6082SKonstantin Belousov boolean_t vm_object_page_clean(vm_object_t object, vm_ooffset_t start,
37217f3095dSAlan Cox     vm_ooffset_t end, int flags);
3733138cd36SMark Johnston void vm_object_page_noreuse(vm_object_t object, vm_pindex_t start,
3743138cd36SMark Johnston     vm_pindex_t end);
3756bbee8e2SAlan Cox void vm_object_page_remove(vm_object_t object, vm_pindex_t start,
3766bbee8e2SAlan Cox     vm_pindex_t end, int options);
377387aabc5SAlan Cox boolean_t vm_object_populate(vm_object_t, vm_pindex_t, vm_pindex_t);
3784de22619SAlan Cox void vm_object_print(long addr, boolean_t have_addr, long count, char *modif);
3791b40f8c0SMatthew Dillon void vm_object_reference (vm_object_t);
380b921a12bSAlan Cox void vm_object_reference_locked(vm_object_t);
3813153e878SAlan Cox int  vm_object_set_memattr(vm_object_t object, vm_memattr_t memattr);
38267388836SKonstantin Belousov void vm_object_shadow(vm_object_t *, vm_ooffset_t *, vm_size_t, struct ucred *,
38367388836SKonstantin Belousov     bool);
384c5aaa06dSAlan Cox void vm_object_split(vm_map_entry_t);
385126d6082SKonstantin Belousov boolean_t vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t,
386950f8459SAlan Cox     boolean_t);
38703462509SAlan Cox void vm_object_unwire(vm_object_t object, vm_ooffset_t offset,
38803462509SAlan Cox     vm_size_t length, uint8_t queue);
38963e4c6cdSEric van Gyzen struct vnode *vm_object_vnode(vm_object_t object);
390cd37afd8SRick Macklem bool vm_object_is_active(vm_object_t obj);
391c4473420SPeter Wemm #endif				/* _KERNEL */
3920d94caffSDavid Greenman 
393df8bae1dSRodney W. Grimes #endif				/* _VM_OBJECT_ */
394