vmparam.h revision 974
14Srgrimes/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
4974Sdg * Copyright (c) 1994 John S. Dyson
5974Sdg * All rights reserved.
64Srgrimes *
74Srgrimes * This code is derived from software contributed to Berkeley by
84Srgrimes * William Jolitz.
94Srgrimes *
104Srgrimes * Redistribution and use in source and binary forms, with or without
114Srgrimes * modification, are permitted provided that the following conditions
124Srgrimes * are met:
134Srgrimes * 1. Redistributions of source code must retain the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer.
154Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
164Srgrimes *    notice, this list of conditions and the following disclaimer in the
174Srgrimes *    documentation and/or other materials provided with the distribution.
184Srgrimes * 3. All advertising materials mentioning features or use of this software
194Srgrimes *    must display the following acknowledgement:
204Srgrimes *	This product includes software developed by the University of
214Srgrimes *	California, Berkeley and its contributors.
224Srgrimes * 4. Neither the name of the University nor the names of its contributors
234Srgrimes *    may be used to endorse or promote products derived from this software
244Srgrimes *    without specific prior written permission.
254Srgrimes *
264Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
274Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
284Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
294Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
304Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
314Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
324Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
334Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
344Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
354Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
364Srgrimes * SUCH DAMAGE.
374Srgrimes *
38607Srgrimes *	from: @(#)vmparam.h	5.9 (Berkeley) 5/12/91
39974Sdg *	$Id: vmparam.h,v 1.10 1994/01/03 16:00:52 davidg Exp $
404Srgrimes */
414Srgrimes
424Srgrimes
43719Swollman#ifndef _MACHINE_VMPARAM_H_
44719Swollman#define _MACHINE_VMPARAM_H_ 1
45719Swollman
464Srgrimes/*
474Srgrimes * Machine dependent constants for 386.
484Srgrimes */
494Srgrimes
504Srgrimes/*
514Srgrimes * Virtual address space arrangement. On 386, both user and kernel
524Srgrimes * share the address space, not unlike the vax.
534Srgrimes * USRTEXT is the start of the user text/data space, while USRSTACK
544Srgrimes * is the top (end) of the user stack. Immediately above the user stack
554Srgrimes * resides the user structure, which is UPAGES long and contains the
564Srgrimes * kernel stack.
574Srgrimes *
584Srgrimes * Immediately after the user structure is the page table map, and then
594Srgrimes * kernal address space.
604Srgrimes */
61879Swollman#define	USRTEXT		0UL
62974Sdg/* #define	USRSTACK	0xFDBFE000UL */
634Srgrimes#define	BTOPUSRSTACK	(0xFDC00-(UPAGES))	/* btop(USRSTACK) */
64879Swollman#define	LOWPAGES	0UL
654Srgrimes#define HIGHPAGES	UPAGES
664Srgrimes
674Srgrimes/*
684Srgrimes * Virtual memory related constants, all in bytes
694Srgrimes */
70926Sdg#define	MAXTSIZ		(16UL*1024*1024)	/* max text size */
714Srgrimes#ifndef DFLDSIZ
72926Sdg#define	DFLDSIZ		(64UL*1024*1024)	/* initial data size limit */
734Srgrimes#endif
744Srgrimes#ifndef MAXDSIZ
75926Sdg#define	MAXDSIZ		(128UL*1024*1024)	/* max data size */
764Srgrimes#endif
774Srgrimes#ifndef	DFLSSIZ
78879Swollman#define	DFLSSIZ		(512UL*1024)		/* initial stack size limit */
794Srgrimes#endif
804Srgrimes#ifndef	MAXSSIZ
81926Sdg#define	MAXSSIZ		(64UL*1024*1024)	/* max stack size */
824Srgrimes#endif
834Srgrimes
844Srgrimes/*
854Srgrimes * Default sizes of swap allocation chunks (see dmap.h).
864Srgrimes * The actual values may be changed in vminit() based on MAXDSIZ.
874Srgrimes * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024.
884Srgrimes */
894Srgrimes#define	DMMIN	32			/* smallest swap allocation */
904Srgrimes#define	DMMAX	4096			/* largest potential swap allocation */
914Srgrimes#define	DMTEXT	1024			/* swap allocation for text */
924Srgrimes
934Srgrimes/*
944Srgrimes * Sizes of the system and user portions of the system page table.
954Srgrimes */
964Srgrimes#define	SYSPTSIZE 	(2*NPTEPG)
974Srgrimes#define	USRPTSIZE 	(2*NPTEPG)
984Srgrimes
994Srgrimes/*
100511Srgrimes * Size of the Shared Memory Pages page table.
101511Srgrimes */
102561Sdg#ifndef	SHMMAXPGS
103607Srgrimes#define	SHMMAXPGS	512		/* XXX until we have more kmap space */
104511Srgrimes#endif
105511Srgrimes
106511Srgrimes/*
1074Srgrimes * Size of User Raw I/O map
1084Srgrimes */
109974Sdg#define	USRIOSIZE 	1024
1104Srgrimes
1114Srgrimes/*
1124Srgrimes * The size of the clock loop.
1134Srgrimes */
1144Srgrimes#define	LOOPPAGES	(maxfree - firstfree)
1154Srgrimes
1164Srgrimes/*
1174Srgrimes * The time for a process to be blocked before being very swappable.
1184Srgrimes * This is a number of seconds which the system takes as being a non-trivial
1194Srgrimes * amount of real time.  You probably shouldn't change this;
1204Srgrimes * it is used in subtle ways (fractions and multiples of it are, that is, like
1214Srgrimes * half of a ``long time'', almost a long time, etc.)
1224Srgrimes * It is related to human patience and other factors which don't really
1234Srgrimes * change over time.
1244Srgrimes */
1254Srgrimes#define	MAXSLP 		20
1264Srgrimes
1274Srgrimes/*
1284Srgrimes * A swapped in process is given a small amount of core without being bothered
1294Srgrimes * by the page replacement algorithm.  Basically this says that if you are
1304Srgrimes * swapped in you deserve some resources.  We protect the last SAFERSS
1314Srgrimes * pages against paging and will just swap you out rather than paging you.
1324Srgrimes * Note that each process has at least UPAGES+CLSIZE pages which are not
1334Srgrimes * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this
1344Srgrimes * number just means a swapped in process is given around 25k bytes.
1354Srgrimes * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81),
1364Srgrimes * so we loan each swapped in process memory worth 100$, or just admit
1374Srgrimes * that we don't consider it worthwhile and swap it out to disk which costs
1384Srgrimes * $30/mb or about $0.75.
1394Srgrimes * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17
1404Srgrimes *   on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) }
1414Srgrimes */
1424Srgrimes#define	SAFERSS		8		/* nominal ``small'' resident set size
1434Srgrimes					   protected against replacement */
1444Srgrimes
1454Srgrimes/*
1464Srgrimes * DISKRPM is used to estimate the number of paging i/o operations
1474Srgrimes * which one can expect from a single disk controller.
1484Srgrimes */
1494Srgrimes#define	DISKRPM		60
1504Srgrimes
1514Srgrimes/*
1524Srgrimes * Klustering constants.  Klustering is the gathering
1534Srgrimes * of pages together for pagein/pageout, while clustering
1544Srgrimes * is the treatment of hardware page size as though it were
1554Srgrimes * larger than it really is.
1564Srgrimes *
1574Srgrimes * KLMAX gives maximum cluster size in CLSIZE page (cluster-page)
1584Srgrimes * units.  Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h.
1594Srgrimes */
1604Srgrimes
1614Srgrimes#define	KLMAX	(4/CLSIZE)
1624Srgrimes#define	KLSEQL	(2/CLSIZE)		/* in klust if vadvise(VA_SEQL) */
1634Srgrimes#define	KLIN	(4/CLSIZE)		/* default data/stack in klust */
1644Srgrimes#define	KLTXT	(4/CLSIZE)		/* default text in klust */
1654Srgrimes#define	KLOUT	(4/CLSIZE)
1664Srgrimes
1674Srgrimes/*
1684Srgrimes * KLSDIST is the advance or retard of the fifo reclaim for sequential
1694Srgrimes * processes data space.
1704Srgrimes */
1714Srgrimes#define	KLSDIST	3		/* klusters advance/retard for seq. fifo */
1724Srgrimes
1734Srgrimes/*
1744Srgrimes * Paging thresholds (see vm_sched.c).
1754Srgrimes * Strategy of 1/19/85:
1764Srgrimes *	lotsfree is 512k bytes, but at most 1/4 of memory
1774Srgrimes *	desfree is 200k bytes, but at most 1/8 of memory
1784Srgrimes *	minfree is 64k bytes, but at most 1/2 of desfree
1794Srgrimes */
1804Srgrimes#define	LOTSFREE	(512 * 1024)
1814Srgrimes#define	LOTSFREEFRACT	4
1824Srgrimes#define	DESFREE		(200 * 1024)
1834Srgrimes#define	DESFREEFRACT	8
1844Srgrimes#define	MINFREE		(64 * 1024)
1854Srgrimes#define	MINFREEFRACT	2
1864Srgrimes
1874Srgrimes/*
1884Srgrimes * There are two clock hands, initially separated by HANDSPREAD bytes
1894Srgrimes * (but at most all of user memory).  The amount of time to reclaim
1904Srgrimes * a page once the pageout process examines it increases with this
1914Srgrimes * distance and decreases as the scan rate rises.
1924Srgrimes */
1934Srgrimes#define	HANDSPREAD	(2 * 1024 * 1024)
1944Srgrimes
1954Srgrimes/*
1964Srgrimes * The number of times per second to recompute the desired paging rate
1974Srgrimes * and poke the pagedaemon.
1984Srgrimes */
1994Srgrimes#define	RATETOSCHEDPAGING	4
2004Srgrimes
2014Srgrimes/*
2024Srgrimes * Believed threshold (in megabytes) for which interleaved
2034Srgrimes * swapping area is desirable.
2044Srgrimes */
2054Srgrimes#define	LOTSOFMEM	2
2064Srgrimes
2074Srgrimes#define	mapin(pte, v, pfnum, prot) \
2084Srgrimes	{(*(int *)(pte) = ((pfnum)<<PGSHIFT) | (prot)) ; }
2094Srgrimes
2104Srgrimes/*
2114Srgrimes * Mach derived constants
2124Srgrimes */
2134Srgrimes
2144Srgrimes/* user/kernel map constants */
215974Sdg#define	KERNBASE (0-(NKPDE+1)*(NBPG*NPTEPG))
216974Sdg#define KERNSIZE (NKPDE*NBPG*NPTEPG)
217974Sdg
2184Srgrimes#define VM_MIN_ADDRESS		((vm_offset_t)0)
219974Sdg#define VM_MAXUSER_ADDRESS	((vm_offset_t)KERNBASE - (NBPG*(NPTEPG+UPAGES)))
220974Sdg#define USRSTACK VM_MAXUSER_ADDRESS
221974Sdg#define UPT_MIN_ADDRESS		((vm_offset_t)KERNBASE - (NBPG*NPTEPG))
222974Sdg#define UPT_MAX_ADDRESS		((vm_offset_t)KERNBASE - (NBPG*(NKPDE+2)))
2234Srgrimes#define VM_MAX_ADDRESS		UPT_MAX_ADDRESS
224974Sdg#define VM_MIN_KERNEL_ADDRESS	((vm_offset_t)KERNBASE - (NBPG*(NKPDE+2)))
2254Srgrimes#define UPDT			VM_MIN_KERNEL_ADDRESS
226974Sdg#define KPT_MIN_ADDRESS		((vm_offset_t)(KERNBASE) - (NBPG*(NKPDE+1)))
227974Sdg#define KPT_MAX_ADDRESS		((vm_offset_t)(KERNBASE) - NBPG)
228974Sdg#define VM_MAX_KERNEL_ADDRESS	((vm_offset_t)ALT_MIN_ADDRESS - NBPG)
229974Sdg#define ALT_MIN_ADDRESS		((vm_offset_t)((APTDPTDI) << 22))
230974Sdg#define HIGHPAGES UPAGES
2314Srgrimes
232974Sdg
2334Srgrimes/* virtual sizes (bytes) for various kernel submaps */
2344Srgrimes#define VM_MBUF_SIZE		(NMBCLUSTERS*MCLBYTES)
235607Srgrimes#define VM_KMEM_SIZE		(16 * 1024 * 1024)
2364Srgrimes#define VM_PHYS_SIZE		(USRIOSIZE*CLBYTES)
2374Srgrimes
2384Srgrimes/* pcb base */
2394Srgrimes#define	pcbb(p)		((u_int)(p)->p_addr)
2404Srgrimes
2414Srgrimes/*
2424Srgrimes * Flush MMU TLB
2434Srgrimes */
2444Srgrimes
2454Srgrimes#ifndef I386_CR3PAT
2464Srgrimes#define	I386_CR3PAT	0x0
2474Srgrimes#endif
2484Srgrimes
2494Srgrimes#ifdef notyet
2504Srgrimes#define _cr3() ({u_long rtn; \
2514Srgrimes	asm (" movl %%cr3,%%eax; movl %%eax,%0 " \
2524Srgrimes		: "=g" (rtn) \
2534Srgrimes		: \
2544Srgrimes		: "ax"); \
2554Srgrimes	rtn; \
2564Srgrimes})
2574Srgrimes
2584Srgrimes#define load_cr3(s) ({ u_long val; \
2594Srgrimes	val = (s) | I386_CR3PAT; \
2604Srgrimes	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
2614Srgrimes		:  \
2624Srgrimes		: "g" (val) \
2634Srgrimes		: "ax"); \
2644Srgrimes})
2654Srgrimes
2664Srgrimes#define tlbflush() ({ u_long val; \
2674Srgrimes	val = u.u_pcb.pcb_ptd | I386_CR3PAT; \
2684Srgrimes	asm ("movl %0,%%eax; movl %%eax,%%cr3" \
2694Srgrimes		:  \
2704Srgrimes		: "g" (val) \
2714Srgrimes		: "ax"); \
2724Srgrimes})
2734Srgrimes#endif
274719Swollman#endif /* _MACHINE_VMPARAM_H_ */
275