xref: /freebsd/sys/vm/vm_page.h (revision 8f9110f6a1b1bd7517643f1bde7fe2db25727efd)
1df8bae1dSRodney W. Grimes /*
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  * 3. All advertising materials mentioning features or use of this software
17df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
18df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
19df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
20df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  *
363c4dd356SDavid Greenman  *	from: @(#)vm_page.h	8.2 (Berkeley) 12/13/93
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  *
39df8bae1dSRodney W. Grimes  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40df8bae1dSRodney W. Grimes  * All rights reserved.
41df8bae1dSRodney W. Grimes  *
42df8bae1dSRodney W. Grimes  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43df8bae1dSRodney W. Grimes  *
44df8bae1dSRodney W. Grimes  * Permission to use, copy, modify and distribute this software and
45df8bae1dSRodney W. Grimes  * its documentation is hereby granted, provided that both the copyright
46df8bae1dSRodney W. Grimes  * notice and this permission notice appear in all copies of the
47df8bae1dSRodney W. Grimes  * software, derivative works or modified versions, and any portions
48df8bae1dSRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
49df8bae1dSRodney W. Grimes  *
50df8bae1dSRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51df8bae1dSRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52df8bae1dSRodney W. Grimes  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53df8bae1dSRodney W. Grimes  *
54df8bae1dSRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
55df8bae1dSRodney W. Grimes  *
56df8bae1dSRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57df8bae1dSRodney W. Grimes  *  School of Computer Science
58df8bae1dSRodney W. Grimes  *  Carnegie Mellon University
59df8bae1dSRodney W. Grimes  *  Pittsburgh PA 15213-3890
60df8bae1dSRodney W. Grimes  *
61df8bae1dSRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
62df8bae1dSRodney W. Grimes  * rights to redistribute these changes.
633c4dd356SDavid Greenman  *
648f9110f6SJohn Dyson  * $Id: vm_page.h,v 1.37 1998/03/01 04:18:26 dyson Exp $
65df8bae1dSRodney W. Grimes  */
66df8bae1dSRodney W. Grimes 
67df8bae1dSRodney W. Grimes /*
68df8bae1dSRodney W. Grimes  *	Resident memory system definitions.
69df8bae1dSRodney W. Grimes  */
70df8bae1dSRodney W. Grimes 
71df8bae1dSRodney W. Grimes #ifndef	_VM_PAGE_
72df8bae1dSRodney W. Grimes #define	_VM_PAGE_
73df8bae1dSRodney W. Grimes 
74f919ebdeSDavid Greenman #include <vm/pmap.h>
75df8bae1dSRodney W. Grimes /*
76df8bae1dSRodney W. Grimes  *	Management of resident (logical) pages.
77df8bae1dSRodney W. Grimes  *
78df8bae1dSRodney W. Grimes  *	A small structure is kept for each resident
79df8bae1dSRodney W. Grimes  *	page, indexed by page number.  Each structure
80df8bae1dSRodney W. Grimes  *	is an element of several lists:
81df8bae1dSRodney W. Grimes  *
82df8bae1dSRodney W. Grimes  *		A hash table bucket used to quickly
83df8bae1dSRodney W. Grimes  *		perform object/offset lookups
84df8bae1dSRodney W. Grimes  *
85df8bae1dSRodney W. Grimes  *		A list of all pages for a given object,
86df8bae1dSRodney W. Grimes  *		so they can be quickly deactivated at
87df8bae1dSRodney W. Grimes  *		time of deallocation.
88df8bae1dSRodney W. Grimes  *
89df8bae1dSRodney W. Grimes  *		An ordered list of pages due for pageout.
90df8bae1dSRodney W. Grimes  *
91df8bae1dSRodney W. Grimes  *	In addition, the structure contains the object
92df8bae1dSRodney W. Grimes  *	and offset to which this page belongs (for pageout),
93df8bae1dSRodney W. Grimes  *	and sundry status bits.
94df8bae1dSRodney W. Grimes  *
95df8bae1dSRodney W. Grimes  *	Fields in this structure are locked either by the lock on the
96df8bae1dSRodney W. Grimes  *	object that the page belongs to (O) or by the lock on the page
97df8bae1dSRodney W. Grimes  *	queues (P).
98df8bae1dSRodney W. Grimes  */
99df8bae1dSRodney W. Grimes 
100df8bae1dSRodney W. Grimes TAILQ_HEAD(pglist, vm_page);
101df8bae1dSRodney W. Grimes 
102df8bae1dSRodney W. Grimes struct vm_page {
1030d94caffSDavid Greenman 	TAILQ_ENTRY(vm_page) pageq;	/* queue info for FIFO queue or free list (P) */
104df8bae1dSRodney W. Grimes 	TAILQ_ENTRY(vm_page) hashq;	/* hash table links (O) */
105df8bae1dSRodney W. Grimes 	TAILQ_ENTRY(vm_page) listq;	/* pages in same object (O) */
106df8bae1dSRodney W. Grimes 
107df8bae1dSRodney W. Grimes 	vm_object_t object;		/* which object am I in (O,P) */
108a316d390SJohn Dyson 	vm_pindex_t pindex;		/* offset into object (O,P) */
1090d94caffSDavid Greenman 	vm_offset_t phys_addr;		/* physical address of page */
1105070c7f8SJohn Dyson 	u_short	queue;			/* page queue index */
1115070c7f8SJohn Dyson 	u_short	flags,			/* see below */
1125070c7f8SJohn Dyson 		pc;			/* page color */
113df8bae1dSRodney W. Grimes 	u_short wire_count;		/* wired down maps refs (P) */
11426f9a767SRodney W. Grimes 	short hold_count;		/* page hold count */
115bd7e5f99SJohn Dyson 	u_char	act_count;		/* page usage count */
116bd7e5f99SJohn Dyson 	u_char	busy;			/* page busy count */
117bd7e5f99SJohn Dyson 	/* NOTE that these must support one bit per DEV_BSIZE in a page!!! */
118bd7e5f99SJohn Dyson 	/* so, on normal X86 kernels, they must be at least 8 bits wide */
119bd7e5f99SJohn Dyson 	u_char	valid;			/* map of valid DEV_BSIZE chunks */
120bd7e5f99SJohn Dyson 	u_char	dirty;			/* map of dirty DEV_BSIZE chunks */
121df8bae1dSRodney W. Grimes };
122df8bae1dSRodney W. Grimes 
1235070c7f8SJohn Dyson /*
1245070c7f8SJohn Dyson  * Page coloring parameters
1255070c7f8SJohn Dyson  */
1265070c7f8SJohn Dyson /* Each of PQ_FREE, PQ_ZERO and PQ_CACHE have PQ_HASH_SIZE entries */
1275070c7f8SJohn Dyson 
1285070c7f8SJohn Dyson /* Define one of the following */
1295070c7f8SJohn Dyson #if defined(PQ_LARGECACHE)
1305070c7f8SJohn Dyson #define PQ_PRIME1 31	/* Prime number somewhat less than PQ_HASH_SIZE */
1315070c7f8SJohn Dyson #define PQ_PRIME2 23	/* Prime number somewhat less than PQ_HASH_SIZE */
1325070c7f8SJohn Dyson #define PQ_PRIME3 17	/* Prime number somewhat less than PQ_HASH_SIZE */
1335070c7f8SJohn Dyson #define PQ_L2_SIZE 128	/* A number of colors opt for 512K cache */
1345070c7f8SJohn Dyson #define PQ_L1_SIZE 2	/* Two page L1 cache */
1355070c7f8SJohn Dyson #endif
1365070c7f8SJohn Dyson 
1375070c7f8SJohn Dyson 
1385070c7f8SJohn Dyson /*
1395070c7f8SJohn Dyson  * Use 'options PQ_NOOPT' to disable page coloring
1405070c7f8SJohn Dyson  */
1415070c7f8SJohn Dyson #if defined(PQ_NOOPT)
1425070c7f8SJohn Dyson #define PQ_PRIME1 1
1435070c7f8SJohn Dyson #define PQ_PRIME2 1
1445070c7f8SJohn Dyson #define PQ_PRIME3 1
1455070c7f8SJohn Dyson #define PQ_L2_SIZE 1
1465070c7f8SJohn Dyson #define PQ_L1_SIZE 1
1475070c7f8SJohn Dyson #endif
1485070c7f8SJohn Dyson 
149853a7bc8SJohn Dyson #if defined(PQ_NORMALCACHE)
1505070c7f8SJohn Dyson #define PQ_PRIME1 5	/* Prime number somewhat less than PQ_HASH_SIZE */
1515070c7f8SJohn Dyson #define PQ_PRIME2 3	/* Prime number somewhat less than PQ_HASH_SIZE */
1525070c7f8SJohn Dyson #define PQ_PRIME3 11	/* Prime number somewhat less than PQ_HASH_SIZE */
1535070c7f8SJohn Dyson #define PQ_L2_SIZE 16	/* A reasonable number of colors (opt for 64K cache) */
1545070c7f8SJohn Dyson #define PQ_L1_SIZE 2	/* Two page L1 cache */
1555070c7f8SJohn Dyson #endif
1565070c7f8SJohn Dyson 
157853a7bc8SJohn Dyson #if defined(PQ_MEDIUMCACHE) || !defined(PQ_L2_SIZE)
158853a7bc8SJohn Dyson #define PQ_PRIME1 13	/* Prime number somewhat less than PQ_HASH_SIZE */
159853a7bc8SJohn Dyson #define PQ_PRIME2 7	/* Prime number somewhat less than PQ_HASH_SIZE */
160853a7bc8SJohn Dyson #define PQ_PRIME3 5	/* Prime number somewhat less than PQ_HASH_SIZE */
161853a7bc8SJohn Dyson #define PQ_L2_SIZE 64	/* A number of colors opt for 256K cache */
162853a7bc8SJohn Dyson #define PQ_L1_SIZE 2	/* Two page L1 cache */
163853a7bc8SJohn Dyson #endif
164853a7bc8SJohn Dyson 
1655070c7f8SJohn Dyson #define PQ_L2_MASK (PQ_L2_SIZE - 1)
1665070c7f8SJohn Dyson 
167bd7e5f99SJohn Dyson #define PQ_NONE 0
168bd7e5f99SJohn Dyson #define PQ_FREE	1
1695070c7f8SJohn Dyson #define PQ_ZERO (1 + PQ_L2_SIZE)
1705070c7f8SJohn Dyson #define PQ_INACTIVE (1 + 2*PQ_L2_SIZE)
1715070c7f8SJohn Dyson #define PQ_ACTIVE (2 + 2*PQ_L2_SIZE)
1725070c7f8SJohn Dyson #define PQ_CACHE (3 + 2*PQ_L2_SIZE)
1735070c7f8SJohn Dyson #define PQ_COUNT (3 + 3*PQ_L2_SIZE)
1745070c7f8SJohn Dyson 
1755070c7f8SJohn Dyson extern struct vpgqueues {
1765070c7f8SJohn Dyson 	struct pglist *pl;
1775070c7f8SJohn Dyson 	int	*cnt;
1785070c7f8SJohn Dyson 	int	*lcnt;
1795070c7f8SJohn Dyson } vm_page_queues[PQ_COUNT];
180bd7e5f99SJohn Dyson 
181df8bae1dSRodney W. Grimes /*
182df8bae1dSRodney W. Grimes  * These are the flags defined for vm_page.
183df8bae1dSRodney W. Grimes  *
184df8bae1dSRodney W. Grimes  * Note: PG_FILLED and PG_DIRTY are added for the filesystems.
185df8bae1dSRodney W. Grimes  */
186bd7e5f99SJohn Dyson #define	PG_BUSY		0x01		/* page is in transit (O) */
187bd7e5f99SJohn Dyson #define	PG_WANTED	0x02		/* someone is waiting for page (O) */
188bd7e5f99SJohn Dyson #define	PG_TABLED	0x04		/* page is in VP table (O) */
189bd7e5f99SJohn Dyson #define	PG_FICTITIOUS	0x08		/* physical page doesn't exist (O) */
190bd7e5f99SJohn Dyson #define	PG_WRITEABLE	0x10		/* page is mapped writeable */
191bd7e5f99SJohn Dyson #define PG_MAPPED	0x20		/* page is mapped */
192bd7e5f99SJohn Dyson #define	PG_ZERO		0x40		/* page is zeroed */
193bd7e5f99SJohn Dyson #define PG_REFERENCED	0x80		/* page has been referenced */
194bd7e5f99SJohn Dyson #define PG_CLEANCHK	0x100		/* page has been checked for cleaning */
195df8bae1dSRodney W. Grimes 
19624a1cce3SDavid Greenman /*
19724a1cce3SDavid Greenman  * Misc constants.
19824a1cce3SDavid Greenman  */
19924a1cce3SDavid Greenman 
20024a1cce3SDavid Greenman #define ACT_DECLINE		1
20124a1cce3SDavid Greenman #define ACT_ADVANCE		3
20238efa82bSJohn Dyson #define ACT_INIT		5
2035070c7f8SJohn Dyson #define ACT_MAX			64
20424a1cce3SDavid Greenman #define PFCLUSTER_BEHIND	3
20524a1cce3SDavid Greenman #define PFCLUSTER_AHEAD		3
206df8bae1dSRodney W. Grimes 
207df8bae1dSRodney W. Grimes #ifdef KERNEL
208df8bae1dSRodney W. Grimes /*
20924a1cce3SDavid Greenman  * Each pageable resident page falls into one of four lists:
210df8bae1dSRodney W. Grimes  *
211df8bae1dSRodney W. Grimes  *	free
212df8bae1dSRodney W. Grimes  *		Available for allocation now.
21324a1cce3SDavid Greenman  *
21424a1cce3SDavid Greenman  * The following are all LRU sorted:
21524a1cce3SDavid Greenman  *
21624a1cce3SDavid Greenman  *	cache
21724a1cce3SDavid Greenman  *		Almost available for allocation. Still in an
21824a1cce3SDavid Greenman  *		object, but clean and immediately freeable at
21924a1cce3SDavid Greenman  *		non-interrupt times.
22024a1cce3SDavid Greenman  *
221df8bae1dSRodney W. Grimes  *	inactive
2226c5e9bbdSMike Pritchard  *		Low activity, candidates for reclamation.
223df8bae1dSRodney W. Grimes  *		This is the list of pages that should be
224df8bae1dSRodney W. Grimes  *		paged out next.
22524a1cce3SDavid Greenman  *
226df8bae1dSRodney W. Grimes  *	active
22724a1cce3SDavid Greenman  *		Pages that are "active" i.e. they have been
22824a1cce3SDavid Greenman  *		recently referenced.
22910ad4d48SJohn Dyson  *
23010ad4d48SJohn Dyson  *	zero
23110ad4d48SJohn Dyson  *		Pages that are really free and have been pre-zeroed
23210ad4d48SJohn Dyson  *
233df8bae1dSRodney W. Grimes  */
234df8bae1dSRodney W. Grimes 
2355070c7f8SJohn Dyson extern struct pglist vm_page_queue_free[PQ_L2_SIZE];/* memory free queue */
2365070c7f8SJohn Dyson extern struct pglist vm_page_queue_zero[PQ_L2_SIZE];/* zeroed memory free queue */
2370d94caffSDavid Greenman extern struct pglist vm_page_queue_active;	/* active memory queue */
2380d94caffSDavid Greenman extern struct pglist vm_page_queue_inactive;	/* inactive memory queue */
2395070c7f8SJohn Dyson extern struct pglist vm_page_queue_cache[PQ_L2_SIZE];/* cache memory queue */
240df8bae1dSRodney W. Grimes 
241a316d390SJohn Dyson extern int vm_page_zero_count;
242a316d390SJohn Dyson 
2430d94caffSDavid Greenman extern vm_page_t vm_page_array;		/* First resident page in table */
2440d94caffSDavid Greenman extern long first_page;			/* first physical page number */
2450d94caffSDavid Greenman 
246df8bae1dSRodney W. Grimes  /* ... represented in vm_page_array */
2470d94caffSDavid Greenman extern long last_page;			/* last physical page number */
2480d94caffSDavid Greenman 
249df8bae1dSRodney W. Grimes  /* ... represented in vm_page_array */
250df8bae1dSRodney W. Grimes  /* [INCLUSIVE] */
2510d94caffSDavid Greenman extern vm_offset_t first_phys_addr;	/* physical address for first_page */
2520d94caffSDavid Greenman extern vm_offset_t last_phys_addr;	/* physical address for last_page */
253df8bae1dSRodney W. Grimes 
254df8bae1dSRodney W. Grimes #define VM_PAGE_TO_PHYS(entry)	((entry)->phys_addr)
255df8bae1dSRodney W. Grimes 
256df8bae1dSRodney W. Grimes #define IS_VM_PHYSADDR(pa) \
257df8bae1dSRodney W. Grimes 		((pa) >= first_phys_addr && (pa) <= last_phys_addr)
258df8bae1dSRodney W. Grimes 
259df8bae1dSRodney W. Grimes #define PHYS_TO_VM_PAGE(pa) \
260df8bae1dSRodney W. Grimes 		(&vm_page_array[atop(pa) - first_page ])
261df8bae1dSRodney W. Grimes 
262df8bae1dSRodney W. Grimes /*
263df8bae1dSRodney W. Grimes  *	Functions implemented as macros
264df8bae1dSRodney W. Grimes  */
265df8bae1dSRodney W. Grimes 
266df8bae1dSRodney W. Grimes #define PAGE_ASSERT_WAIT(m, interruptible)	{ \
267df8bae1dSRodney W. Grimes 	(m)->flags |= PG_WANTED; \
268df8bae1dSRodney W. Grimes 	assert_wait((int) (m), (interruptible)); \
269df8bae1dSRodney W. Grimes }
270df8bae1dSRodney W. Grimes 
271df8bae1dSRodney W. Grimes #define PAGE_WAKEUP(m)	{ \
272df8bae1dSRodney W. Grimes 	(m)->flags &= ~PG_BUSY; \
273ffc82b0aSJohn Dyson 	if (((m)->flags & PG_WANTED) && ((m)->busy == 0)) { \
274df8bae1dSRodney W. Grimes 		(m)->flags &= ~PG_WANTED; \
275ffc82b0aSJohn Dyson 		wakeup((m)); \
276df8bae1dSRodney W. Grimes 	} \
277df8bae1dSRodney W. Grimes }
278df8bae1dSRodney W. Grimes 
2798f9110f6SJohn Dyson #define PAGE_BWAKEUP(m) { \
2808f9110f6SJohn Dyson 	(m)->busy--; \
2818f9110f6SJohn Dyson 	if ((((m)->flags & (PG_WANTED | PG_BUSY)) == PG_WANTED) && \
2828f9110f6SJohn Dyson 		((m)->busy == 0)) { \
2838f9110f6SJohn Dyson 		(m)->flags &= ~PG_WANTED; \
2848f9110f6SJohn Dyson 		wakeup((m)); \
2858f9110f6SJohn Dyson 	} \
2868f9110f6SJohn Dyson }
2878f9110f6SJohn Dyson 
2888f9110f6SJohn Dyson 
2890d94caffSDavid Greenman #if PAGE_SIZE == 4096
2900d94caffSDavid Greenman #define VM_PAGE_BITS_ALL 0xff
2910d94caffSDavid Greenman #endif
2920d94caffSDavid Greenman 
2930d94caffSDavid Greenman #if PAGE_SIZE == 8192
2940d94caffSDavid Greenman #define VM_PAGE_BITS_ALL 0xffff
2950d94caffSDavid Greenman #endif
2960d94caffSDavid Greenman 
2976d40c3d3SDavid Greenman #define VM_ALLOC_NORMAL		0
2986d40c3d3SDavid Greenman #define VM_ALLOC_INTERRUPT	1
2996d40c3d3SDavid Greenman #define VM_ALLOC_SYSTEM		2
300bd7e5f99SJohn Dyson #define	VM_ALLOC_ZERO		3
30195461b45SJohn Dyson #define	VM_ALLOC_RETRY		0x80
3020d94caffSDavid Greenman 
303df8bae1dSRodney W. Grimes void vm_page_activate __P((vm_page_t));
304a316d390SJohn Dyson vm_page_t vm_page_alloc __P((vm_object_t, vm_pindex_t, int));
30595461b45SJohn Dyson vm_page_t vm_page_grab __P((vm_object_t, vm_pindex_t, int));
306d2fc5315SPoul-Henning Kamp void vm_page_cache __P((register vm_page_t));
3077f5fe93fSJohn Dyson static __inline void vm_page_copy __P((vm_page_t, vm_page_t));
308df8bae1dSRodney W. Grimes void vm_page_deactivate __P((vm_page_t));
309df8bae1dSRodney W. Grimes void vm_page_free __P((vm_page_t));
3106b6f0008SJohn Dyson void vm_page_free_zero __P((vm_page_t));
311a316d390SJohn Dyson void vm_page_insert __P((vm_page_t, vm_object_t, vm_pindex_t));
312a316d390SJohn Dyson vm_page_t vm_page_lookup __P((vm_object_t, vm_pindex_t));
313df8bae1dSRodney W. Grimes void vm_page_remove __P((vm_page_t));
314a316d390SJohn Dyson void vm_page_rename __P((vm_page_t, vm_object_t, vm_pindex_t));
31526f9a767SRodney W. Grimes vm_offset_t vm_page_startup __P((vm_offset_t, vm_offset_t, vm_offset_t));
316df8bae1dSRodney W. Grimes void vm_page_unwire __P((vm_page_t));
317df8bae1dSRodney W. Grimes void vm_page_wire __P((vm_page_t));
31867bf6868SJohn Dyson void vm_page_unqueue __P((vm_page_t));
31967bf6868SJohn Dyson void vm_page_unqueue_nowakeup __P((vm_page_t));
32010ad4d48SJohn Dyson void vm_page_set_validclean __P((vm_page_t, int, int));
3210d94caffSDavid Greenman void vm_page_set_invalid __P((vm_page_t, int, int));
3227f5fe93fSJohn Dyson static __inline boolean_t vm_page_zero_fill __P((vm_page_t));
3230d94caffSDavid Greenman int vm_page_is_valid __P((vm_page_t, int, int));
3240d94caffSDavid Greenman void vm_page_test_dirty __P((vm_page_t));
325d2fc5315SPoul-Henning Kamp int vm_page_bits __P((int, int));
3265070c7f8SJohn Dyson vm_page_t vm_page_list_find __P((int, int));
3275070c7f8SJohn Dyson int vm_page_queue_index __P((vm_offset_t, int));
3285070c7f8SJohn Dyson vm_page_t vm_page_select __P((vm_object_t, vm_pindex_t, int));
329ffc82b0aSJohn Dyson int vm_page_sleep(vm_page_t m, char *msg, char *busy);
330d2fc5315SPoul-Henning Kamp 
33126f9a767SRodney W. Grimes /*
33226f9a767SRodney W. Grimes  * Keep page from being freed by the page daemon
33326f9a767SRodney W. Grimes  * much of the same effect as wiring, except much lower
33426f9a767SRodney W. Grimes  * overhead and should be used only for *very* temporary
33526f9a767SRodney W. Grimes  * holding ("wiring").
33626f9a767SRodney W. Grimes  */
3377666fb47SBruce Evans static __inline void
3384f21005bSBruce Evans vm_page_hold(vm_page_t mem)
33926f9a767SRodney W. Grimes {
34026f9a767SRodney W. Grimes 	mem->hold_count++;
34126f9a767SRodney W. Grimes }
34226f9a767SRodney W. Grimes 
343091b0456SGarrett Wollman #ifdef DIAGNOSTIC
344091b0456SGarrett Wollman #include <sys/systm.h>		/* make GCC shut up */
345091b0456SGarrett Wollman #endif
346091b0456SGarrett Wollman 
3477666fb47SBruce Evans static __inline void
3484f21005bSBruce Evans vm_page_unhold(vm_page_t mem)
34926f9a767SRodney W. Grimes {
35027de4e40SDavid Greenman #ifdef DIAGNOSTIC
35126f9a767SRodney W. Grimes 	if (--mem->hold_count < 0)
35226f9a767SRodney W. Grimes 		panic("vm_page_unhold: hold count < 0!!!");
35327de4e40SDavid Greenman #else
35427de4e40SDavid Greenman 	--mem->hold_count;
35527de4e40SDavid Greenman #endif
35626f9a767SRodney W. Grimes }
35726f9a767SRodney W. Grimes 
3587666fb47SBruce Evans static __inline void
359f919ebdeSDavid Greenman vm_page_protect(vm_page_t mem, int prot)
360f919ebdeSDavid Greenman {
361f919ebdeSDavid Greenman 	if (prot == VM_PROT_NONE) {
362f919ebdeSDavid Greenman 		if (mem->flags & (PG_WRITEABLE|PG_MAPPED)) {
3638f9110f6SJohn Dyson 			pmap_page_protect(VM_PAGE_TO_PHYS(mem), VM_PROT_NONE);
364f919ebdeSDavid Greenman 			mem->flags &= ~(PG_WRITEABLE|PG_MAPPED);
365f919ebdeSDavid Greenman 		}
366f919ebdeSDavid Greenman 	} else if ((prot == VM_PROT_READ) && (mem->flags & PG_WRITEABLE)) {
3678f9110f6SJohn Dyson 		pmap_page_protect(VM_PAGE_TO_PHYS(mem), VM_PROT_READ);
368f919ebdeSDavid Greenman 		mem->flags &= ~PG_WRITEABLE;
369f919ebdeSDavid Greenman 	}
370f919ebdeSDavid Greenman }
371f919ebdeSDavid Greenman 
3727f5fe93fSJohn Dyson /*
3737f5fe93fSJohn Dyson  *	vm_page_zero_fill:
3747f5fe93fSJohn Dyson  *
3757f5fe93fSJohn Dyson  *	Zero-fill the specified page.
3767f5fe93fSJohn Dyson  *	Written as a standard pagein routine, to
3777f5fe93fSJohn Dyson  *	be used by the zero-fill object.
3787f5fe93fSJohn Dyson  */
3797f5fe93fSJohn Dyson static __inline boolean_t
3807f5fe93fSJohn Dyson vm_page_zero_fill(m)
3817f5fe93fSJohn Dyson 	vm_page_t m;
3827f5fe93fSJohn Dyson {
3837f5fe93fSJohn Dyson 	pmap_zero_page(VM_PAGE_TO_PHYS(m));
3847f5fe93fSJohn Dyson 	return (TRUE);
3857f5fe93fSJohn Dyson }
3867f5fe93fSJohn Dyson 
3877f5fe93fSJohn Dyson /*
3887f5fe93fSJohn Dyson  *	vm_page_copy:
3897f5fe93fSJohn Dyson  *
3907f5fe93fSJohn Dyson  *	Copy one page to another
3917f5fe93fSJohn Dyson  */
3927f5fe93fSJohn Dyson static __inline void
3937f5fe93fSJohn Dyson vm_page_copy(src_m, dest_m)
3947f5fe93fSJohn Dyson 	vm_page_t src_m;
3957f5fe93fSJohn Dyson 	vm_page_t dest_m;
3967f5fe93fSJohn Dyson {
3977f5fe93fSJohn Dyson 	pmap_copy_page(VM_PAGE_TO_PHYS(src_m), VM_PAGE_TO_PHYS(dest_m));
3987f5fe93fSJohn Dyson 	dest_m->valid = VM_PAGE_BITS_ALL;
3997f5fe93fSJohn Dyson }
400f919ebdeSDavid Greenman 
401df8bae1dSRodney W. Grimes #endif				/* KERNEL */
402df8bae1dSRodney W. Grimes #endif				/* !_VM_PAGE_ */
403