xref: /original-bsd/sys/i386/include/vmparam.h (revision c520bfa7)
1 /*-
2  * Copyright (c) 1990, 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  * William Jolitz.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)vmparam.h	8.2 (Berkeley) 04/22/94
11  */
12 
13 
14 /*
15  * Machine dependent constants for 386.
16  */
17 
18 /*
19  * Virtual address space arrangement. On 386, both user and kernel
20  * share the address space, not unlike the vax.
21  * USRTEXT is the start of the user text/data space, while USRSTACK
22  * is the top (end) of the user stack. Immediately above the user stack
23  * resides the user structure, which is UPAGES long and contains the
24  * kernel stack.
25  *
26  * Immediately after the user structure is the page table map, and then
27  * kernal address space.
28  */
29 #define	USRTEXT		0
30 #define	USRSTACK	0xFDBFE000
31 #define	BTOPUSRSTACK	(0xFDC00-(UPAGES))	/* btop(USRSTACK) */
32 #define	LOWPAGES	0
33 #define HIGHPAGES	UPAGES
34 
35 /*
36  * Virtual memory related constants, all in bytes
37  */
38 #define	MAXTSIZ		(6*1024*1024)		/* max text size */
39 #ifndef DFLDSIZ
40 #define	DFLDSIZ		(6*1024*1024)		/* initial data size limit */
41 #endif
42 #ifndef MAXDSIZ
43 #define	MAXDSIZ		(32*1024*1024)		/* max data size */
44 #endif
45 #ifndef	DFLSSIZ
46 #define	DFLSSIZ		(512*1024)		/* initial stack size limit */
47 #endif
48 #ifndef	MAXSSIZ
49 #define	MAXSSIZ		MAXDSIZ			/* max stack size */
50 #endif
51 
52 /*
53  * Default sizes of swap allocation chunks (see dmap.h).
54  * The actual values may be changed in vminit() based on MAXDSIZ.
55  * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024.
56  */
57 #define	DMMIN	32			/* smallest swap allocation */
58 #define	DMMAX	4096			/* largest potential swap allocation */
59 #define	DMTEXT	1024			/* swap allocation for text */
60 
61 /*
62  * Sizes of the system and user portions of the system page table.
63  */
64 #define	SYSPTSIZE 	(2*NPTEPG)
65 #define	USRPTSIZE 	(2*NPTEPG)
66 
67 /*
68  * Size of User Raw I/O map
69  */
70 #define	USRIOSIZE 	300
71 
72 /*
73  * The size of the clock loop.
74  */
75 #define	LOOPPAGES	(maxfree - firstfree)
76 
77 /*
78  * The time for a process to be blocked before being very swappable.
79  * This is a number of seconds which the system takes as being a non-trivial
80  * amount of real time.  You probably shouldn't change this;
81  * it is used in subtle ways (fractions and multiples of it are, that is, like
82  * half of a ``long time'', almost a long time, etc.)
83  * It is related to human patience and other factors which don't really
84  * change over time.
85  */
86 #define	MAXSLP 		20
87 
88 /*
89  * A swapped in process is given a small amount of core without being bothered
90  * by the page replacement algorithm.  Basically this says that if you are
91  * swapped in you deserve some resources.  We protect the last SAFERSS
92  * pages against paging and will just swap you out rather than paging you.
93  * Note that each process has at least UPAGES+CLSIZE pages which are not
94  * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this
95  * number just means a swapped in process is given around 25k bytes.
96  * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81),
97  * so we loan each swapped in process memory worth 100$, or just admit
98  * that we don't consider it worthwhile and swap it out to disk which costs
99  * $30/mb or about $0.75.
100  * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17
101  *   on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) }
102  */
103 #define	SAFERSS		8		/* nominal ``small'' resident set size
104 					   protected against replacement */
105 
106 /*
107  * DISKRPM is used to estimate the number of paging i/o operations
108  * which one can expect from a single disk controller.
109  */
110 #define	DISKRPM		60
111 
112 /*
113  * Klustering constants.  Klustering is the gathering
114  * of pages together for pagein/pageout, while clustering
115  * is the treatment of hardware page size as though it were
116  * larger than it really is.
117  *
118  * KLMAX gives maximum cluster size in CLSIZE page (cluster-page)
119  * units.  Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h.
120  */
121 
122 #define	KLMAX	(4/CLSIZE)
123 #define	KLSEQL	(2/CLSIZE)		/* in klust if vadvise(VA_SEQL) */
124 #define	KLIN	(4/CLSIZE)		/* default data/stack in klust */
125 #define	KLTXT	(4/CLSIZE)		/* default text in klust */
126 #define	KLOUT	(4/CLSIZE)
127 
128 /*
129  * KLSDIST is the advance or retard of the fifo reclaim for sequential
130  * processes data space.
131  */
132 #define	KLSDIST	3		/* klusters advance/retard for seq. fifo */
133 
134 /*
135  * Paging thresholds (see vm_sched.c).
136  * Strategy of 1/19/85:
137  *	lotsfree is 512k bytes, but at most 1/4 of memory
138  *	desfree is 200k bytes, but at most 1/8 of memory
139  */
140 #define	LOTSFREE	(512 * 1024)
141 #define	LOTSFREEFRACT	4
142 #define	DESFREE		(200 * 1024)
143 #define	DESFREEFRACT	8
144 
145 /*
146  * There are two clock hands, initially separated by HANDSPREAD bytes
147  * (but at most all of user memory).  The amount of time to reclaim
148  * a page once the pageout process examines it increases with this
149  * distance and decreases as the scan rate rises.
150  */
151 #define	HANDSPREAD	(2 * 1024 * 1024)
152 
153 /*
154  * The number of times per second to recompute the desired paging rate
155  * and poke the pagedaemon.
156  */
157 #define	RATETOSCHEDPAGING	4
158 
159 /*
160  * Believed threshold (in megabytes) for which interleaved
161  * swapping area is desirable.
162  */
163 #define	LOTSOFMEM	2
164 
165 #define	mapin(pte, v, pfnum, prot) \
166 	{(*(int *)(pte) = ((pfnum)<<PGSHIFT) | (prot)) ; }
167 
168 /*
169  * Mach derived constants
170  */
171 
172 /* user/kernel map constants */
173 #define VM_MIN_ADDRESS		((vm_offset_t)0)
174 #define VM_MAXUSER_ADDRESS	((vm_offset_t)0xFDBFD000)
175 #define UPT_MIN_ADDRESS		((vm_offset_t)0xFDC00000)
176 #define UPT_MAX_ADDRESS		((vm_offset_t)0xFDFF7000)
177 #define VM_MAX_ADDRESS		UPT_MAX_ADDRESS
178 #define VM_MIN_KERNEL_ADDRESS	((vm_offset_t)0xFDFF7000)
179 #define UPDT			VM_MIN_KERNEL_ADDRESS
180 #define KPT_MIN_ADDRESS		((vm_offset_t)0xFDFF8000)
181 #define KPT_MAX_ADDRESS		((vm_offset_t)0xFDFFF000)
182 #define VM_MAX_KERNEL_ADDRESS	((vm_offset_t)0xFF7FF000)
183 
184 /* virtual sizes (bytes) for various kernel submaps */
185 #define VM_MBUF_SIZE		(NMBCLUSTERS*MCLBYTES)
186 #define VM_KMEM_SIZE		(NKMEMCLUSTERS*CLBYTES)
187 #define VM_PHYS_SIZE		(USRIOSIZE*CLBYTES)
188 
189 /* # of kernel PT pages (initial only, can grow dynamically) */
190 #define VM_KERNEL_PT_PAGES	((vm_size_t)2)		/* XXX: SYSPTSIZE */
191 
192 /* pcb base */
193 #define	pcbb(p)		((u_int)(p)->p_addr)
194 
195 /*
196  * Flush MMU TLB
197  */
198 
199 #ifndef I386_CR3PAT
200 #define	I386_CR3PAT	0x0
201 #endif
202 
203 #ifdef notyet
204 #define _cr3() ({u_long rtn; \
205 	asm (" movl %%cr3,%%eax; movl %%eax,%0 " \
206 		: "=g" (rtn) \
207 		: \
208 		: "ax"); \
209 	rtn; \
210 })
211 
212 #define load_cr3(s) ({ u_long val; \
213 	val = (s) | I386_CR3PAT; \
214 	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
215 		:  \
216 		: "g" (val) \
217 		: "ax"); \
218 })
219 
220 #define tlbflush() ({ u_long val; \
221 	val = u.u_pcb.pcb_ptd | I386_CR3PAT; \
222 	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
223 		:  \
224 		: "g" (val) \
225 		: "ax"); \
226 })
227 #endif
228