xref: /original-bsd/sys/vm/vm_page.h (revision 3705696b)
1 /*
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * The Mach Operating System project at Carnegie-Mellon University.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)vm_page.h	8.1 (Berkeley) 06/11/93
11  *
12  *
13  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
14  * All rights reserved.
15  *
16  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
17  *
18  * Permission to use, copy, modify and distribute this software and
19  * its documentation is hereby granted, provided that both the copyright
20  * notice and this permission notice appear in all copies of the
21  * software, derivative works or modified versions, and any portions
22  * thereof, and that both notices appear in supporting documentation.
23  *
24  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
25  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
26  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
27  *
28  * Carnegie Mellon requests users of this software to return to
29  *
30  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
31  *  School of Computer Science
32  *  Carnegie Mellon University
33  *  Pittsburgh PA 15213-3890
34  *
35  * any improvements or extensions that they make and grant Carnegie the
36  * rights to redistribute these changes.
37  */
38 
39 /*
40  *	Resident memory system definitions.
41  */
42 
43 #ifndef	_VM_PAGE_
44 #define	_VM_PAGE_
45 
46 /*
47  *	Management of resident (logical) pages.
48  *
49  *	A small structure is kept for each resident
50  *	page, indexed by page number.  Each structure
51  *	is an element of several lists:
52  *
53  *		A hash table bucket used to quickly
54  *		perform object/offset lookups
55  *
56  *		A list of all pages for a given object,
57  *		so they can be quickly deactivated at
58  *		time of deallocation.
59  *
60  *		An ordered list of pages due for pageout.
61  *
62  *	In addition, the structure contains the object
63  *	and offset to which this page belongs (for pageout),
64  *	and sundry status bits.
65  *
66  *	Fields in this structure are locked either by the lock on the
67  *	object that the page belongs to (O) or by the lock on the page
68  *	queues (P).
69  */
70 
71 struct vm_page {
72 	queue_chain_t	pageq;		/* queue info for FIFO
73 					 * queue or free list (P) */
74 	queue_chain_t	hashq;		/* hash table links (O)*/
75 	queue_chain_t	listq;		/* all pages in same object (O)*/
76 
77 	vm_object_t	object;		/* which object am I in (O,P)*/
78 	vm_offset_t	offset;		/* offset into that object (O,P) */
79 
80 	u_short		wire_count;	/* number wired down maps use me? (P) */
81 	u_short		flags;		/* see below */
82 
83 	vm_offset_t	phys_addr;	/* physical address of page */
84 };
85 
86 /*
87  * These are the flags defined for vm_page.
88  *
89  * Note: PG_FILLED and PG_DIRTY are added for the filesystems.
90  */
91 #define	PG_INACTIVE	0x0001		/* page is in inactive list (P) */
92 #define	PG_ACTIVE	0x0002		/* page is in active list (P) */
93 #define	PG_LAUNDRY	0x0004		/* page is being cleaned now (P)*/
94 #define	PG_CLEAN	0x0008		/* page has not been modified */
95 #define	PG_BUSY		0x0010		/* page is in transit (O) */
96 #define	PG_WANTED	0x0020		/* someone is waiting for page (O) */
97 #define	PG_TABLED	0x0040		/* page is in VP table (O) */
98 #define	PG_COPYONWRITE	0x0080		/* must copy page before changing (O) */
99 #define	PG_FICTITIOUS	0x0100		/* physical page doesn't exist (O) */
100 #define	PG_FAKE		0x0200		/* page is placeholder for pagein (O) */
101 #define	PG_FILLED	0x0400		/* client flag to set when filled */
102 #define	PG_DIRTY	0x0800		/* client flag to set when dirty */
103 #define	PG_PAGEROWNED	0x4000		/* DEBUG: async paging op in progress */
104 #define	PG_PTPAGE	0x8000		/* DEBUG: is a user page table page */
105 
106 #if	VM_PAGE_DEBUG
107 #define	VM_PAGE_CHECK(mem) { \
108 	if ((((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \
109 	    (((unsigned int) mem) > \
110 		((unsigned int) &vm_page_array[last_page-first_page])) || \
111 	    ((mem->flags & (PG_ACTIVE | PG_INACTIVE)) == \
112 		(PG_ACTIVE | PG_INACTIVE))) \
113 		panic("vm_page_check: not valid!"); \
114 }
115 #else /* VM_PAGE_DEBUG */
116 #define	VM_PAGE_CHECK(mem)
117 #endif /* VM_PAGE_DEBUG */
118 
119 #ifdef KERNEL
120 /*
121  *	Each pageable resident page falls into one of three lists:
122  *
123  *	free
124  *		Available for allocation now.
125  *	inactive
126  *		Not referenced in any map, but still has an
127  *		object/offset-page mapping, and may be dirty.
128  *		This is the list of pages that should be
129  *		paged out next.
130  *	active
131  *		A list of pages which have been placed in
132  *		at least one physical map.  This list is
133  *		ordered, in LRU-like fashion.
134  */
135 
136 extern
137 queue_head_t	vm_page_queue_free;	/* memory free queue */
138 extern
139 queue_head_t	vm_page_queue_active;	/* active memory queue */
140 extern
141 queue_head_t	vm_page_queue_inactive;	/* inactive memory queue */
142 
143 extern
144 vm_page_t	vm_page_array;		/* First resident page in table */
145 extern
146 long		first_page;		/* first physical page number */
147 					/* ... represented in vm_page_array */
148 extern
149 long		last_page;		/* last physical page number */
150 					/* ... represented in vm_page_array */
151 					/* [INCLUSIVE] */
152 extern
153 vm_offset_t	first_phys_addr;	/* physical address for first_page */
154 extern
155 vm_offset_t	last_phys_addr;		/* physical address for last_page */
156 
157 #define VM_PAGE_TO_PHYS(entry)	((entry)->phys_addr)
158 
159 #define IS_VM_PHYSADDR(pa) \
160 		((pa) >= first_phys_addr && (pa) <= last_phys_addr)
161 
162 #define PHYS_TO_VM_PAGE(pa) \
163 		(&vm_page_array[atop(pa) - first_page ])
164 
165 extern
166 simple_lock_data_t	vm_page_queue_lock;	/* lock on active and inactive
167 						   page queues */
168 extern						/* lock on free page queue */
169 simple_lock_data_t	vm_page_queue_free_lock;
170 
171 /*
172  *	Functions implemented as macros
173  */
174 
175 #define PAGE_ASSERT_WAIT(m, interruptible)	{ \
176 				(m)->flags |= PG_WANTED; \
177 				assert_wait((int) (m), (interruptible)); \
178 			}
179 
180 #define PAGE_WAKEUP(m)	{ \
181 				(m)->flags &= ~PG_BUSY; \
182 				if ((m)->flags & PG_WANTED) { \
183 					(m)->flags &= ~PG_WANTED; \
184 					thread_wakeup((int) (m)); \
185 				} \
186 			}
187 
188 #define	vm_page_lock_queues()	simple_lock(&vm_page_queue_lock)
189 #define	vm_page_unlock_queues()	simple_unlock(&vm_page_queue_lock)
190 
191 #define vm_page_set_modified(m)	{ (m)->flags &= ~PG_CLEAN; }
192 
193 #define	VM_PAGE_INIT(mem, object, offset) { \
194 	(mem)->flags = PG_BUSY | PG_CLEAN | PG_FAKE; \
195 	vm_page_insert((mem), (object), (offset)); \
196 	(mem)->wire_count = 0; \
197 }
198 
199 void		 vm_page_activate __P((vm_page_t));
200 vm_page_t	 vm_page_alloc __P((vm_object_t, vm_offset_t));
201 void		 vm_page_copy __P((vm_page_t, vm_page_t));
202 void		 vm_page_deactivate __P((vm_page_t));
203 void		 vm_page_free __P((vm_page_t));
204 void		 vm_page_insert __P((vm_page_t, vm_object_t, vm_offset_t));
205 vm_page_t	 vm_page_lookup __P((vm_object_t, vm_offset_t));
206 void		 vm_page_remove __P((vm_page_t));
207 void		 vm_page_rename __P((vm_page_t, vm_object_t, vm_offset_t));
208 void		 vm_page_startup __P((vm_offset_t *, vm_offset_t *));
209 void		 vm_page_unwire __P((vm_page_t));
210 void		 vm_page_wire __P((vm_page_t));
211 boolean_t	 vm_page_zero_fill __P((vm_page_t));
212 
213 #endif /* KERNEL */
214 #endif /* !_VM_PAGE_ */
215