xref: /freebsd/sys/vm/vm_page.h (revision d98d0ce27a3c2f0886b681d1aec0a8e70a17c3af)
160727d8bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
6df8bae1dSRodney W. Grimes  * The Mach Operating System project at Carnegie-Mellon University.
7df8bae1dSRodney W. Grimes  *
8df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
9df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
10df8bae1dSRodney W. Grimes  * are met:
11df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
12df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
13df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
15df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
16df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
17df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
18df8bae1dSRodney W. Grimes  *    without specific prior written permission.
19df8bae1dSRodney W. Grimes  *
20df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
31df8bae1dSRodney W. Grimes  *
323c4dd356SDavid Greenman  *	from: @(#)vm_page.h	8.2 (Berkeley) 12/13/93
33df8bae1dSRodney W. Grimes  *
34df8bae1dSRodney W. Grimes  *
35df8bae1dSRodney W. Grimes  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
36df8bae1dSRodney W. Grimes  * All rights reserved.
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
39df8bae1dSRodney W. Grimes  *
40df8bae1dSRodney W. Grimes  * Permission to use, copy, modify and distribute this software and
41df8bae1dSRodney W. Grimes  * its documentation is hereby granted, provided that both the copyright
42df8bae1dSRodney W. Grimes  * notice and this permission notice appear in all copies of the
43df8bae1dSRodney W. Grimes  * software, derivative works or modified versions, and any portions
44df8bae1dSRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
45df8bae1dSRodney W. Grimes  *
46df8bae1dSRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47df8bae1dSRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48df8bae1dSRodney W. Grimes  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49df8bae1dSRodney W. Grimes  *
50df8bae1dSRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
51df8bae1dSRodney W. Grimes  *
52df8bae1dSRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
53df8bae1dSRodney W. Grimes  *  School of Computer Science
54df8bae1dSRodney W. Grimes  *  Carnegie Mellon University
55df8bae1dSRodney W. Grimes  *  Pittsburgh PA 15213-3890
56df8bae1dSRodney W. Grimes  *
57df8bae1dSRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
58df8bae1dSRodney W. Grimes  * rights to redistribute these changes.
593c4dd356SDavid Greenman  *
60c3aac50fSPeter Wemm  * $FreeBSD$
61df8bae1dSRodney W. Grimes  */
62df8bae1dSRodney W. Grimes 
63df8bae1dSRodney W. Grimes /*
64df8bae1dSRodney W. Grimes  *	Resident memory system definitions.
65df8bae1dSRodney W. Grimes  */
66df8bae1dSRodney W. Grimes 
67df8bae1dSRodney W. Grimes #ifndef	_VM_PAGE_
68df8bae1dSRodney W. Grimes #define	_VM_PAGE_
69df8bae1dSRodney W. Grimes 
70f919ebdeSDavid Greenman #include <vm/pmap.h>
71069e9bc1SDoug Rabson 
72df8bae1dSRodney W. Grimes /*
73df8bae1dSRodney W. Grimes  *	Management of resident (logical) pages.
74df8bae1dSRodney W. Grimes  *
75df8bae1dSRodney W. Grimes  *	A small structure is kept for each resident
76df8bae1dSRodney W. Grimes  *	page, indexed by page number.  Each structure
77df8bae1dSRodney W. Grimes  *	is an element of several lists:
78df8bae1dSRodney W. Grimes  *
79df8bae1dSRodney W. Grimes  *		A hash table bucket used to quickly
80df8bae1dSRodney W. Grimes  *		perform object/offset lookups
81df8bae1dSRodney W. Grimes  *
82df8bae1dSRodney W. Grimes  *		A list of all pages for a given object,
83df8bae1dSRodney W. Grimes  *		so they can be quickly deactivated at
84df8bae1dSRodney W. Grimes  *		time of deallocation.
85df8bae1dSRodney W. Grimes  *
86df8bae1dSRodney W. Grimes  *		An ordered list of pages due for pageout.
87df8bae1dSRodney W. Grimes  *
88df8bae1dSRodney W. Grimes  *	In addition, the structure contains the object
89df8bae1dSRodney W. Grimes  *	and offset to which this page belongs (for pageout),
90df8bae1dSRodney W. Grimes  *	and sundry status bits.
91df8bae1dSRodney W. Grimes  *
923c76db4cSAlan Cox  *	In general, operations on this structure's mutable fields are
933c76db4cSAlan Cox  *	synchronized using either one of or a combination of the lock on the
943c76db4cSAlan Cox  *	object that the page belongs to (O), the pool lock for the page (P),
953c76db4cSAlan Cox  *	or the lock for either the free or paging queues (Q).  If a field is
963c76db4cSAlan Cox  *	annotated below with two of these locks, then holding either lock is
973c76db4cSAlan Cox  *	sufficient for read access, but both locks are required for write
983c76db4cSAlan Cox  *	access.
990ce3ba8cSKip Macy  *
1003c76db4cSAlan Cox  *	In contrast, the synchronization of accesses to the page's dirty field
1013c76db4cSAlan Cox  *	is machine dependent (M).  In the machine-independent layer, the lock
1023c76db4cSAlan Cox  *	on the object that the page belongs to must be held in order to
1033c76db4cSAlan Cox  *	operate on the field.  However, the pmap layer is permitted to set
1043c76db4cSAlan Cox  *	all bits within the field without holding that lock.  Therefore, if
1053c76db4cSAlan Cox  *	the underlying architecture does not support atomic read-modify-write
1063c76db4cSAlan Cox  *	operations on the field's type, then the machine-independent layer
1073c76db4cSAlan Cox  *	must also hold the page queues lock when performing read-modify-write
1083c76db4cSAlan Cox  *	operations and the pmap layer must hold the page queues lock when
1093c76db4cSAlan Cox  *	setting the field.  In the machine-independent layer, the
1103c76db4cSAlan Cox  *	implementation of read-modify-write operations on the field is
1113c76db4cSAlan Cox  *	encapsulated in vm_page_clear_dirty_mask().
112df8bae1dSRodney W. Grimes  */
113df8bae1dSRodney W. Grimes 
114e3975643SJake Burkholder TAILQ_HEAD(pglist, vm_page);
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes struct vm_page {
1170ce3ba8cSKip Macy 	TAILQ_ENTRY(vm_page) pageq;	/* queue info for FIFO queue or free list (Q) */
118e3975643SJake Burkholder 	TAILQ_ENTRY(vm_page) listq;	/* pages in same object (O) 	*/
119b86ec922SMatthew Dillon 	struct vm_page *left;		/* splay tree link (O)		*/
120b86ec922SMatthew Dillon 	struct vm_page *right;		/* splay tree link (O)		*/
121df8bae1dSRodney W. Grimes 
1225ac59343SAlan Cox 	vm_object_t object;		/* which object am I in (O,P)*/
12343319c11SAlan Cox 	vm_pindex_t pindex;		/* offset into object (O,P) */
124227f9a1cSJake Burkholder 	vm_paddr_t phys_addr;		/* physical address of page */
1250385347cSPeter Wemm 	struct md_page md;		/* machine dependant stuff */
1267024db1dSAlan Cox 	uint8_t	queue;			/* page queue index (P,Q) */
1272446e4f0SAlan Cox 	int8_t segind;
1282446e4f0SAlan Cox 	u_short	flags;			/* see below */
1292446e4f0SAlan Cox 	uint8_t	order;			/* index of the buddy queue */
1302446e4f0SAlan Cox 	uint8_t pool;
131b2775308SAlan Cox 	u_short cow;			/* page cow mapping count (P) */
132fd8c28bfSAlan Cox 	u_int wire_count;		/* wired down maps refs (P) */
1330ce3ba8cSKip Macy 	short hold_count;		/* page hold count (P) */
1345786be7cSAlan Cox 	u_short oflags;			/* page flags (O) */
1354c6a2e7aSAlan Cox 	u_char	act_count;		/* page usage count (O) */
13691f7a860SAlan Cox 	u_char	busy;			/* page busy count (O) */
137bd7e5f99SJohn Dyson 	/* NOTE that these must support one bit per DEV_BSIZE in a page!!! */
138bd7e5f99SJohn Dyson 	/* so, on normal X86 kernels, they must be at least 8 bits wide */
1393c76db4cSAlan Cox 	/* In reality, support for 32KB pages is not fully implemented. */
140ecbb00a2SDoug Rabson #if PAGE_SIZE == 4096
14193dbd071SAlan Cox 	u_char	valid;			/* map of valid DEV_BSIZE chunks (O) */
1423c76db4cSAlan Cox 	u_char	dirty;			/* map of dirty DEV_BSIZE chunks (M) */
143ecbb00a2SDoug Rabson #elif PAGE_SIZE == 8192
14493dbd071SAlan Cox 	u_short	valid;			/* map of valid DEV_BSIZE chunks (O) */
1453c76db4cSAlan Cox 	u_short	dirty;			/* map of dirty DEV_BSIZE chunks (M) */
1461fa057c6SMarcel Moolenaar #elif PAGE_SIZE == 16384
14793dbd071SAlan Cox 	u_int valid;			/* map of valid DEV_BSIZE chunks (O) */
1483c76db4cSAlan Cox 	u_int dirty;			/* map of dirty DEV_BSIZE chunks (M) */
1491fa057c6SMarcel Moolenaar #elif PAGE_SIZE == 32768
15093dbd071SAlan Cox 	u_long valid;			/* map of valid DEV_BSIZE chunks (O) */
1513c76db4cSAlan Cox 	u_long dirty;			/* map of dirty DEV_BSIZE chunks (M) */
152ecbb00a2SDoug Rabson #endif
153df8bae1dSRodney W. Grimes };
154df8bae1dSRodney W. Grimes 
1555786be7cSAlan Cox /*
1565786be7cSAlan Cox  * Page flags stored in oflags:
1575786be7cSAlan Cox  *
1585786be7cSAlan Cox  * Access to these page flags is synchronized by the lock on the object
1595786be7cSAlan Cox  * containing the page (O).
160*d98d0ce2SKonstantin Belousov  *
161*d98d0ce2SKonstantin Belousov  * Note: VPO_UNMANAGED (used by OBJT_DEVICE, OBJT_PHYS and OBJT_SG)
162*d98d0ce2SKonstantin Belousov  * 	 indicates that the page is not under PV management but
163*d98d0ce2SKonstantin Belousov  * 	 otherwise should be treated as a normal page.  Pages not
164*d98d0ce2SKonstantin Belousov  * 	 under PV management cannot be paged out via the
165*d98d0ce2SKonstantin Belousov  * 	 object/vm_page_t because there is no knowledge of their pte
166*d98d0ce2SKonstantin Belousov  * 	 mappings, and such pages are also not on any PQ queue.
167*d98d0ce2SKonstantin Belousov  *
1685786be7cSAlan Cox  */
1699af80719SAlan Cox #define	VPO_BUSY	0x0001	/* page is in transit */
1705786be7cSAlan Cox #define	VPO_WANTED	0x0002	/* someone is waiting for page */
171*d98d0ce2SKonstantin Belousov #define	VPO_UNMANAGED	0x0004		/* No PV management for page */
1725786be7cSAlan Cox #define	VPO_SWAPINPROG	0x0200	/* swap I/O in progress on page */
173b146f9e5SAlan Cox #define	VPO_NOSYNC	0x0400	/* do not collect for syncer */
1745786be7cSAlan Cox 
17544e46b9eSAlan Cox #define	PQ_NONE		255
17644e46b9eSAlan Cox #define	PQ_INACTIVE	0
17744e46b9eSAlan Cox #define	PQ_ACTIVE	1
17844e46b9eSAlan Cox #define	PQ_HOLD		2
17944e46b9eSAlan Cox #define	PQ_COUNT	3
180ef39c05bSAlexander Leidinger 
181be72f788SAlan Cox struct vpgqueues {
182be72f788SAlan Cox 	struct pglist pl;
1835070c7f8SJohn Dyson 	int	*cnt;
184ef39c05bSAlexander Leidinger };
18570c17636SAlan Cox 
1861fa94a36SAlan Cox extern struct vpgqueues vm_page_queues[PQ_COUNT];
187e67e0775SAlan Cox 
188e67e0775SAlan Cox struct vpglocks {
189e67e0775SAlan Cox 	struct mtx	data;
190e67e0775SAlan Cox 	char		pad[CACHE_LINE_SIZE - sizeof(struct mtx)];
191e67e0775SAlan Cox } __aligned(CACHE_LINE_SIZE);
192e67e0775SAlan Cox 
193e67e0775SAlan Cox extern struct vpglocks vm_page_queue_free_lock;
1942965a453SKip Macy extern struct vpglocks pa_lock[];
1952965a453SKip Macy 
1962965a453SKip Macy #if defined(__arm__)
1972965a453SKip Macy #define	PDRSHIFT	PDR_SHIFT
1982965a453SKip Macy #elif !defined(PDRSHIFT)
1992965a453SKip Macy #define PDRSHIFT	21
2002965a453SKip Macy #endif
2012965a453SKip Macy 
2022965a453SKip Macy #define	pa_index(pa)	((pa) >> PDRSHIFT)
2032965a453SKip Macy #define	PA_LOCKPTR(pa)	&pa_lock[pa_index((pa)) % PA_LOCK_COUNT].data
2042965a453SKip Macy #define	PA_LOCKOBJPTR(pa)	((struct lock_object *)PA_LOCKPTR((pa)))
2052965a453SKip Macy #define	PA_LOCK(pa)	mtx_lock(PA_LOCKPTR(pa))
2062965a453SKip Macy #define	PA_TRYLOCK(pa)	mtx_trylock(PA_LOCKPTR(pa))
2072965a453SKip Macy #define	PA_UNLOCK(pa)	mtx_unlock(PA_LOCKPTR(pa))
2082965a453SKip Macy #define	PA_UNLOCK_COND(pa) 			\
2092965a453SKip Macy 	do {		   			\
210567e51e1SAlan Cox 		if ((pa) != 0) {		\
211567e51e1SAlan Cox 			PA_UNLOCK((pa));	\
212567e51e1SAlan Cox 			(pa) = 0;		\
213567e51e1SAlan Cox 		}				\
2142965a453SKip Macy 	} while (0)
2152965a453SKip Macy 
2162965a453SKip Macy #define	PA_LOCK_ASSERT(pa, a)	mtx_assert(PA_LOCKPTR(pa), (a))
2172965a453SKip Macy 
2182965a453SKip Macy #define	vm_page_lockptr(m)	(PA_LOCKPTR(VM_PAGE_TO_PHYS((m))))
2192965a453SKip Macy #define	vm_page_lock(m)		mtx_lock(vm_page_lockptr((m)))
2202965a453SKip Macy #define	vm_page_unlock(m)	mtx_unlock(vm_page_lockptr((m)))
2212965a453SKip Macy #define	vm_page_trylock(m)	mtx_trylock(vm_page_lockptr((m)))
2222965a453SKip Macy #define	vm_page_lock_assert(m, a)	mtx_assert(vm_page_lockptr((m)), (a))
223e67e0775SAlan Cox 
224e67e0775SAlan Cox #define	vm_page_queue_free_mtx	vm_page_queue_free_lock.data
225df8bae1dSRodney W. Grimes /*
226df8bae1dSRodney W. Grimes  * These are the flags defined for vm_page.
227df8bae1dSRodney W. Grimes  *
228ce186587SAlan Cox  * PG_REFERENCED may be cleared only if the object containing the page is
229ce186587SAlan Cox  * locked.
230ce186587SAlan Cox  *
2318f0d5d3bSAlan Cox  * PG_WRITEABLE is set exclusively on managed pages by pmap_enter().  When it
2328f0d5d3bSAlan Cox  * does so, the page must be VPO_BUSY.
233df8bae1dSRodney W. Grimes  */
2347bfda801SAlan Cox #define	PG_CACHED	0x0001		/* page is cached */
2352446e4f0SAlan Cox #define	PG_FREE		0x0002		/* page is free */
2362b6b0df7SMatthew Dillon #define PG_WINATCFLS	0x0004		/* flush dirty page on inactive q */
2371c7c3c6aSMatthew Dillon #define	PG_FICTITIOUS	0x0008		/* physical page doesn't exist (O) */
2381c7c3c6aSMatthew Dillon #define	PG_WRITEABLE	0x0010		/* page is mapped writeable */
2391c7c3c6aSMatthew Dillon #define	PG_ZERO		0x0040		/* page is zeroed */
2401c7c3c6aSMatthew Dillon #define PG_REFERENCED	0x0080		/* page has been referenced */
241936524aaSMatthew Dillon #define PG_MARKER	0x1000		/* special queue marker page */
24299571dc3SJeff Roberson #define	PG_SLAB		0x2000		/* object pointer is actually a slab */
243df8bae1dSRodney W. Grimes 
24424a1cce3SDavid Greenman /*
24524a1cce3SDavid Greenman  * Misc constants.
24624a1cce3SDavid Greenman  */
24724a1cce3SDavid Greenman #define ACT_DECLINE		1
24824a1cce3SDavid Greenman #define ACT_ADVANCE		3
24938efa82bSJohn Dyson #define ACT_INIT		5
2505070c7f8SJohn Dyson #define ACT_MAX			64
251df8bae1dSRodney W. Grimes 
252c4473420SPeter Wemm #ifdef _KERNEL
25304a18977SAlan Cox 
25404a18977SAlan Cox #include <vm/vm_param.h>
25504a18977SAlan Cox 
256df8bae1dSRodney W. Grimes /*
2570f752392SAlan Cox  * Each pageable resident page falls into one of five lists:
258df8bae1dSRodney W. Grimes  *
259df8bae1dSRodney W. Grimes  *	free
260df8bae1dSRodney W. Grimes  *		Available for allocation now.
26124a1cce3SDavid Greenman  *
26224a1cce3SDavid Greenman  *	cache
2637bfda801SAlan Cox  *		Almost available for allocation. Still associated with
2647bfda801SAlan Cox  *		an object, but clean and immediately freeable.
26524a1cce3SDavid Greenman  *
2660f752392SAlan Cox  *	hold
2670f752392SAlan Cox  *		Will become free after a pending I/O operation
2680f752392SAlan Cox  *		completes.
2690f752392SAlan Cox  *
2700f752392SAlan Cox  * The following lists are LRU sorted:
2710f752392SAlan Cox  *
272df8bae1dSRodney W. Grimes  *	inactive
2736c5e9bbdSMike Pritchard  *		Low activity, candidates for reclamation.
274df8bae1dSRodney W. Grimes  *		This is the list of pages that should be
275df8bae1dSRodney W. Grimes  *		paged out next.
27624a1cce3SDavid Greenman  *
277df8bae1dSRodney W. Grimes  *	active
27824a1cce3SDavid Greenman  *		Pages that are "active" i.e. they have been
27924a1cce3SDavid Greenman  *		recently referenced.
28010ad4d48SJohn Dyson  *
281df8bae1dSRodney W. Grimes  */
282df8bae1dSRodney W. Grimes 
28349ca10d4SJayachandran C. struct vnode;
284a316d390SJohn Dyson extern int vm_page_zero_count;
285a316d390SJohn Dyson 
2860d94caffSDavid Greenman extern vm_page_t vm_page_array;		/* First resident page in table */
2870385347cSPeter Wemm extern int vm_page_array_size;		/* number of vm_page_t's */
2880d94caffSDavid Greenman extern long first_page;			/* first physical page number */
2890d94caffSDavid Greenman 
2902446e4f0SAlan Cox #define	VM_PAGE_IS_FREE(m)	(((m)->flags & PG_FREE) != 0)
2912446e4f0SAlan Cox 
292df8bae1dSRodney W. Grimes #define VM_PAGE_TO_PHYS(entry)	((entry)->phys_addr)
293df8bae1dSRodney W. Grimes 
2942446e4f0SAlan Cox vm_page_t vm_phys_paddr_to_vm_page(vm_paddr_t pa);
2952446e4f0SAlan Cox 
29604a18977SAlan Cox static __inline vm_page_t PHYS_TO_VM_PAGE(vm_paddr_t pa);
29704a18977SAlan Cox 
29804a18977SAlan Cox static __inline vm_page_t
29904a18977SAlan Cox PHYS_TO_VM_PAGE(vm_paddr_t pa)
30004a18977SAlan Cox {
30104a18977SAlan Cox #ifdef VM_PHYSSEG_SPARSE
3022446e4f0SAlan Cox 	return (vm_phys_paddr_to_vm_page(pa));
30304a18977SAlan Cox #elif defined(VM_PHYSSEG_DENSE)
30404a18977SAlan Cox 	return (&vm_page_array[atop(pa) - first_page]);
30504a18977SAlan Cox #else
30604a18977SAlan Cox #error "Either VM_PHYSSEG_DENSE or VM_PHYSSEG_SPARSE must be defined."
30704a18977SAlan Cox #endif
30804a18977SAlan Cox }
309df8bae1dSRodney W. Grimes 
310e67e0775SAlan Cox extern struct vpglocks vm_page_queue_lock;
311e67e0775SAlan Cox 
312e67e0775SAlan Cox #define	vm_page_queue_mtx	vm_page_queue_lock.data
3131f545269SAlan Cox #define vm_page_lock_queues()   mtx_lock(&vm_page_queue_mtx)
3141f545269SAlan Cox #define vm_page_unlock_queues() mtx_unlock(&vm_page_queue_mtx)
3158f9110f6SJohn Dyson 
3160d94caffSDavid Greenman #if PAGE_SIZE == 4096
31721a708cfSMarcel Moolenaar #define VM_PAGE_BITS_ALL 0xffu
31821a708cfSMarcel Moolenaar #elif PAGE_SIZE == 8192
31921a708cfSMarcel Moolenaar #define VM_PAGE_BITS_ALL 0xffffu
32021a708cfSMarcel Moolenaar #elif PAGE_SIZE == 16384
32121a708cfSMarcel Moolenaar #define VM_PAGE_BITS_ALL 0xffffffffu
32221a708cfSMarcel Moolenaar #elif PAGE_SIZE == 32768
32321a708cfSMarcel Moolenaar #define VM_PAGE_BITS_ALL 0xfffffffffffffffflu
3240d94caffSDavid Greenman #endif
3250d94caffSDavid Greenman 
326827b2fa0SAlan Cox /* page allocation classes: */
3276d40c3d3SDavid Greenman #define VM_ALLOC_NORMAL		0
3286d40c3d3SDavid Greenman #define VM_ALLOC_INTERRUPT	1
3296d40c3d3SDavid Greenman #define VM_ALLOC_SYSTEM		2
330827b2fa0SAlan Cox #define	VM_ALLOC_CLASS_MASK	3
331827b2fa0SAlan Cox /* page allocation flags: */
332026aa839SJeff Roberson #define	VM_ALLOC_WIRED		0x0020	/* non pageable */
333026aa839SJeff Roberson #define	VM_ALLOC_ZERO		0x0040	/* Try to obtain a zeroed page */
3341d9e77f6SKonstantin Belousov #define	VM_ALLOC_RETRY		0x0080	/* Mandatory with vm_page_grab() */
335026aa839SJeff Roberson #define	VM_ALLOC_NOOBJ		0x0100	/* No associated object */
3360f9f9bcbSAlan Cox #define	VM_ALLOC_NOBUSY		0x0200	/* Do not busy the page */
3377bfda801SAlan Cox #define	VM_ALLOC_IFCACHED	0x0400	/* Fail if the page is not cached */
3387bfda801SAlan Cox #define	VM_ALLOC_IFNOTCACHED	0x0800	/* Fail if the page is cached */
3395f195aa3SKonstantin Belousov #define	VM_ALLOC_IGN_SBUSY	0x1000	/* vm_page_grab() only */
3405f195aa3SKonstantin Belousov 
3415f195aa3SKonstantin Belousov #define	VM_ALLOC_COUNT_SHIFT	16
3425f195aa3SKonstantin Belousov #define	VM_ALLOC_COUNT(count)	((count) << VM_ALLOC_COUNT_SHIFT)
3430d94caffSDavid Greenman 
3441b40f8c0SMatthew Dillon void vm_page_flag_set(vm_page_t m, unsigned short bits);
3451b40f8c0SMatthew Dillon void vm_page_flag_clear(vm_page_t m, unsigned short bits);
3461b40f8c0SMatthew Dillon void vm_page_busy(vm_page_t m);
3471b40f8c0SMatthew Dillon void vm_page_flash(vm_page_t m);
3481b40f8c0SMatthew Dillon void vm_page_io_start(vm_page_t m);
3491b40f8c0SMatthew Dillon void vm_page_io_finish(vm_page_t m);
3501b40f8c0SMatthew Dillon void vm_page_hold(vm_page_t mem);
3511b40f8c0SMatthew Dillon void vm_page_unhold(vm_page_t mem);
3521b40f8c0SMatthew Dillon void vm_page_free(vm_page_t m);
3531b40f8c0SMatthew Dillon void vm_page_free_zero(vm_page_t m);
3541b40f8c0SMatthew Dillon void vm_page_dirty(vm_page_t m);
3551b40f8c0SMatthew Dillon void vm_page_wakeup(vm_page_t m);
3561b40f8c0SMatthew Dillon 
3576d03d577SMatthew Dillon void vm_pageq_remove(vm_page_t m);
3586d03d577SMatthew Dillon 
3591b40f8c0SMatthew Dillon void vm_page_activate (vm_page_t);
3601b40f8c0SMatthew Dillon vm_page_t vm_page_alloc (vm_object_t, vm_pindex_t, int);
361aa546366SJayachandran C. vm_page_t vm_page_alloc_freelist(int, int);
36249ca10d4SJayachandran C. struct vnode *vm_page_alloc_init(vm_page_t);
3631b40f8c0SMatthew Dillon vm_page_t vm_page_grab (vm_object_t, vm_pindex_t, int);
364461c7860SAlan Cox void vm_page_cache(vm_page_t);
365c9444914SAlan Cox void vm_page_cache_free(vm_object_t, vm_pindex_t, vm_pindex_t);
3667bfda801SAlan Cox void vm_page_cache_remove(vm_page_t);
3677bfda801SAlan Cox void vm_page_cache_transfer(vm_object_t, vm_pindex_t, vm_object_t);
3681b40f8c0SMatthew Dillon int vm_page_try_to_cache (vm_page_t);
3691b40f8c0SMatthew Dillon int vm_page_try_to_free (vm_page_t);
370461c7860SAlan Cox void vm_page_dontneed(vm_page_t);
3711b40f8c0SMatthew Dillon void vm_page_deactivate (vm_page_t);
372b382c10aSKonstantin Belousov vm_page_t vm_page_find_least(vm_object_t, vm_pindex_t);
37310cf2560SAlan Cox vm_page_t vm_page_getfake(vm_paddr_t paddr, vm_memattr_t memattr);
3741b40f8c0SMatthew Dillon void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t);
3751b40f8c0SMatthew Dillon vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t);
37691b4f427SAlan Cox vm_page_t vm_page_next(vm_page_t m);
3772965a453SKip Macy int vm_page_pa_tryrelock(pmap_t, vm_paddr_t, vm_paddr_t *);
37891b4f427SAlan Cox vm_page_t vm_page_prev(vm_page_t m);
37910cf2560SAlan Cox void vm_page_putfake(vm_page_t m);
3801b40f8c0SMatthew Dillon void vm_page_remove (vm_page_t);
3811b40f8c0SMatthew Dillon void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t);
382e5b006ffSAlan Cox void vm_page_requeue(vm_page_t m);
3831c1b26f2SAlan Cox void vm_page_set_valid(vm_page_t m, int base, int size);
384eb4bbba8SAlan Cox void vm_page_sleep(vm_page_t m, const char *msg);
385ada2a050SAlan Cox vm_page_t vm_page_splay(vm_pindex_t, vm_page_t);
386889eb0fcSAlan Cox vm_offset_t vm_page_startup(vm_offset_t vaddr);
3878c22654dSAlan Cox void vm_page_unhold_pages(vm_page_t *ma, int count);
3881b40f8c0SMatthew Dillon void vm_page_unwire (vm_page_t, int);
38910cf2560SAlan Cox void vm_page_updatefake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr);
3901b40f8c0SMatthew Dillon void vm_page_wire (vm_page_t);
3911b40f8c0SMatthew Dillon void vm_page_set_validclean (vm_page_t, int, int);
3921b40f8c0SMatthew Dillon void vm_page_clear_dirty (vm_page_t, int, int);
3931b40f8c0SMatthew Dillon void vm_page_set_invalid (vm_page_t, int, int);
3941b40f8c0SMatthew Dillon int vm_page_is_valid (vm_page_t, int, int);
3951b40f8c0SMatthew Dillon void vm_page_test_dirty (vm_page_t);
3961b40f8c0SMatthew Dillon int vm_page_bits (int, int);
3978d17e694SJulian Elischer void vm_page_zero_invalid(vm_page_t m, boolean_t setvalid);
398faa273d5SMatthew Dillon void vm_page_free_toq(vm_page_t m);
3993516c025SPeter Wemm void vm_page_zero_idle_wakeup(void);
40098cb733cSKenneth D. Merry void vm_page_cowfault (vm_page_t);
401641e2829SKonstantin Belousov int vm_page_cowsetup(vm_page_t);
40298cb733cSKenneth D. Merry void vm_page_cowclear (vm_page_t);
40398cb733cSKenneth D. Merry 
4043b1025d2SKonstantin Belousov #ifdef INVARIANTS
4053b1025d2SKonstantin Belousov void vm_page_object_lock_assert(vm_page_t m);
4063b1025d2SKonstantin Belousov #define	VM_PAGE_OBJECT_LOCK_ASSERT(m)	vm_page_object_lock_assert(m)
4073b1025d2SKonstantin Belousov #else
4083b1025d2SKonstantin Belousov #define	VM_PAGE_OBJECT_LOCK_ASSERT(m)	(void)0
4093b1025d2SKonstantin Belousov #endif
4103b1025d2SKonstantin Belousov 
411f3b676f0SAlan Cox /*
412eb4bbba8SAlan Cox  *	vm_page_sleep_if_busy:
413eb4bbba8SAlan Cox  *
4149af80719SAlan Cox  *	Sleep and release the page queues lock if VPO_BUSY is set or,
415eb4bbba8SAlan Cox  *	if also_m_busy is TRUE, busy is non-zero.  Returns TRUE if the
416eb4bbba8SAlan Cox  *	thread slept and the page queues lock was released.
417eb4bbba8SAlan Cox  *	Otherwise, retains the page queues lock and returns FALSE.
418eb4bbba8SAlan Cox  *
419eb4bbba8SAlan Cox  *	The object containing the given page must be locked.
420eb4bbba8SAlan Cox  */
421eb4bbba8SAlan Cox static __inline int
422eb4bbba8SAlan Cox vm_page_sleep_if_busy(vm_page_t m, int also_m_busy, const char *msg)
423eb4bbba8SAlan Cox {
424eb4bbba8SAlan Cox 
4259af80719SAlan Cox 	if ((m->oflags & VPO_BUSY) || (also_m_busy && m->busy)) {
426eb4bbba8SAlan Cox 		vm_page_sleep(m, msg);
427eb4bbba8SAlan Cox 		return (TRUE);
428eb4bbba8SAlan Cox 	}
429eb4bbba8SAlan Cox 	return (FALSE);
430eb4bbba8SAlan Cox }
431eb4bbba8SAlan Cox 
432eb4bbba8SAlan Cox /*
433f3b676f0SAlan Cox  *	vm_page_undirty:
434f3b676f0SAlan Cox  *
435f3b676f0SAlan Cox  *	Set page to not be dirty.  Note: does not clear pmap modify bits
436f3b676f0SAlan Cox  */
437f3b676f0SAlan Cox static __inline void
438f3b676f0SAlan Cox vm_page_undirty(vm_page_t m)
439f3b676f0SAlan Cox {
4403b1025d2SKonstantin Belousov 
4413b1025d2SKonstantin Belousov 	VM_PAGE_OBJECT_LOCK_ASSERT(m);
442f3b676f0SAlan Cox 	m->dirty = 0;
443f3b676f0SAlan Cox }
444f3b676f0SAlan Cox 
445c4473420SPeter Wemm #endif				/* _KERNEL */
446df8bae1dSRodney W. Grimes #endif				/* !_VM_PAGE_ */
447