xref: /freebsd/sys/i386/include/vmparam.h (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  * Copyright (c) 1994 John S. Dyson
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	from: @(#)vmparam.h	5.9 (Berkeley) 5/12/91
39  *	$Id: vmparam.h,v 1.11 1994/01/14 16:24:00 davidg Exp $
40  */
41 
42 
43 #ifndef _MACHINE_VMPARAM_H_
44 #define _MACHINE_VMPARAM_H_ 1
45 
46 /*
47  * Machine dependent constants for 386.
48  */
49 
50 /*
51  * Virtual address space arrangement. On 386, both user and kernel
52  * share the address space, not unlike the vax.
53  * USRTEXT is the start of the user text/data space, while USRSTACK
54  * is the top (end) of the user stack. Immediately above the user stack
55  * resides the user structure, which is UPAGES long and contains the
56  * kernel stack.
57  *
58  * Immediately after the user structure is the page table map, and then
59  * kernal address space.
60  */
61 #define	USRTEXT		0UL
62 /* #define	USRSTACK	0xFDBFE000UL */
63 #define	BTOPUSRSTACK	(0xFDC00-(UPAGES))	/* btop(USRSTACK) */
64 #define	LOWPAGES	0UL
65 #define HIGHPAGES	UPAGES
66 
67 /*
68  * Virtual memory related constants, all in bytes
69  */
70 #define	MAXTSIZ		(16UL*1024*1024)	/* max text size */
71 #ifndef DFLDSIZ
72 #define	DFLDSIZ		(64UL*1024*1024)	/* initial data size limit */
73 #endif
74 #ifndef MAXDSIZ
75 #define	MAXDSIZ		(128UL*1024*1024)	/* max data size */
76 #endif
77 #ifndef	DFLSSIZ
78 #define	DFLSSIZ		(8UL*1024*1024)		/* initial stack size limit */
79 #endif
80 #ifndef	MAXSSIZ
81 #define	MAXSSIZ		(64UL*1024*1024)	/* max stack size */
82 #endif
83 #ifndef SGROWSIZ
84 #define SGROWSIZ	(128UL*1024)		/* amount to grow stack */
85 #endif
86 
87 /*
88  * Default sizes of swap allocation chunks (see dmap.h).
89  * The actual values may be changed in vminit() based on MAXDSIZ.
90  * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024.
91  */
92 #define	DMMIN	32			/* smallest swap allocation */
93 #define	DMMAX	4096			/* largest potential swap allocation */
94 #define	DMTEXT	1024			/* swap allocation for text */
95 
96 /*
97  * Sizes of the system and user portions of the system page table.
98  */
99 #define	SYSPTSIZE 	(2*NPTEPG)
100 #define	USRPTSIZE 	(2*NPTEPG)
101 
102 /*
103  * Size of the Shared Memory Pages page table.
104  */
105 #ifndef	SHMMAXPGS
106 #define	SHMMAXPGS	512		/* XXX until we have more kmap space */
107 #endif
108 
109 /*
110  * Size of User Raw I/O map
111  */
112 #define	USRIOSIZE 	1024
113 
114 /*
115  * The size of the clock loop.
116  */
117 #define	LOOPPAGES	(maxfree - firstfree)
118 
119 /*
120  * The time for a process to be blocked before being very swappable.
121  * This is a number of seconds which the system takes as being a non-trivial
122  * amount of real time.  You probably shouldn't change this;
123  * it is used in subtle ways (fractions and multiples of it are, that is, like
124  * half of a ``long time'', almost a long time, etc.)
125  * It is related to human patience and other factors which don't really
126  * change over time.
127  */
128 #define	MAXSLP 		20
129 
130 /*
131  * A swapped in process is given a small amount of core without being bothered
132  * by the page replacement algorithm.  Basically this says that if you are
133  * swapped in you deserve some resources.  We protect the last SAFERSS
134  * pages against paging and will just swap you out rather than paging you.
135  * Note that each process has at least UPAGES+CLSIZE pages which are not
136  * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this
137  * number just means a swapped in process is given around 25k bytes.
138  * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81),
139  * so we loan each swapped in process memory worth 100$, or just admit
140  * that we don't consider it worthwhile and swap it out to disk which costs
141  * $30/mb or about $0.75.
142  * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17
143  *   on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) }
144  */
145 #define	SAFERSS		8		/* nominal ``small'' resident set size
146 					   protected against replacement */
147 
148 /*
149  * DISKRPM is used to estimate the number of paging i/o operations
150  * which one can expect from a single disk controller.
151  */
152 #define	DISKRPM		60
153 
154 /*
155  * Klustering constants.  Klustering is the gathering
156  * of pages together for pagein/pageout, while clustering
157  * is the treatment of hardware page size as though it were
158  * larger than it really is.
159  *
160  * KLMAX gives maximum cluster size in CLSIZE page (cluster-page)
161  * units.  Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h.
162  */
163 
164 #define	KLMAX	(4/CLSIZE)
165 #define	KLSEQL	(2/CLSIZE)		/* in klust if vadvise(VA_SEQL) */
166 #define	KLIN	(4/CLSIZE)		/* default data/stack in klust */
167 #define	KLTXT	(4/CLSIZE)		/* default text in klust */
168 #define	KLOUT	(4/CLSIZE)
169 
170 /*
171  * KLSDIST is the advance or retard of the fifo reclaim for sequential
172  * processes data space.
173  */
174 #define	KLSDIST	3		/* klusters advance/retard for seq. fifo */
175 
176 /*
177  * There are two clock hands, initially separated by HANDSPREAD bytes
178  * (but at most all of user memory).  The amount of time to reclaim
179  * a page once the pageout process examines it increases with this
180  * distance and decreases as the scan rate rises.
181  */
182 #define	HANDSPREAD	(2 * 1024 * 1024)
183 
184 /*
185  * The number of times per second to recompute the desired paging rate
186  * and poke the pagedaemon.
187  */
188 #define	RATETOSCHEDPAGING	4
189 
190 /*
191  * Believed threshold (in megabytes) for which interleaved
192  * swapping area is desirable.
193  */
194 #define	LOTSOFMEM	2
195 
196 #define	mapin(pte, v, pfnum, prot) \
197 	{(*(int *)(pte) = ((pfnum)<<PGSHIFT) | (prot)) ; }
198 
199 /*
200  * Mach derived constants
201  */
202 
203 /* user/kernel map constants */
204 #define	KERNBASE (0-(NKPDE+1)*(NBPG*NPTEPG))
205 #define KERNSIZE (NKPDE*NBPG*NPTEPG)
206 
207 #define VM_MIN_ADDRESS		((vm_offset_t)0)
208 #define VM_MAXUSER_ADDRESS	((vm_offset_t)KERNBASE - (NBPG*(NPTEPG+UPAGES)))
209 #define USRSTACK VM_MAXUSER_ADDRESS
210 #define UPT_MIN_ADDRESS		((vm_offset_t)KERNBASE - (NBPG*NPTEPG))
211 #define UPT_MAX_ADDRESS		((vm_offset_t)KERNBASE - (NBPG*(NKPDE+2)))
212 #define VM_MAX_ADDRESS		UPT_MAX_ADDRESS
213 #define VM_MIN_KERNEL_ADDRESS	((vm_offset_t)KERNBASE - (NBPG*(NKPDE+2)))
214 #define UPDT			VM_MIN_KERNEL_ADDRESS
215 #define KPT_MIN_ADDRESS		((vm_offset_t)(KERNBASE) - (NBPG*(NKPDE+1)))
216 #define KPT_MAX_ADDRESS		((vm_offset_t)(KERNBASE) - NBPG)
217 #define VM_MAX_KERNEL_ADDRESS	((vm_offset_t)ALT_MIN_ADDRESS - NBPG)
218 #define ALT_MIN_ADDRESS		((vm_offset_t)((APTDPTDI) << 22))
219 #define HIGHPAGES UPAGES
220 
221 
222 /* virtual sizes (bytes) for various kernel submaps */
223 #define VM_MBUF_SIZE		(NMBCLUSTERS*MCLBYTES)
224 #define VM_KMEM_SIZE		(16 * 1024 * 1024)
225 #define VM_PHYS_SIZE		(USRIOSIZE*CLBYTES)
226 
227 /* pcb base */
228 #define	pcbb(p)		((u_int)(p)->p_addr)
229 
230 /*
231  * Flush MMU TLB
232  */
233 
234 #ifndef I386_CR3PAT
235 #define	I386_CR3PAT	0x0
236 #endif
237 
238 #ifdef notyet
239 #define _cr3() ({u_long rtn; \
240 	asm (" movl %%cr3,%%eax; movl %%eax,%0 " \
241 		: "=g" (rtn) \
242 		: \
243 		: "ax"); \
244 	rtn; \
245 })
246 
247 #define load_cr3(s) ({ u_long val; \
248 	val = (s) | I386_CR3PAT; \
249 	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
250 		:  \
251 		: "g" (val) \
252 		: "ax"); \
253 })
254 
255 #define tlbflush() ({ u_long val; \
256 	val = u.u_pcb.pcb_ptd | I386_CR3PAT; \
257 	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
258 		:  \
259 		: "g" (val) \
260 		: "ax"); \
261 })
262 #endif
263 #endif /* _MACHINE_VMPARAM_H_ */
264