xref: /freebsd/sys/vm/vm_page.h (revision 6d03d577a58094d65902f97d4f365e7f716515fc)
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  *
64c3aac50fSPeter Wemm  * $FreeBSD$
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 
740237469fSJulian Elischer #if !defined(KLD_MODULE)
7520f71813SJohn-Mark Gurney #include "opt_vmpage.h"
760237469fSJulian Elischer #endif
7720f71813SJohn-Mark Gurney 
78f919ebdeSDavid Greenman #include <vm/pmap.h>
79069e9bc1SDoug Rabson #include <machine/atomic.h>
80069e9bc1SDoug Rabson 
81df8bae1dSRodney W. Grimes /*
82df8bae1dSRodney W. Grimes  *	Management of resident (logical) pages.
83df8bae1dSRodney W. Grimes  *
84df8bae1dSRodney W. Grimes  *	A small structure is kept for each resident
85df8bae1dSRodney W. Grimes  *	page, indexed by page number.  Each structure
86df8bae1dSRodney W. Grimes  *	is an element of several lists:
87df8bae1dSRodney W. Grimes  *
88df8bae1dSRodney W. Grimes  *		A hash table bucket used to quickly
89df8bae1dSRodney W. Grimes  *		perform object/offset lookups
90df8bae1dSRodney W. Grimes  *
91df8bae1dSRodney W. Grimes  *		A list of all pages for a given object,
92df8bae1dSRodney W. Grimes  *		so they can be quickly deactivated at
93df8bae1dSRodney W. Grimes  *		time of deallocation.
94df8bae1dSRodney W. Grimes  *
95df8bae1dSRodney W. Grimes  *		An ordered list of pages due for pageout.
96df8bae1dSRodney W. Grimes  *
97df8bae1dSRodney W. Grimes  *	In addition, the structure contains the object
98df8bae1dSRodney W. Grimes  *	and offset to which this page belongs (for pageout),
99df8bae1dSRodney W. Grimes  *	and sundry status bits.
100df8bae1dSRodney W. Grimes  *
101df8bae1dSRodney W. Grimes  *	Fields in this structure are locked either by the lock on the
102df8bae1dSRodney W. Grimes  *	object that the page belongs to (O) or by the lock on the page
103df8bae1dSRodney W. Grimes  *	queues (P).
1044221e284SAlan Cox  *
1054221e284SAlan Cox  *	The 'valid' and 'dirty' fields are distinct.  A page may have dirty
1064221e284SAlan Cox  *	bits set without having associated valid bits set.  This is used by
1074221e284SAlan Cox  *	NFS to implement piecemeal writes.
108df8bae1dSRodney W. Grimes  */
109df8bae1dSRodney W. Grimes 
110e3975643SJake Burkholder TAILQ_HEAD(pglist, vm_page);
111df8bae1dSRodney W. Grimes 
112df8bae1dSRodney W. Grimes struct vm_page {
113e3975643SJake Burkholder 	TAILQ_ENTRY(vm_page) pageq;	/* queue info for FIFO queue or free list (P) */
1141c7c3c6aSMatthew Dillon 	struct vm_page	*hnext;		/* hash table link (O,P)	*/
115e3975643SJake Burkholder 	TAILQ_ENTRY(vm_page) listq;	/* pages in same object (O) 	*/
116df8bae1dSRodney W. Grimes 
117df8bae1dSRodney W. Grimes 	vm_object_t object;		/* which object am I in (O,P)*/
118a316d390SJohn Dyson 	vm_pindex_t pindex;		/* offset into object (O,P) */
1190d94caffSDavid Greenman 	vm_offset_t phys_addr;		/* physical address of page */
1200385347cSPeter Wemm 	struct md_page md;		/* machine dependant stuff */
1215070c7f8SJohn Dyson 	u_short	queue;			/* page queue index */
1225070c7f8SJohn Dyson 	u_short	flags,			/* see below */
1235070c7f8SJohn Dyson 		pc;			/* page color */
124df8bae1dSRodney W. Grimes 	u_short wire_count;		/* wired down maps refs (P) */
12526f9a767SRodney W. Grimes 	short hold_count;		/* page hold count */
126bd7e5f99SJohn Dyson 	u_char	act_count;		/* page usage count */
127bd7e5f99SJohn Dyson 	u_char	busy;			/* page busy count */
128bd7e5f99SJohn Dyson 	/* NOTE that these must support one bit per DEV_BSIZE in a page!!! */
129bd7e5f99SJohn Dyson 	/* so, on normal X86 kernels, they must be at least 8 bits wide */
130ecbb00a2SDoug Rabson #if PAGE_SIZE == 4096
131bd7e5f99SJohn Dyson 	u_char	valid;			/* map of valid DEV_BSIZE chunks */
132bd7e5f99SJohn Dyson 	u_char	dirty;			/* map of dirty DEV_BSIZE chunks */
133ecbb00a2SDoug Rabson #elif PAGE_SIZE == 8192
134ecbb00a2SDoug Rabson 	u_short	valid;			/* map of valid DEV_BSIZE chunks */
135ecbb00a2SDoug Rabson 	u_short	dirty;			/* map of dirty DEV_BSIZE chunks */
136ecbb00a2SDoug Rabson #endif
137df8bae1dSRodney W. Grimes };
138df8bae1dSRodney W. Grimes 
1395070c7f8SJohn Dyson /*
14090ecac61SMatthew Dillon  * note: currently use SWAPBLK_NONE as an absolute value rather then
14190ecac61SMatthew Dillon  * a flag bit.
1421c7c3c6aSMatthew Dillon  */
1431c7c3c6aSMatthew Dillon 
1441c7c3c6aSMatthew Dillon #define SWAPBLK_MASK	((daddr_t)((u_daddr_t)-1 >> 1))		/* mask */
1451c7c3c6aSMatthew Dillon #define SWAPBLK_NONE	((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */
1461c7c3c6aSMatthew Dillon 
1470237469fSJulian Elischer #if !defined(KLD_MODULE)
1480237469fSJulian Elischer 
1491c7c3c6aSMatthew Dillon /*
1506d03d577SMatthew Dillon  * shared mutex array for vm_page_buckets[]
1516d03d577SMatthew Dillon  */
1526d03d577SMatthew Dillon #ifndef BUCKET_HASH_SIZE
1536d03d577SMatthew Dillon #define BUCKET_HASH_SIZE	16
1546d03d577SMatthew Dillon #endif
1556d03d577SMatthew Dillon #define BUCKET_HASH_MASK	(BUCKET_HASH_SIZE - 1)
1566d03d577SMatthew Dillon 
1576d03d577SMatthew Dillon /*
1585070c7f8SJohn Dyson  * Page coloring parameters
1595070c7f8SJohn Dyson  */
160faa273d5SMatthew Dillon /* Each of PQ_FREE, and PQ_CACHE have PQ_HASH_SIZE entries */
1615070c7f8SJohn Dyson 
1629a20f99aSJohn Baldwin /* Backward compatibility for existing PQ_*CACHE config options. */
1639a20f99aSJohn Baldwin #if !defined(PQ_CACHESIZE)
164b9cefc08SJohn Dyson #if defined(PQ_HUGECACHE)
1659a20f99aSJohn Baldwin #define PQ_CACHESIZE 1024
1664c8545c1SAlfred Perlstein #elif defined(PQ_LARGECACHE)
1679a20f99aSJohn Baldwin #define PQ_CACHESIZE 512
1684c8545c1SAlfred Perlstein #elif defined(PQ_MEDIUMCACHE)
1699a20f99aSJohn Baldwin #define PQ_CACHESIZE 256
1704c8545c1SAlfred Perlstein #elif defined(PQ_NORMALCACHE)
1719a20f99aSJohn Baldwin #define PQ_CACHESIZE 64
1724c8545c1SAlfred Perlstein #elif defined(PQ_NOOPT)
1739a20f99aSJohn Baldwin #define PQ_CACHESIZE 0
1749a20f99aSJohn Baldwin #else
1759a20f99aSJohn Baldwin #define PQ_CACHESIZE 128
1769a20f99aSJohn Baldwin #endif
1779a20f99aSJohn Baldwin #endif
1789a20f99aSJohn Baldwin 
1799a20f99aSJohn Baldwin #if PQ_CACHESIZE >= 1024
180b9cefc08SJohn Dyson #define PQ_PRIME1 31	/* Prime number somewhat less than PQ_HASH_SIZE */
181b9cefc08SJohn Dyson #define PQ_PRIME2 23	/* Prime number somewhat less than PQ_HASH_SIZE */
182b9cefc08SJohn Dyson #define PQ_L2_SIZE 256	/* A number of colors opt for 1M cache */
183b9cefc08SJohn Dyson 
1844c8545c1SAlfred Perlstein #elif PQ_CACHESIZE >= 512
1855070c7f8SJohn Dyson #define PQ_PRIME1 31	/* Prime number somewhat less than PQ_HASH_SIZE */
1865070c7f8SJohn Dyson #define PQ_PRIME2 23	/* Prime number somewhat less than PQ_HASH_SIZE */
1875070c7f8SJohn Dyson #define PQ_L2_SIZE 128	/* A number of colors opt for 512K cache */
1885070c7f8SJohn Dyson 
1894c8545c1SAlfred Perlstein #elif PQ_CACHESIZE >= 256
190853a7bc8SJohn Dyson #define PQ_PRIME1 13	/* Prime number somewhat less than PQ_HASH_SIZE */
191853a7bc8SJohn Dyson #define PQ_PRIME2 7	/* Prime number somewhat less than PQ_HASH_SIZE */
192853a7bc8SJohn Dyson #define PQ_L2_SIZE 64	/* A number of colors opt for 256K cache */
193853a7bc8SJohn Dyson 
1944c8545c1SAlfred Perlstein #elif PQ_CACHESIZE >= 128
1951aefb1d9SAlan Cox #define PQ_PRIME1 9	/* Produces a good PQ_L2_SIZE/3 + PQ_PRIME1 */
1961aefb1d9SAlan Cox #define PQ_PRIME2 5	/* Prime number somewhat less than PQ_HASH_SIZE */
1979a20f99aSJohn Baldwin #define PQ_L2_SIZE 32	/* A number of colors opt for 128k cache */
1989a20f99aSJohn Baldwin 
1994c8545c1SAlfred Perlstein #elif PQ_CACHESIZE >= 64
2009a20f99aSJohn Baldwin #define PQ_PRIME1 5	/* Prime number somewhat less than PQ_HASH_SIZE */
2019a20f99aSJohn Baldwin #define PQ_PRIME2 3	/* Prime number somewhat less than PQ_HASH_SIZE */
2029a20f99aSJohn Baldwin #define PQ_L2_SIZE 16	/* A reasonable number of colors (opt for 64K cache) */
2039a20f99aSJohn Baldwin 
2049a20f99aSJohn Baldwin #else
2059a20f99aSJohn Baldwin #define PQ_PRIME1 1	/* Disable page coloring. */
2069a20f99aSJohn Baldwin #define PQ_PRIME2 1
2079a20f99aSJohn Baldwin #define PQ_L2_SIZE 1
2089a20f99aSJohn Baldwin 
2091aefb1d9SAlan Cox #endif
2101aefb1d9SAlan Cox 
2115070c7f8SJohn Dyson #define PQ_L2_MASK (PQ_L2_SIZE - 1)
2125070c7f8SJohn Dyson 
213175d1f69SAlan Cox #if 1
2143739d7daSMatt Jacob #define PQ_NONE 0
2153739d7daSMatt Jacob #define PQ_FREE	1
2163739d7daSMatt Jacob #define PQ_INACTIVE (1 + 1*PQ_L2_SIZE)
2173739d7daSMatt Jacob #define PQ_ACTIVE (2 + 1*PQ_L2_SIZE)
2183739d7daSMatt Jacob #define PQ_CACHE (3 + 1*PQ_L2_SIZE)
2193739d7daSMatt Jacob #define PQ_COUNT (3 + 2*PQ_L2_SIZE)
2203739d7daSMatt Jacob #else
221514bfcc4SAlan Cox #define PQ_NONE		PQ_COUNT
222514bfcc4SAlan Cox #define PQ_FREE		0
223514bfcc4SAlan Cox #define PQ_INACTIVE	PQ_L2_SIZE
224514bfcc4SAlan Cox #define PQ_ACTIVE	(1 +   PQ_L2_SIZE)
225514bfcc4SAlan Cox #define PQ_CACHE	(2 +   PQ_L2_SIZE)
226514bfcc4SAlan Cox #define PQ_COUNT	(2 + 2*PQ_L2_SIZE)
2273739d7daSMatt Jacob #endif
2285070c7f8SJohn Dyson 
229be72f788SAlan Cox struct vpgqueues {
230be72f788SAlan Cox 	struct pglist pl;
2315070c7f8SJohn Dyson 	int	*cnt;
2325d2aec89SAlan Cox 	int	lcnt;
233be72f788SAlan Cox };
234be72f788SAlan Cox 
235be72f788SAlan Cox extern struct vpgqueues vm_page_queues[PQ_COUNT];
236bd7e5f99SJohn Dyson 
2370237469fSJulian Elischer #endif
2380237469fSJulian Elischer 
239df8bae1dSRodney W. Grimes /*
240df8bae1dSRodney W. Grimes  * These are the flags defined for vm_page.
241df8bae1dSRodney W. Grimes  *
242df8bae1dSRodney W. Grimes  * Note: PG_FILLED and PG_DIRTY are added for the filesystems.
2438b03c8edSMatthew Dillon  *
2448b03c8edSMatthew Dillon  * Note: PG_UNMANAGED (used by OBJT_PHYS) indicates that the page is
2458b03c8edSMatthew Dillon  * 	 not under PV management but otherwise should be treated as a
2468b03c8edSMatthew Dillon  *	 normal page.  Pages not under PV management cannot be paged out
2478b03c8edSMatthew Dillon  *	 via the object/vm_page_t because there is no knowledge of their
2488b03c8edSMatthew Dillon  *	 pte mappings, nor can they be removed from their objects via
2498b03c8edSMatthew Dillon  *	 the object, and such pages are also not on any PQ queue.
250df8bae1dSRodney W. Grimes  */
2511c7c3c6aSMatthew Dillon #define	PG_BUSY		0x0001		/* page is in transit (O) */
2521c7c3c6aSMatthew Dillon #define	PG_WANTED	0x0002		/* someone is waiting for page (O) */
2532b6b0df7SMatthew Dillon #define PG_WINATCFLS	0x0004		/* flush dirty page on inactive q */
2541c7c3c6aSMatthew Dillon #define	PG_FICTITIOUS	0x0008		/* physical page doesn't exist (O) */
2551c7c3c6aSMatthew Dillon #define	PG_WRITEABLE	0x0010		/* page is mapped writeable */
2561c7c3c6aSMatthew Dillon #define PG_MAPPED	0x0020		/* page is mapped */
2571c7c3c6aSMatthew Dillon #define	PG_ZERO		0x0040		/* page is zeroed */
2581c7c3c6aSMatthew Dillon #define PG_REFERENCED	0x0080		/* page has been referenced */
2591c7c3c6aSMatthew Dillon #define PG_CLEANCHK	0x0100		/* page will be checked for cleaning */
2601c7c3c6aSMatthew Dillon #define PG_SWAPINPROG	0x0200		/* swap I/O in progress on page	     */
2614f79d873SMatthew Dillon #define PG_NOSYNC	0x0400		/* do not collect for syncer */
2628b03c8edSMatthew Dillon #define PG_UNMANAGED	0x0800		/* No PV management for page */
263936524aaSMatthew Dillon #define PG_MARKER	0x1000		/* special queue marker page */
264df8bae1dSRodney W. Grimes 
26524a1cce3SDavid Greenman /*
26624a1cce3SDavid Greenman  * Misc constants.
26724a1cce3SDavid Greenman  */
26824a1cce3SDavid Greenman 
26924a1cce3SDavid Greenman #define ACT_DECLINE		1
27024a1cce3SDavid Greenman #define ACT_ADVANCE		3
27138efa82bSJohn Dyson #define ACT_INIT		5
2725070c7f8SJohn Dyson #define ACT_MAX			64
27324a1cce3SDavid Greenman #define PFCLUSTER_BEHIND	3
27424a1cce3SDavid Greenman #define PFCLUSTER_AHEAD		3
275df8bae1dSRodney W. Grimes 
276c4473420SPeter Wemm #ifdef _KERNEL
277df8bae1dSRodney W. Grimes /*
27824a1cce3SDavid Greenman  * Each pageable resident page falls into one of four lists:
279df8bae1dSRodney W. Grimes  *
280df8bae1dSRodney W. Grimes  *	free
281df8bae1dSRodney W. Grimes  *		Available for allocation now.
28224a1cce3SDavid Greenman  *
28324a1cce3SDavid Greenman  * The following are all LRU sorted:
28424a1cce3SDavid Greenman  *
28524a1cce3SDavid Greenman  *	cache
28624a1cce3SDavid Greenman  *		Almost available for allocation. Still in an
28724a1cce3SDavid Greenman  *		object, but clean and immediately freeable at
28824a1cce3SDavid Greenman  *		non-interrupt times.
28924a1cce3SDavid Greenman  *
290df8bae1dSRodney W. Grimes  *	inactive
2916c5e9bbdSMike Pritchard  *		Low activity, candidates for reclamation.
292df8bae1dSRodney W. Grimes  *		This is the list of pages that should be
293df8bae1dSRodney W. Grimes  *		paged out next.
29424a1cce3SDavid Greenman  *
295df8bae1dSRodney W. Grimes  *	active
29624a1cce3SDavid Greenman  *		Pages that are "active" i.e. they have been
29724a1cce3SDavid Greenman  *		recently referenced.
29810ad4d48SJohn Dyson  *
29910ad4d48SJohn Dyson  *	zero
30010ad4d48SJohn Dyson  *		Pages that are really free and have been pre-zeroed
30110ad4d48SJohn Dyson  *
302df8bae1dSRodney W. Grimes  */
303df8bae1dSRodney W. Grimes 
304a316d390SJohn Dyson extern int vm_page_zero_count;
305a316d390SJohn Dyson 
3060d94caffSDavid Greenman extern vm_page_t vm_page_array;		/* First resident page in table */
3070385347cSPeter Wemm extern int vm_page_array_size;		/* number of vm_page_t's */
3080d94caffSDavid Greenman extern long first_page;			/* first physical page number */
3090d94caffSDavid Greenman 
310df8bae1dSRodney W. Grimes #define VM_PAGE_TO_PHYS(entry)	((entry)->phys_addr)
311df8bae1dSRodney W. Grimes 
312df8bae1dSRodney W. Grimes #define PHYS_TO_VM_PAGE(pa) \
313df8bae1dSRodney W. Grimes 		(&vm_page_array[atop(pa) - first_page ])
314df8bae1dSRodney W. Grimes 
3158f9110f6SJohn Dyson 
3160d94caffSDavid Greenman #if PAGE_SIZE == 4096
3170d94caffSDavid Greenman #define VM_PAGE_BITS_ALL 0xff
3180d94caffSDavid Greenman #endif
3190d94caffSDavid Greenman 
3200d94caffSDavid Greenman #if PAGE_SIZE == 8192
3210d94caffSDavid Greenman #define VM_PAGE_BITS_ALL 0xffff
3220d94caffSDavid Greenman #endif
3230d94caffSDavid Greenman 
3246d40c3d3SDavid Greenman #define VM_ALLOC_NORMAL		0
3256d40c3d3SDavid Greenman #define VM_ALLOC_INTERRUPT	1
3266d40c3d3SDavid Greenman #define VM_ALLOC_SYSTEM		2
327bd7e5f99SJohn Dyson #define	VM_ALLOC_ZERO		3
32895461b45SJohn Dyson #define	VM_ALLOC_RETRY		0x80
3290d94caffSDavid Greenman 
3301b40f8c0SMatthew Dillon void vm_page_flag_set(vm_page_t m, unsigned short bits);
3311b40f8c0SMatthew Dillon void vm_page_flag_clear(vm_page_t m, unsigned short bits);
3321b40f8c0SMatthew Dillon void vm_page_busy(vm_page_t m);
3331b40f8c0SMatthew Dillon void vm_page_flash(vm_page_t m);
3341b40f8c0SMatthew Dillon void vm_page_io_start(vm_page_t m);
3351b40f8c0SMatthew Dillon void vm_page_io_finish(vm_page_t m);
3361b40f8c0SMatthew Dillon void vm_page_hold(vm_page_t mem);
3371b40f8c0SMatthew Dillon void vm_page_unhold(vm_page_t mem);
3381b40f8c0SMatthew Dillon void vm_page_protect(vm_page_t mem, int prot);
3391b40f8c0SMatthew Dillon boolean_t vm_page_zero_fill(vm_page_t m);
3401b40f8c0SMatthew Dillon void vm_page_copy(vm_page_t src_m, vm_page_t dest_m);
3411b40f8c0SMatthew Dillon void vm_page_free(vm_page_t m);
3421b40f8c0SMatthew Dillon void vm_page_free_zero(vm_page_t m);
3431b40f8c0SMatthew Dillon int vm_page_sleep_busy(vm_page_t m, int also_m_busy, const char *msg);
3441b40f8c0SMatthew Dillon void vm_page_dirty(vm_page_t m);
3451b40f8c0SMatthew Dillon void vm_page_undirty(vm_page_t m);
3461b40f8c0SMatthew Dillon vm_page_t vm_page_list_find(int basequeue, int index, boolean_t prefer_zero);
3471b40f8c0SMatthew Dillon void vm_page_wakeup(vm_page_t m);
3481b40f8c0SMatthew Dillon 
3496d03d577SMatthew Dillon void vm_pageq_init(void);
3506d03d577SMatthew Dillon struct vpgqueues *vm_pageq_aquire(int queue);
3516d03d577SMatthew Dillon void vm_pageq_release(struct vpgqueues *vpq);
3526d03d577SMatthew Dillon vm_page_t vm_pageq_add_new_page(vm_offset_t pa);
3536d03d577SMatthew Dillon void vm_pageq_remove_nowakeup(vm_page_t m);
3546d03d577SMatthew Dillon void vm_pageq_remove(vm_page_t m);
3556d03d577SMatthew Dillon vm_page_t vm_pageq_find(int basequeue, int index, boolean_t prefer_zero);
3566d03d577SMatthew Dillon void vm_pageq_requeue(vm_page_t m);
3576d03d577SMatthew Dillon 
3581b40f8c0SMatthew Dillon void vm_page_activate (vm_page_t);
3591b40f8c0SMatthew Dillon vm_page_t vm_page_alloc (vm_object_t, vm_pindex_t, int);
3601b40f8c0SMatthew Dillon vm_page_t vm_page_grab (vm_object_t, vm_pindex_t, int);
3611b40f8c0SMatthew Dillon void vm_page_cache (register vm_page_t);
3621b40f8c0SMatthew Dillon int vm_page_try_to_cache (vm_page_t);
3631b40f8c0SMatthew Dillon int vm_page_try_to_free (vm_page_t);
3641b40f8c0SMatthew Dillon void vm_page_dontneed (register vm_page_t);
3651b40f8c0SMatthew Dillon void vm_page_deactivate (vm_page_t);
3661b40f8c0SMatthew Dillon void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t);
3671b40f8c0SMatthew Dillon vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t);
3681b40f8c0SMatthew Dillon void vm_page_remove (vm_page_t);
3691b40f8c0SMatthew Dillon void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t);
3701b40f8c0SMatthew Dillon vm_offset_t vm_page_startup (vm_offset_t, vm_offset_t, vm_offset_t);
3711b40f8c0SMatthew Dillon vm_page_t vm_add_new_page (vm_offset_t pa);
3721b40f8c0SMatthew Dillon void vm_page_unmanage (vm_page_t);
3731b40f8c0SMatthew Dillon void vm_page_unwire (vm_page_t, int);
3741b40f8c0SMatthew Dillon void vm_page_wire (vm_page_t);
3751b40f8c0SMatthew Dillon void vm_page_unqueue (vm_page_t);
3761b40f8c0SMatthew Dillon void vm_page_unqueue_nowakeup (vm_page_t);
3771b40f8c0SMatthew Dillon void vm_page_set_validclean (vm_page_t, int, int);
3781b40f8c0SMatthew Dillon void vm_page_set_dirty (vm_page_t, int, int);
3791b40f8c0SMatthew Dillon void vm_page_clear_dirty (vm_page_t, int, int);
3801b40f8c0SMatthew Dillon void vm_page_set_invalid (vm_page_t, int, int);
3811b40f8c0SMatthew Dillon int vm_page_is_valid (vm_page_t, int, int);
3821b40f8c0SMatthew Dillon void vm_page_test_dirty (vm_page_t);
3831b40f8c0SMatthew Dillon int vm_page_bits (int, int);
3841c7c3c6aSMatthew Dillon #if 0
385ffc82b0aSJohn Dyson int vm_page_sleep(vm_page_t m, char *msg, char *busy);
3861c7c3c6aSMatthew Dillon int vm_page_asleep(vm_page_t m, char *msg, char *busy);
3871c7c3c6aSMatthew Dillon #endif
3888d17e694SJulian Elischer void vm_page_zero_invalid(vm_page_t m, boolean_t setvalid);
389faa273d5SMatthew Dillon void vm_page_free_toq(vm_page_t m);
390d2fc5315SPoul-Henning Kamp 
391c4473420SPeter Wemm #endif				/* _KERNEL */
392df8bae1dSRodney W. Grimes #endif				/* !_VM_PAGE_ */
393