uvm.h revision 1.15
1/*	$OpenBSD: uvm.h,v 1.15 2001/11/28 19:28:14 art Exp $	*/
2/*	$NetBSD: uvm.h,v 1.30 2001/06/27 21:18:34 thorpej Exp $	*/
3
4/*
5 *
6 * Copyright (c) 1997 Charles D. Cranor and Washington University.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *      This product includes software developed by Charles D. Cranor and
20 *      Washington University.
21 * 4. The name of the author may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
36 */
37
38#ifndef _UVM_UVM_H_
39#define _UVM_UVM_H_
40
41#if defined(_KERNEL_OPT)
42#include "opt_lockdebug.h"
43#include "opt_multiprocessor.h"
44#include "opt_uvmhist.h"
45#endif
46
47#include <uvm/uvm_extern.h>
48
49#include <uvm/uvm_stat.h>
50
51/*
52 * pull in prototypes
53 */
54
55#include <uvm/uvm_amap.h>
56#include <uvm/uvm_aobj.h>
57#include <uvm/uvm_fault.h>
58#include <uvm/uvm_glue.h>
59#include <uvm/uvm_km.h>
60#include <uvm/uvm_loan.h>
61#include <uvm/uvm_map.h>
62#include <uvm/uvm_object.h>
63#include <uvm/uvm_page.h>
64#include <uvm/uvm_pager.h>
65#include <uvm/uvm_pdaemon.h>
66#include <uvm/uvm_swap.h>
67#ifdef UVM_SWAP_ENCRYPT
68#include <uvm/uvm_swap_encrypt.h>
69#endif
70
71/*
72 * pull in VM_NFREELIST
73 */
74#include <machine/vmparam.h>
75
76/*
77 * uvm structure (vm global state: collected in one structure for ease
78 * of reference...)
79 */
80
81struct uvm {
82	/* vm_page related parameters */
83
84		/* vm_page queues */
85	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
86	int page_free_nextcolor;	/* next color to allocate from */
87	struct pglist page_active;	/* allocated pages, in use */
88	struct pglist page_inactive;	/* pages between the clock hands */
89	struct simplelock pageqlock;	/* lock for active/inactive page q */
90	struct simplelock fpageqlock;	/* lock for free page q */
91	boolean_t page_init_done;	/* TRUE if uvm_page_init() finished */
92	boolean_t page_idle_zero;	/* TRUE if we should try to zero
93					   pages in the idle loop */
94
95		/* page daemon trigger */
96	int pagedaemon;			/* daemon sleeps on this */
97	struct proc *pagedaemon_proc;	/* daemon's pid */
98	struct simplelock pagedaemon_lock;
99
100		/* aiodone daemon trigger */
101	int aiodoned;			/* daemon sleeps on this */
102	struct proc *aiodoned_proc;	/* daemon's pid */
103	struct simplelock aiodoned_lock;
104
105		/* page hash */
106	struct pglist *page_hash;	/* page hash table (vp/off->page) */
107	int page_nhash;			/* number of buckets */
108	int page_hashmask;		/* hash mask */
109	struct simplelock hashlock;	/* lock on page_hash array */
110
111	/* anon stuff */
112	struct vm_anon *afree;		/* anon free list */
113	struct simplelock afreelock; 	/* lock on anon free list */
114
115	/* static kernel map entry pool */
116	struct vm_map_entry *kentry_free;	/* free page pool */
117	struct simplelock kentry_lock;
118
119	/* aio_done is locked by uvm.pagedaemon_lock and splbio! */
120	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
121
122	/* pager VM area bounds */
123	vaddr_t pager_sva;		/* start of pager VA area */
124	vaddr_t pager_eva;		/* end of pager VA area */
125
126	/* swap-related items */
127	struct simplelock swap_data_lock;
128
129	/* kernel object: to support anonymous pageable kernel memory */
130	struct uvm_object *kernel_object;
131};
132
133/*
134 * vm_map_entry etype bits:
135 */
136
137#define UVM_ET_OBJ		0x01	/* it is a uvm_object */
138#define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
139#define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
140#define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
141
142#define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
143#define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
144#define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
145#define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
146
147#ifdef _KERNEL
148
149/*
150 * holds all the internal UVM data
151 */
152extern struct uvm uvm;
153
154/*
155 * historys
156 */
157
158UVMHIST_DECL(maphist);
159UVMHIST_DECL(pdhist);
160UVMHIST_DECL(ubchist);
161
162/*
163 * UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
164 * interlocked tsleep() function.
165 */
166
167#define	UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo)		\
168do {									\
169	(void) ltsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0),	\
170	    msg, timo, slock);						\
171} while (0)
172
173/*
174 * UVM_KICK_PDAEMON: perform checks to determine if we need to
175 * give the pagedaemon a nudge, and do so if necessary.
176 */
177
178#define	UVM_KICK_PDAEMON()						\
179do {									\
180	if (uvmexp.free + uvmexp.paging < uvmexp.freemin ||		\
181	    (uvmexp.free + uvmexp.paging < uvmexp.freetarg &&		\
182	     uvmexp.inactive < uvmexp.inactarg)) {			\
183		wakeup(&uvm.pagedaemon);				\
184	}								\
185} while (/*CONSTCOND*/0)
186
187/*
188 * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
189 */
190
191#if defined(UVM_PAGE_TRKOWN)
192#define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
193#else
194#define UVM_PAGE_OWN(PG, TAG) /* nothing */
195#endif /* UVM_PAGE_TRKOWN */
196
197/*
198 * pull in inlines
199 */
200
201#include <uvm/uvm_amap_i.h>
202#include <uvm/uvm_fault_i.h>
203#include <uvm/uvm_map_i.h>
204#include <uvm/uvm_page_i.h>
205#include <uvm/uvm_pager_i.h>
206
207#endif /* _KERNEL */
208
209#endif /* _UVM_UVM_H_ */
210