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