Index: head/sys/amd64/include/pmap.h =================================================================== --- head/sys/amd64/include/pmap.h (revision 606) +++ head/sys/amd64/include/pmap.h (revision 607) @@ -1,240 +1,233 @@ /* * Copyright (c) 1991 Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department and William Jolitz of UUNET Technologies Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)pmap.h 7.4 (Berkeley) 5/12/91 - */ - -/* * Derived from hp300 version by Mike Hibler, this version by William * Jolitz uses a recursive map [a pde points to the page directory] to * map the page tables using the pagetables themselves. This is done to * reduce the impact on kernel virtual memory for lots of sparse address * space, and to reduce the cost of memory to each process. * - * from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 + * $Id$ */ #ifndef _PMAP_MACHINE_ #define _PMAP_MACHINE_ 1 /* * 386 page table entry and page table directory * W.Jolitz, 8/89 */ - struct pde { unsigned int pd_v:1, /* valid bit */ pd_prot:2, /* access control */ pd_mbz1:2, /* reserved, must be zero */ pd_u:1, /* hardware maintained 'used' bit */ :1, /* not used */ pd_mbz2:2, /* reserved, must be zero */ :3, /* reserved for software */ pd_pfnum:20; /* physical page frame number of pte's*/ }; #define PD_MASK 0xffc00000 /* page directory address bits */ #define PT_MASK 0x003ff000 /* page table address bits */ #define PD_SHIFT 22 /* page directory address shift */ #define PG_SHIFT 12 /* page table address shift */ struct pte { unsigned int pg_v:1, /* valid bit */ pg_prot:2, /* access control */ pg_mbz1:2, /* reserved, must be zero */ pg_u:1, /* hardware maintained 'used' bit */ pg_m:1, /* hardware maintained modified bit */ pg_mbz2:2, /* reserved, must be zero */ pg_w:1, /* software, wired down page */ :1, /* software (unused) */ pg_nc:1, /* 'uncacheable page' bit */ pg_pfnum:20; /* physical page frame number */ }; #define PG_V 0x00000001 #define PG_RO 0x00000000 #define PG_RW 0x00000002 #define PG_u 0x00000004 #define PG_PROT 0x00000006 /* all protection bits . */ #define PG_W 0x00000200 #define PG_N 0x00000800 /* Non-cacheable */ #define PG_M 0x00000040 #define PG_U 0x00000020 #define PG_FRAME 0xfffff000 #define PG_NOACC 0 #define PG_KR 0x00000000 #define PG_KW 0x00000002 #define PG_URKR 0x00000004 #define PG_URKW 0x00000004 #define PG_UW 0x00000006 /* Garbage for current bastardized pager that assumes a hp300 */ #define PG_NV 0 #define PG_CI 0 + /* * Page Protection Exception bits */ - #define PGEX_P 0x01 /* Protection violation vs. not present */ #define PGEX_W 0x02 /* during a Write cycle */ #define PGEX_U 0x04 /* access from User mode (UPL) */ typedef struct pde pd_entry_t; /* page directory entry */ typedef struct pte pt_entry_t; /* Mach page table entry */ /* * NKPDE controls the virtual space of the kernel, what ever is left is * given to the user (NUPDE) - * - * XXX NKPDE should be 8, but until locore.s is fixed it needs to be 3 */ -#define NKPDE 3 /* number of kernel pde's */ +#define NKPDE 7 /* number of kernel pde's */ #define NUPDE (NPTEPG-NKPDE) /* number of user pde's */ /* * The *PTDI values control the layout of virtual memory * * XXX This works for now, but I am not real happy with it, I'll fix it * right after I fix locore.s and the magic 28K hole */ -#define LASTPTDI (NPTEPG-1) /* reserved for the future (unused) */ -#define APTDPTDI (LASTPTDI-1) /* alt ptd entry that points to APTD */ -#define RSVDPTDI (APTDPTDI-3) /* reserved for the near future */ -#define KPTDI (RSVDPTDI-NKPDE)/* start of kernel virtual pde's */ +#define APTDPTDI (NPTEPG-1) /* alt ptd entry that points to APTD */ +#define KPTDI (APTDPTDI-NKPDE)/* start of kernel virtual pde's */ #define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */ #define UPTDI (PTDPTDI-1) /* ptd entry for u./kernel&user stack */ /* * Address of current and alternate address space page table maps * and directories. */ #ifdef KERNEL extern struct pte PTmap[], APTmap[], Upte; extern struct pde PTD[], APTD[], PTDpde, APTDpde, Upde; -extern pt_entry_t *Sysmap; +extern pt_entry_t *Sysmap; extern int IdlePTD; /* physical address of "Idle" state directory */ #endif /* * virtual address to page table entry and * to physical address. Likewise for alternate address space. * Note: these work recursively, thus vtopte of a pte will give * the corresponding pde that in turn maps it. */ #define vtopte(va) (PTmap + i386_btop(va)) #define kvtopte(va) vtopte(va) #define ptetov(pt) (i386_ptob(pt - PTmap)) -#define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) +#define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) #define ispt(va) ((va) >= UPT_MIN_ADDRESS && (va) <= KPT_MAX_ADDRESS) #define avtopte(va) (APTmap + i386_btop(va)) #define ptetoav(pt) (i386_ptob(pt - APTmap)) -#define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) +#define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) /* * macros to generate page directory/table indicies */ #define pdei(va) (((va)&PD_MASK)>>PD_SHIFT) #define ptei(va) (((va)&PT_MASK)>>PG_SHIFT) /* * Pmap stuff */ struct pmap { pd_entry_t *pm_pdir; /* KVA of page directory */ boolean_t pm_pdchanged; /* pdir changed */ short pm_dref; /* page directory ref count */ short pm_count; /* pmap reference count */ simple_lock_data_t pm_lock; /* lock on pmap */ struct pmap_statistics pm_stats; /* pmap statistics */ long pm_ptpages; /* more stats: PT pages */ }; typedef struct pmap *pmap_t; #ifdef KERNEL extern pmap_t kernel_pmap; #endif /* * Macros for speed */ #define PMAP_ACTIVATE(pmapp, pcbp) \ if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) { \ (pcbp)->pcb_cr3 = \ pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \ if ((pmapp) == &curproc->p_vmspace->vm_pmap) \ load_cr3((pcbp)->pcb_cr3); \ (pmapp)->pm_pdchanged = FALSE; \ } #define PMAP_DEACTIVATE(pmapp, pcbp) /* * For each vm_page_t, there is a list of all currently valid virtual * mappings of that page. An entry is a pv_entry_t, the list is pv_table. */ typedef struct pv_entry { struct pv_entry *pv_next; /* next pv_entry */ pmap_t pv_pmap; /* pmap where mapping lies */ vm_offset_t pv_va; /* virtual address for mapping */ int pv_flags; /* flags */ } *pv_entry_t; #define PV_ENTRY_NULL ((pv_entry_t) 0) #define PV_CI 0x01 /* all entries must be cache inhibited */ #define PV_PTPAGE 0x02 /* entry maps a page table page */ #ifdef KERNEL pv_entry_t pv_table; /* array of entries, one per page */ #define pa_index(pa) atop(pa - vm_first_phys) #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) #endif KERNEL #endif _PMAP_MACHINE_ Index: head/sys/amd64/include/vmparam.h =================================================================== --- head/sys/amd64/include/vmparam.h (revision 606) +++ head/sys/amd64/include/vmparam.h (revision 607) @@ -1,263 +1,261 @@ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * William Jolitz. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * from: @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * $Id$ */ /* * Machine dependent constants for 386. */ /* * Virtual address space arrangement. On 386, both user and kernel * share the address space, not unlike the vax. * USRTEXT is the start of the user text/data space, while USRSTACK * is the top (end) of the user stack. Immediately above the user stack * resides the user structure, which is UPAGES long and contains the * kernel stack. * * Immediately after the user structure is the page table map, and then * kernal address space. */ #define USRTEXT 0 #define USRSTACK 0xFDBFE000 #define BTOPUSRSTACK (0xFDC00-(UPAGES)) /* btop(USRSTACK) */ #define LOWPAGES 0 #define HIGHPAGES UPAGES /* * Virtual memory related constants, all in bytes */ #define MAXTSIZ (6*1024*1024) /* max text size */ #ifndef DFLDSIZ #define DFLDSIZ (16*1024*1024) /* initial data size limit */ #endif #ifndef MAXDSIZ #define MAXDSIZ (32*1024*1024) /* max data size */ #endif #ifndef DFLSSIZ #define DFLSSIZ (512*1024) /* initial stack size limit */ #endif #ifndef MAXSSIZ #define MAXSSIZ (8*1024*1024) /* max stack size */ #endif /* * Default sizes of swap allocation chunks (see dmap.h). * The actual values may be changed in vminit() based on MAXDSIZ. * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024. */ #define DMMIN 32 /* smallest swap allocation */ #define DMMAX 4096 /* largest potential swap allocation */ #define DMTEXT 1024 /* swap allocation for text */ /* * Sizes of the system and user portions of the system page table. */ #define SYSPTSIZE (2*NPTEPG) #define USRPTSIZE (2*NPTEPG) /* * Size of the Shared Memory Pages page table. */ #ifndef SHMMAXPGS -#define SHMMAXPGS 64 /* XXX until we have more kmap space */ +#define SHMMAXPGS 512 /* XXX until we have more kmap space */ #endif /* * Size of User Raw I/O map */ #define USRIOSIZE 300 /* * The size of the clock loop. */ #define LOOPPAGES (maxfree - firstfree) /* * The time for a process to be blocked before being very swappable. * This is a number of seconds which the system takes as being a non-trivial * amount of real time. You probably shouldn't change this; * it is used in subtle ways (fractions and multiples of it are, that is, like * half of a ``long time'', almost a long time, etc.) * It is related to human patience and other factors which don't really * change over time. */ #define MAXSLP 20 /* * A swapped in process is given a small amount of core without being bothered * by the page replacement algorithm. Basically this says that if you are * swapped in you deserve some resources. We protect the last SAFERSS * pages against paging and will just swap you out rather than paging you. * Note that each process has at least UPAGES+CLSIZE pages which are not * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this * number just means a swapped in process is given around 25k bytes. * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81), * so we loan each swapped in process memory worth 100$, or just admit * that we don't consider it worthwhile and swap it out to disk which costs * $30/mb or about $0.75. * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17 * on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) } */ #define SAFERSS 8 /* nominal ``small'' resident set size protected against replacement */ /* * DISKRPM is used to estimate the number of paging i/o operations * which one can expect from a single disk controller. */ #define DISKRPM 60 /* * Klustering constants. Klustering is the gathering * of pages together for pagein/pageout, while clustering * is the treatment of hardware page size as though it were * larger than it really is. * * KLMAX gives maximum cluster size in CLSIZE page (cluster-page) * units. Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h. */ #define KLMAX (4/CLSIZE) #define KLSEQL (2/CLSIZE) /* in klust if vadvise(VA_SEQL) */ #define KLIN (4/CLSIZE) /* default data/stack in klust */ #define KLTXT (4/CLSIZE) /* default text in klust */ #define KLOUT (4/CLSIZE) /* * KLSDIST is the advance or retard of the fifo reclaim for sequential * processes data space. */ #define KLSDIST 3 /* klusters advance/retard for seq. fifo */ /* * Paging thresholds (see vm_sched.c). * Strategy of 1/19/85: * lotsfree is 512k bytes, but at most 1/4 of memory * desfree is 200k bytes, but at most 1/8 of memory * minfree is 64k bytes, but at most 1/2 of desfree */ #define LOTSFREE (512 * 1024) #define LOTSFREEFRACT 4 #define DESFREE (200 * 1024) #define DESFREEFRACT 8 #define MINFREE (64 * 1024) #define MINFREEFRACT 2 /* * There are two clock hands, initially separated by HANDSPREAD bytes * (but at most all of user memory). The amount of time to reclaim * a page once the pageout process examines it increases with this * distance and decreases as the scan rate rises. */ #define HANDSPREAD (2 * 1024 * 1024) /* * The number of times per second to recompute the desired paging rate * and poke the pagedaemon. */ #define RATETOSCHEDPAGING 4 /* * Believed threshold (in megabytes) for which interleaved * swapping area is desirable. */ #define LOTSOFMEM 2 #define mapin(pte, v, pfnum, prot) \ {(*(int *)(pte) = ((pfnum)<p_addr) /* * Flush MMU TLB */ #ifndef I386_CR3PAT #define I386_CR3PAT 0x0 #endif #ifdef notyet #define _cr3() ({u_long rtn; \ asm (" movl %%cr3,%%eax; movl %%eax,%0 " \ : "=g" (rtn) \ : \ : "ax"); \ rtn; \ }) #define load_cr3(s) ({ u_long val; \ val = (s) | I386_CR3PAT; \ asm ("movl %0,%%eax; movl %%eax,%%cr3" \ : \ : "g" (val) \ : "ax"); \ }) #define tlbflush() ({ u_long val; \ val = u.u_pcb.pcb_ptd | I386_CR3PAT; \ asm ("movl %0,%%eax; movl %%eax,%%cr3" \ : \ : "g" (val) \ : "ax"); \ }) #endif Index: head/sys/i386/include/param.h =================================================================== --- head/sys/i386/include/param.h (revision 606) +++ head/sys/i386/include/param.h (revision 607) @@ -1,161 +1,162 @@ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * William Jolitz. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: @(#)param.h 5.8 (Berkeley) 6/28/91 - * $Id: param.h,v 1.5 1993/10/12 07:13:12 rgrimes Exp $ + * $Id: param.h,v 1.6 1993/10/12 12:08:16 rgrimes Exp $ */ /* * Machine dependent constants for Intel 386. */ #define MACHINE "i386" #define MID_MACHINE MID_I386 /* * Round p (pointer or byte index) up to a correctly-aligned value * for all data types (int, long, ...). The result is u_int and * must be cast to any desired pointer type. */ #define ALIGNBYTES (sizeof(int) - 1) #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES) +/* XXX PGSHIFT and PG_SHIFT are two names for the same thing */ #define PGSHIFT 12 /* LOG2(NBPG) */ #define NBPG (1 << PGSHIFT) /* bytes/page */ #define PGOFSET (NBPG-1) /* byte offset into page */ #define NPTEPG (NBPG/(sizeof (struct pte))) +/* XXX PDRSHIFT and PD_SHIFT are two names for the same thing */ #define PDRSHIFT 22 /* LOG2(NBPDR) */ #define NBPDR (1 << PDRSHIFT) /* bytes/page dir */ #define PDROFSET (NBPDR-1) /* byte offset into page dir */ +/* + * XXX This should really be KPTDPTDI << PDRSHIFT, but since KPTDPTDI is + * defined in pmap.h which is included after this we can't do that + * (YET!) + */ #define KERNBASE 0xFE000000 /* start of kernel virtual */ #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) #define KERNSIZE 0x00C00000 /* size of kernel virtual */ #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ #define DEV_BSIZE (1 << DEV_BSHIFT) #define BLKDEV_IOSIZE 2048 #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ #define CLSIZELOG2 0 #define CLSIZE (1 << CLSIZELOG2) /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */ #define SSIZE 1 /* initial stack size/NBPG */ #define SINCR 1 /* increment of stack/NBPG */ #define UPAGES 2 /* pages of u-area */ /* * Constants related to network buffer management. * MCLBYTES must be no larger than CLBYTES (the software page size), and, * on machines that exchange pages of input or output buffers with mbuf * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple * of the hardware page size. */ #ifndef MSIZE #define MSIZE 128 /* size of an mbuf */ #endif /* MSIZE */ #ifndef MCLSHIFT #define MCLSHIFT 11 /* convert bytes to m_buf clusters */ #endif /* MCLSHIFT */ #define MCLBYTES (1 << MCLSHIFT) /* size of an m_buf cluster */ #define MCLOFSET (MCLBYTES - 1) /* offset within an m_buf cluster */ #ifndef NMBCLUSTERS #ifdef GATEWAY #define NMBCLUSTERS 512 /* map size, max cluster allocation */ #else #define NMBCLUSTERS 256 /* map size, max cluster allocation */ #endif /* GATEWAY */ #endif /* NMBCLUSTERS */ -/* - * Size of kernel malloc arena in CLBYTES-sized logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (3072*1024/CLBYTES) -#endif /* * Some macros for units conversion */ /* Core clicks (4096 bytes) to segments and vice versa */ #define ctos(x) (x) #define stoc(x) (x) /* Core clicks (4096 bytes) to disk blocks */ #define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT)) #define dtoc(x) ((x)>>(PGSHIFT-DEV_BSHIFT)) #define dtob(x) ((x)<>PGSHIFT) #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ ((unsigned)(bytes) >> DEV_BSHIFT) #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ ((unsigned)(db) << DEV_BSHIFT) /* * Map a ``block device block'' to a file system block. * This should be device dependent, and will be if we * add an entry to cdevsw/bdevsw for that purpose. * For now though just use DEV_BSIZE. */ #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE/DEV_BSIZE)) /* * Mach derived conversion macros */ #define i386_round_pdr(x) ((((unsigned)(x)) + NBPDR - 1) & ~(NBPDR-1)) #define i386_trunc_pdr(x) ((unsigned)(x) & ~(NBPDR-1)) #define i386_round_page(x) ((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1)) #define i386_trunc_page(x) ((unsigned)(x) & ~(NBPG-1)) #define i386_btod(x) ((unsigned)(x) >> PDRSHIFT) #define i386_dtob(x) ((unsigned)(x) << PDRSHIFT) #define i386_btop(x) ((unsigned)(x) >> PGSHIFT) #define i386_ptob(x) ((unsigned)(x) << PGSHIFT) /* * phystokv stolen from SCSI device drivers and fixed to use KERNBASE */ #define PHYSTOKV(x) (x | KERNBASE) Index: head/sys/i386/include/pmap.h =================================================================== --- head/sys/i386/include/pmap.h (revision 606) +++ head/sys/i386/include/pmap.h (revision 607) @@ -1,240 +1,233 @@ /* * Copyright (c) 1991 Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department and William Jolitz of UUNET Technologies Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)pmap.h 7.4 (Berkeley) 5/12/91 - */ - -/* * Derived from hp300 version by Mike Hibler, this version by William * Jolitz uses a recursive map [a pde points to the page directory] to * map the page tables using the pagetables themselves. This is done to * reduce the impact on kernel virtual memory for lots of sparse address * space, and to reduce the cost of memory to each process. * - * from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 + * $Id$ */ #ifndef _PMAP_MACHINE_ #define _PMAP_MACHINE_ 1 /* * 386 page table entry and page table directory * W.Jolitz, 8/89 */ - struct pde { unsigned int pd_v:1, /* valid bit */ pd_prot:2, /* access control */ pd_mbz1:2, /* reserved, must be zero */ pd_u:1, /* hardware maintained 'used' bit */ :1, /* not used */ pd_mbz2:2, /* reserved, must be zero */ :3, /* reserved for software */ pd_pfnum:20; /* physical page frame number of pte's*/ }; #define PD_MASK 0xffc00000 /* page directory address bits */ #define PT_MASK 0x003ff000 /* page table address bits */ #define PD_SHIFT 22 /* page directory address shift */ #define PG_SHIFT 12 /* page table address shift */ struct pte { unsigned int pg_v:1, /* valid bit */ pg_prot:2, /* access control */ pg_mbz1:2, /* reserved, must be zero */ pg_u:1, /* hardware maintained 'used' bit */ pg_m:1, /* hardware maintained modified bit */ pg_mbz2:2, /* reserved, must be zero */ pg_w:1, /* software, wired down page */ :1, /* software (unused) */ pg_nc:1, /* 'uncacheable page' bit */ pg_pfnum:20; /* physical page frame number */ }; #define PG_V 0x00000001 #define PG_RO 0x00000000 #define PG_RW 0x00000002 #define PG_u 0x00000004 #define PG_PROT 0x00000006 /* all protection bits . */ #define PG_W 0x00000200 #define PG_N 0x00000800 /* Non-cacheable */ #define PG_M 0x00000040 #define PG_U 0x00000020 #define PG_FRAME 0xfffff000 #define PG_NOACC 0 #define PG_KR 0x00000000 #define PG_KW 0x00000002 #define PG_URKR 0x00000004 #define PG_URKW 0x00000004 #define PG_UW 0x00000006 /* Garbage for current bastardized pager that assumes a hp300 */ #define PG_NV 0 #define PG_CI 0 + /* * Page Protection Exception bits */ - #define PGEX_P 0x01 /* Protection violation vs. not present */ #define PGEX_W 0x02 /* during a Write cycle */ #define PGEX_U 0x04 /* access from User mode (UPL) */ typedef struct pde pd_entry_t; /* page directory entry */ typedef struct pte pt_entry_t; /* Mach page table entry */ /* * NKPDE controls the virtual space of the kernel, what ever is left is * given to the user (NUPDE) - * - * XXX NKPDE should be 8, but until locore.s is fixed it needs to be 3 */ -#define NKPDE 3 /* number of kernel pde's */ +#define NKPDE 7 /* number of kernel pde's */ #define NUPDE (NPTEPG-NKPDE) /* number of user pde's */ /* * The *PTDI values control the layout of virtual memory * * XXX This works for now, but I am not real happy with it, I'll fix it * right after I fix locore.s and the magic 28K hole */ -#define LASTPTDI (NPTEPG-1) /* reserved for the future (unused) */ -#define APTDPTDI (LASTPTDI-1) /* alt ptd entry that points to APTD */ -#define RSVDPTDI (APTDPTDI-3) /* reserved for the near future */ -#define KPTDI (RSVDPTDI-NKPDE)/* start of kernel virtual pde's */ +#define APTDPTDI (NPTEPG-1) /* alt ptd entry that points to APTD */ +#define KPTDI (APTDPTDI-NKPDE)/* start of kernel virtual pde's */ #define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */ #define UPTDI (PTDPTDI-1) /* ptd entry for u./kernel&user stack */ /* * Address of current and alternate address space page table maps * and directories. */ #ifdef KERNEL extern struct pte PTmap[], APTmap[], Upte; extern struct pde PTD[], APTD[], PTDpde, APTDpde, Upde; -extern pt_entry_t *Sysmap; +extern pt_entry_t *Sysmap; extern int IdlePTD; /* physical address of "Idle" state directory */ #endif /* * virtual address to page table entry and * to physical address. Likewise for alternate address space. * Note: these work recursively, thus vtopte of a pte will give * the corresponding pde that in turn maps it. */ #define vtopte(va) (PTmap + i386_btop(va)) #define kvtopte(va) vtopte(va) #define ptetov(pt) (i386_ptob(pt - PTmap)) -#define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) +#define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) #define ispt(va) ((va) >= UPT_MIN_ADDRESS && (va) <= KPT_MAX_ADDRESS) #define avtopte(va) (APTmap + i386_btop(va)) #define ptetoav(pt) (i386_ptob(pt - APTmap)) -#define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) +#define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) /* * macros to generate page directory/table indicies */ #define pdei(va) (((va)&PD_MASK)>>PD_SHIFT) #define ptei(va) (((va)&PT_MASK)>>PG_SHIFT) /* * Pmap stuff */ struct pmap { pd_entry_t *pm_pdir; /* KVA of page directory */ boolean_t pm_pdchanged; /* pdir changed */ short pm_dref; /* page directory ref count */ short pm_count; /* pmap reference count */ simple_lock_data_t pm_lock; /* lock on pmap */ struct pmap_statistics pm_stats; /* pmap statistics */ long pm_ptpages; /* more stats: PT pages */ }; typedef struct pmap *pmap_t; #ifdef KERNEL extern pmap_t kernel_pmap; #endif /* * Macros for speed */ #define PMAP_ACTIVATE(pmapp, pcbp) \ if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) { \ (pcbp)->pcb_cr3 = \ pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \ if ((pmapp) == &curproc->p_vmspace->vm_pmap) \ load_cr3((pcbp)->pcb_cr3); \ (pmapp)->pm_pdchanged = FALSE; \ } #define PMAP_DEACTIVATE(pmapp, pcbp) /* * For each vm_page_t, there is a list of all currently valid virtual * mappings of that page. An entry is a pv_entry_t, the list is pv_table. */ typedef struct pv_entry { struct pv_entry *pv_next; /* next pv_entry */ pmap_t pv_pmap; /* pmap where mapping lies */ vm_offset_t pv_va; /* virtual address for mapping */ int pv_flags; /* flags */ } *pv_entry_t; #define PV_ENTRY_NULL ((pv_entry_t) 0) #define PV_CI 0x01 /* all entries must be cache inhibited */ #define PV_PTPAGE 0x02 /* entry maps a page table page */ #ifdef KERNEL pv_entry_t pv_table; /* array of entries, one per page */ #define pa_index(pa) atop(pa - vm_first_phys) #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) #endif KERNEL #endif _PMAP_MACHINE_ Index: head/sys/i386/include/vmparam.h =================================================================== --- head/sys/i386/include/vmparam.h (revision 606) +++ head/sys/i386/include/vmparam.h (revision 607) @@ -1,263 +1,261 @@ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * William Jolitz. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * from: @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * $Id$ */ /* * Machine dependent constants for 386. */ /* * Virtual address space arrangement. On 386, both user and kernel * share the address space, not unlike the vax. * USRTEXT is the start of the user text/data space, while USRSTACK * is the top (end) of the user stack. Immediately above the user stack * resides the user structure, which is UPAGES long and contains the * kernel stack. * * Immediately after the user structure is the page table map, and then * kernal address space. */ #define USRTEXT 0 #define USRSTACK 0xFDBFE000 #define BTOPUSRSTACK (0xFDC00-(UPAGES)) /* btop(USRSTACK) */ #define LOWPAGES 0 #define HIGHPAGES UPAGES /* * Virtual memory related constants, all in bytes */ #define MAXTSIZ (6*1024*1024) /* max text size */ #ifndef DFLDSIZ #define DFLDSIZ (16*1024*1024) /* initial data size limit */ #endif #ifndef MAXDSIZ #define MAXDSIZ (32*1024*1024) /* max data size */ #endif #ifndef DFLSSIZ #define DFLSSIZ (512*1024) /* initial stack size limit */ #endif #ifndef MAXSSIZ #define MAXSSIZ (8*1024*1024) /* max stack size */ #endif /* * Default sizes of swap allocation chunks (see dmap.h). * The actual values may be changed in vminit() based on MAXDSIZ. * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024. */ #define DMMIN 32 /* smallest swap allocation */ #define DMMAX 4096 /* largest potential swap allocation */ #define DMTEXT 1024 /* swap allocation for text */ /* * Sizes of the system and user portions of the system page table. */ #define SYSPTSIZE (2*NPTEPG) #define USRPTSIZE (2*NPTEPG) /* * Size of the Shared Memory Pages page table. */ #ifndef SHMMAXPGS -#define SHMMAXPGS 64 /* XXX until we have more kmap space */ +#define SHMMAXPGS 512 /* XXX until we have more kmap space */ #endif /* * Size of User Raw I/O map */ #define USRIOSIZE 300 /* * The size of the clock loop. */ #define LOOPPAGES (maxfree - firstfree) /* * The time for a process to be blocked before being very swappable. * This is a number of seconds which the system takes as being a non-trivial * amount of real time. You probably shouldn't change this; * it is used in subtle ways (fractions and multiples of it are, that is, like * half of a ``long time'', almost a long time, etc.) * It is related to human patience and other factors which don't really * change over time. */ #define MAXSLP 20 /* * A swapped in process is given a small amount of core without being bothered * by the page replacement algorithm. Basically this says that if you are * swapped in you deserve some resources. We protect the last SAFERSS * pages against paging and will just swap you out rather than paging you. * Note that each process has at least UPAGES+CLSIZE pages which are not * paged anyways (this is currently 8+2=10 pages or 5k bytes), so this * number just means a swapped in process is given around 25k bytes. * Just for fun: current memory prices are 4600$ a megabyte on VAX (4/22/81), * so we loan each swapped in process memory worth 100$, or just admit * that we don't consider it worthwhile and swap it out to disk which costs * $30/mb or about $0.75. * { wfj 6/16/89: Retail AT memory expansion $800/megabyte, loan of $17 * on disk costing $7/mb or $0.18 (in memory still 100:1 in cost!) } */ #define SAFERSS 8 /* nominal ``small'' resident set size protected against replacement */ /* * DISKRPM is used to estimate the number of paging i/o operations * which one can expect from a single disk controller. */ #define DISKRPM 60 /* * Klustering constants. Klustering is the gathering * of pages together for pagein/pageout, while clustering * is the treatment of hardware page size as though it were * larger than it really is. * * KLMAX gives maximum cluster size in CLSIZE page (cluster-page) * units. Note that KLMAX*CLSIZE must be <= DMMIN in dmap.h. */ #define KLMAX (4/CLSIZE) #define KLSEQL (2/CLSIZE) /* in klust if vadvise(VA_SEQL) */ #define KLIN (4/CLSIZE) /* default data/stack in klust */ #define KLTXT (4/CLSIZE) /* default text in klust */ #define KLOUT (4/CLSIZE) /* * KLSDIST is the advance or retard of the fifo reclaim for sequential * processes data space. */ #define KLSDIST 3 /* klusters advance/retard for seq. fifo */ /* * Paging thresholds (see vm_sched.c). * Strategy of 1/19/85: * lotsfree is 512k bytes, but at most 1/4 of memory * desfree is 200k bytes, but at most 1/8 of memory * minfree is 64k bytes, but at most 1/2 of desfree */ #define LOTSFREE (512 * 1024) #define LOTSFREEFRACT 4 #define DESFREE (200 * 1024) #define DESFREEFRACT 8 #define MINFREE (64 * 1024) #define MINFREEFRACT 2 /* * There are two clock hands, initially separated by HANDSPREAD bytes * (but at most all of user memory). The amount of time to reclaim * a page once the pageout process examines it increases with this * distance and decreases as the scan rate rises. */ #define HANDSPREAD (2 * 1024 * 1024) /* * The number of times per second to recompute the desired paging rate * and poke the pagedaemon. */ #define RATETOSCHEDPAGING 4 /* * Believed threshold (in megabytes) for which interleaved * swapping area is desirable. */ #define LOTSOFMEM 2 #define mapin(pte, v, pfnum, prot) \ {(*(int *)(pte) = ((pfnum)<p_addr) /* * Flush MMU TLB */ #ifndef I386_CR3PAT #define I386_CR3PAT 0x0 #endif #ifdef notyet #define _cr3() ({u_long rtn; \ asm (" movl %%cr3,%%eax; movl %%eax,%0 " \ : "=g" (rtn) \ : \ : "ax"); \ rtn; \ }) #define load_cr3(s) ({ u_long val; \ val = (s) | I386_CR3PAT; \ asm ("movl %0,%%eax; movl %%eax,%%cr3" \ : \ : "g" (val) \ : "ax"); \ }) #define tlbflush() ({ u_long val; \ val = u.u_pcb.pcb_ptd | I386_CR3PAT; \ asm ("movl %0,%%eax; movl %%eax,%%cr3" \ : \ : "g" (val) \ : "ax"); \ }) #endif