141062Swilliam /*- 241062Swilliam * Copyright (c) 1990 The Regents of the University of California. 341062Swilliam * All rights reserved. 441062Swilliam * 541062Swilliam * This code is derived from software contributed to Berkeley by 641062Swilliam * William Jolitz. 741062Swilliam * 846006Swilliam * %sccs.include.redist.c% 941062Swilliam * 10*49523Swilliam * @(#)vmparam.h 5.8 (Berkeley) 05/09/91 1141062Swilliam */ 1241062Swilliam 1345964Swilliam 1441062Swilliam /* 1541062Swilliam * Machine dependent constants for 386. 1641062Swilliam */ 1741062Swilliam 1841062Swilliam /* 1941062Swilliam * Virtual address space arrangement. On 386, both user and kernel 2045964Swilliam * share the address space, not unlike the vax. 2141062Swilliam * USRTEXT is the start of the user text/data space, while USRSTACK 2241062Swilliam * is the top (end) of the user stack. Immediately above the user stack 2341062Swilliam * resides the user structure, which is UPAGES long and contains the 24*49523Swilliam * kernel stack. 25*49523Swilliam * 26*49523Swilliam * Immediately after the user structure is the page table map, and then 27*49523Swilliam * kernal address space. 2841062Swilliam */ 2941062Swilliam #define USRTEXT 0 30*49523Swilliam #define USRSTACK 0xFDBFD000 3148000Swilliam #define BTOPUSRSTACK (0xFDC00-(UPAGES)) /* btop(USRSTACK) */ 3241062Swilliam #define LOWPAGES 0 3341062Swilliam #define HIGHPAGES UPAGES 3441062Swilliam 3541062Swilliam /* 3641062Swilliam * Virtual memory related constants, all in bytes 3741062Swilliam */ 3841062Swilliam #define MAXTSIZ (6*1024*1024) /* max text size */ 3941062Swilliam #ifndef DFLDSIZ 4041062Swilliam #define DFLDSIZ (6*1024*1024) /* initial data size limit */ 4141062Swilliam #endif 4241062Swilliam #ifndef MAXDSIZ 4341062Swilliam #define MAXDSIZ (32*1024*1024) /* max data size */ 4441062Swilliam #endif 4541062Swilliam #ifndef DFLSSIZ 4641062Swilliam #define DFLSSIZ (512*1024) /* initial stack size limit */ 4741062Swilliam #endif 4841062Swilliam #ifndef MAXSSIZ 4941062Swilliam #define MAXSSIZ MAXDSIZ /* max stack size */ 5041062Swilliam #endif 5141062Swilliam 5241062Swilliam /* 5341062Swilliam * Default sizes of swap allocation chunks (see dmap.h). 5441062Swilliam * The actual values may be changed in vminit() based on MAXDSIZ. 5541062Swilliam * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024. 5641062Swilliam */ 5741062Swilliam #define DMMIN 32 /* smallest swap allocation */ 5841062Swilliam #define DMMAX 4096 /* largest potential swap allocation */ 5941062Swilliam #define DMTEXT 1024 /* swap allocation for text */ 6041062Swilliam 6141062Swilliam /* 6241062Swilliam * Sizes of the system and user portions of the system page table. 6341062Swilliam */ 6441062Swilliam #define SYSPTSIZE (2*NPTEPG) 6541062Swilliam #define USRPTSIZE (2*NPTEPG) 6641062Swilliam 6741062Swilliam /* 6845593Sbill * Size of User Raw I/O map 6945593Sbill */ 7045964Swilliam #define USRIOSIZE 300 7145593Sbill 7245593Sbill /* 7341062Swilliam * The size of the clock loop. 7441062Swilliam */ 7541062Swilliam #define LOOPPAGES (maxfree - firstfree) 7641062Swilliam 7741062Swilliam /* 7841062Swilliam * The time for a process to be blocked before being very swappable. 7941062Swilliam * This is a number of seconds which the system takes as being a non-trivial 8041062Swilliam * amount of real time. You probably shouldn't change this; 8141062Swilliam * it is used in subtle ways (fractions and multiples of it are, that is, like 8241062Swilliam * half of a ``long time'', almost a long time, etc.) 8341062Swilliam * It is related to human patience and other factors which don't really 8441062Swilliam * change over time. 8541062Swilliam */ 8641062Swilliam #define MAXSLP 20 8741062Swilliam 8841062Swilliam /* 8941062Swilliam * A swapped in process is given a small amount of core without being bothered 9041062Swilliam * by the page replacement algorithm. Basically this says that if you are 9141062Swilliam * swapped in you deserve some resources. We protect the last SAFERSS 9241062Swilliam * pages against paging and will just swap you out rather than paging you. 9341062Swilliam * Note that each process has at least UPAGES+CLSIZE pages which are not 9441062Swilliam * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this 9541062Swilliam * number just means a swapped in process is given around 25k bytes. 9641062Swilliam * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81), 9741062Swilliam * so we loan each swapped in process memory worth 100$, or just admit 9841062Swilliam * that we don't consider it worthwhile and swap it out to disk which costs 9941062Swilliam * $30/mb or about $0.75. 10041062Swilliam * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17 10141062Swilliam * on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) } 10241062Swilliam */ 10345593Sbill #define SAFERSS 8 /* nominal ``small'' resident set size 10441062Swilliam protected against replacement */ 10541062Swilliam 10641062Swilliam /* 10741062Swilliam * DISKRPM is used to estimate the number of paging i/o operations 10841062Swilliam * which one can expect from a single disk controller. 10941062Swilliam */ 11041062Swilliam #define DISKRPM 60 11141062Swilliam 11241062Swilliam /* 11341062Swilliam * Klustering constants. Klustering is the gathering 11441062Swilliam * of pages together for pagein/pageout, while clustering 11541062Swilliam * is the treatment of hardware page size as though it were 11641062Swilliam * larger than it really is. 11741062Swilliam * 11841062Swilliam * KLMAX gives maximum cluster size in CLSIZE page (cluster-page) 11941062Swilliam * units. Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h. 12041062Swilliam */ 12141062Swilliam 12241062Swilliam #define KLMAX (4/CLSIZE) 12341062Swilliam #define KLSEQL (2/CLSIZE) /* in klust if vadvise(VA_SEQL) */ 12441062Swilliam #define KLIN (4/CLSIZE) /* default data/stack in klust */ 12541062Swilliam #define KLTXT (4/CLSIZE) /* default text in klust */ 12641062Swilliam #define KLOUT (4/CLSIZE) 12741062Swilliam 12841062Swilliam /* 12941062Swilliam * KLSDIST is the advance or retard of the fifo reclaim for sequential 13041062Swilliam * processes data space. 13141062Swilliam */ 13241062Swilliam #define KLSDIST 3 /* klusters advance/retard for seq. fifo */ 13341062Swilliam 13441062Swilliam /* 13541062Swilliam * Paging thresholds (see vm_sched.c). 13641062Swilliam * Strategy of 1/19/85: 13741062Swilliam * lotsfree is 512k bytes, but at most 1/4 of memory 13841062Swilliam * desfree is 200k bytes, but at most 1/8 of memory 13941062Swilliam * minfree is 64k bytes, but at most 1/2 of desfree 14041062Swilliam */ 14141062Swilliam #define LOTSFREE (512 * 1024) 14241062Swilliam #define LOTSFREEFRACT 4 14341062Swilliam #define DESFREE (200 * 1024) 14441062Swilliam #define DESFREEFRACT 8 14541062Swilliam #define MINFREE (64 * 1024) 14641062Swilliam #define MINFREEFRACT 2 14741062Swilliam 14841062Swilliam /* 14941062Swilliam * There are two clock hands, initially separated by HANDSPREAD bytes 15041062Swilliam * (but at most all of user memory). The amount of time to reclaim 15141062Swilliam * a page once the pageout process examines it increases with this 15241062Swilliam * distance and decreases as the scan rate rises. 15341062Swilliam */ 15441062Swilliam #define HANDSPREAD (2 * 1024 * 1024) 15541062Swilliam 15641062Swilliam /* 15741062Swilliam * The number of times per second to recompute the desired paging rate 15841062Swilliam * and poke the pagedaemon. 15941062Swilliam */ 16041062Swilliam #define RATETOSCHEDPAGING 4 16141062Swilliam 16241062Swilliam /* 16341062Swilliam * Believed threshold (in megabytes) for which interleaved 16441062Swilliam * swapping area is desirable. 16541062Swilliam */ 16641062Swilliam #define LOTSOFMEM 2 16741062Swilliam 16841062Swilliam #define mapin(pte, v, pfnum, prot) \ 16945964Swilliam {(*(int *)(pte) = ((pfnum)<<PGSHIFT) | (prot)) ; } 17041062Swilliam 17141062Swilliam /* 17247996Swilliam * Mach derived constants 17341062Swilliam */ 17445593Sbill 17547996Swilliam /* user/kernel map constants */ 17647996Swilliam #define VM_MIN_ADDRESS ((vm_offset_t)0) 177*49523Swilliam #define VM_MAXUSER_ADDRESS ((vm_offset_t)0xFDBFD000) 17848000Swilliam #define UPT_MIN_ADDRESS ((vm_offset_t)0xFDC00000) 17948000Swilliam #define UPT_MAX_ADDRESS ((vm_offset_t)0xFDFF7000) 18048000Swilliam #define VM_MAX_ADDRESS UPT_MAX_ADDRESS 18148000Swilliam #define VM_MIN_KERNEL_ADDRESS ((vm_offset_t)0xFDFF7000) 18248000Swilliam #define UPDT VM_MIN_KERNEL_ADDRESS 18348000Swilliam #define KPT_MIN_ADDRESS ((vm_offset_t)0xFDFF8000) 18448000Swilliam #define KPT_MAX_ADDRESS ((vm_offset_t)0xFDFFF000) 18548000Swilliam #define VM_MAX_KERNEL_ADDRESS ((vm_offset_t)0xFF7FF000) 18647996Swilliam 18747996Swilliam /* virtual sizes (bytes) for various kernel submaps */ 18847996Swilliam #define VM_MBUF_SIZE (NMBCLUSTERS*MCLBYTES) 18947996Swilliam #define VM_KMEM_SIZE (NKMEMCLUSTERS*CLBYTES) 19047996Swilliam #define VM_PHYS_SIZE (USRIOSIZE*CLBYTES) 19147996Swilliam 19247996Swilliam /* # of kernel PT pages (initial only, can grow dynamically) */ 19347996Swilliam #define VM_KERNEL_PT_PAGES ((vm_size_t)2) /* XXX: SYSPTSIZE */ 19447996Swilliam 19547996Swilliam /* pcb base */ 19647996Swilliam #define pcbb(p) ((u_int)(p)->p_addr) 19747996Swilliam 19845593Sbill /* 19945593Sbill * Flush MMU TLB 20045593Sbill */ 20145593Sbill 20245623Sbill #ifndef I386_CR3PAT 20345623Sbill #define I386_CR3PAT 0x0 20445623Sbill #endif 20545623Sbill 20648000Swilliam #ifdef notyet 20745623Sbill #define _cr3() ({u_long rtn; \ 20845623Sbill asm (" movl %%cr3,%%eax; movl %%eax,%0 " \ 20945623Sbill : "=g" (rtn) \ 21045623Sbill : \ 21145623Sbill : "ax"); \ 21245623Sbill rtn; \ 21345623Sbill }) 21445623Sbill 21545623Sbill #define load_cr3(s) ({ u_long val; \ 21645623Sbill val = (s) | I386_CR3PAT; \ 21745623Sbill asm ("movl %0,%%eax; movl %%eax,%%cr3" \ 21845623Sbill : \ 21945623Sbill : "g" (val) \ 22045623Sbill : "ax"); \ 22145623Sbill }) 22245964Swilliam 22345964Swilliam #define tlbflush() ({ u_long val; \ 22445964Swilliam val = u.u_pcb.pcb_ptd | I386_CR3PAT; \ 22545964Swilliam asm ("movl %0,%%eax; movl %%eax,%%cr3" \ 22645964Swilliam : \ 22745964Swilliam : "g" (val) \ 22845964Swilliam : "ax"); \ 22945964Swilliam }) 23048000Swilliam #endif 231