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