|
|
1.1 ! root 1: /* vm.h 2.1 1/5/80 */ ! 2: ! 3: /* ! 4: * Machine dependent constants ! 5: */ ! 6: #define NBBY 8 /* number of bits in a byte */ ! 7: #define NBPG 512 /* number of bytes per page */ ! 8: #define PGSHIFT 9 /* LOG2(NBPG) */ ! 9: #define NPTEPG (NBPG/(sizeof (struct pte))) ! 10: /* number of ptes per page */ ! 11: #define PGOFSET (NBPG-1) /* byte offset into page */ ! 12: #define CLOFSET (CLSIZE*NBPG-1) /* for clusters, like PGOFSET */ ! 13: #define USRSTACK 0x80000000 /* Start of user stack */ ! 14: #define P1TOP 0x200000 /* boundary between P0 and P1 regions */ ! 15: #define AST 0x04000000 /* ast level */ ! 16: ! 17: /* ! 18: * Virtual memory related constants ! 19: * ! 20: * note: USRPTSIZE is well known in locore.s ! 21: */ ! 22: #define MAXTSIZ (4*2048) /* max virtual text size in clicks */ ! 23: #define MAXDSIZ (4*2048) /* max virtual data size in clicks */ ! 24: #define MAXSSIZ (1024) /* max virtual stack size in clicks */ ! 25: #define USRPTSIZE (8*NPTEPG) /* max number of pages of page tables ! 26: for resident processes, this is ! 27: known in locore.s */ ! 28: ! 29: /* ! 30: * Page clustering macros. ! 31: * ! 32: * dirtycl(pte) is the page cluster dirty? ! 33: * anycl(pte,fld) does any pte in the cluster has fld set? ! 34: * zapcl(pte,fld) = val set all fields fld in the cluster to val ! 35: * distcl(pte) distribute high bits to cluster; note that ! 36: * distcl copies everything but pg_pfnum, ! 37: * INCLUDING pg_m!!! ! 38: * ! 39: * In all cases, pte must be the low pte in the cluster, even if ! 40: * the segment grows backwards (e.g. the stack). ! 41: */ ! 42: #define H(pte) ((struct hpte *)(pte)) ! 43: ! 44: #if CLSIZE==1 ! 45: #define dirtycl(pte) dirty(pte) ! 46: #define anycl(pte,fld) ((pte)->fld) ! 47: #define zapcl(pte,fld) (pte)->fld ! 48: #define distcl(pte) ! 49: #endif ! 50: ! 51: #if CLSIZE==2 ! 52: #define dirtycl(pte) (dirty(pte) || dirty((pte)+1)) ! 53: #define anycl(pte,fld) ((pte)->fld || (((pte)+1)->fld)) ! 54: #define zapcl(pte,fld) (pte)[1].fld = (pte)[0].fld ! 55: #endif ! 56: ! 57: #if CLSIZE==4 ! 58: #define dirtycl(pte) \ ! 59: (dirty(pte) || dirty((pte)+1) || dirty((pte)+2) || dirty((pte)+3)) ! 60: #define anycl(pte,fld) \ ! 61: ((pte)->fld || (((pte)+1)->fld) || (((pte)+2)->fld) || (((pte)+3)->fld)) ! 62: #define zapcl(pte,fld) \ ! 63: (pte)[3].fld = (pte)[2].fld = (pte)[1].fld = (pte)[0].fld ! 64: #endif ! 65: ! 66: #ifndef distcl ! 67: #define distcl(pte) zapcl(H(pte),pg_high) ! 68: #endif ! 69: ! 70: /* ! 71: * Tunable performance parameters ! 72: * ! 73: * These may vary per-cpu due to configuration as well as the flavor of ! 74: * the local job mix. MAXPGIO in particular is dependent on the number ! 75: * of disk drives and controllers available locally. ! 76: */ ! 77: #define LOOPSIZ ((maxfree - firstfree) / CLSIZE) ! 78: /* loop circumference */ ! 79: #define LOTSFREE ((maxfree - firstfree) / 8) ! 80: /* very high mark to freeze scans */ ! 81: #define DESFREE 64 /* minimum desirable free memory */ ! 82: #define MINFREE 32 /* water mark to run swap daemon */ ! 83: #define MAXSLP 20 /* max blocked time (in seconds) allowed ! 84: before being very swappable */ ! 85: /* SLOWSCAN AND FASTSCAN SHOULD BE MADE DEPENDENT ON LOOPSIZ */ ! 86: #define SLOWSCAN 30 /* seconds per loop when memory easy */ ! 87: #define FASTSCAN 20 /* seconds per loop when memory tight */ ! 88: #define SAFERSS 32 /* nominal ``small'' resident set size ! 89: protected against replacement */ ! 90: #define MAXPGIO 40 /* max desired paging i/o per second, ! 91: if exceeded, and freemem < desfree ! 92: then we try to swap someone out */ ! 93: ! 94: /* ! 95: * Virtual memory related conversion macros ! 96: */ ! 97: ! 98: /* Core clicks to number of pages of page tables needed to map that much */ ! 99: #define ctopt(x) (((x)+NPTEPG-1)/NPTEPG) ! 100: ! 101: /* Virtual page numbers to text|data|stack segment page numbers and back */ ! 102: #define vtotp(p, v) ((int)(v)) ! 103: #define vtodp(p, v) ((int)((v) - (p)->p_tsize)) ! 104: #define vtosp(p, v) ((int)(btop(USRSTACK) - 1 - (v))) ! 105: #define tptov(p, i) ((unsigned)(i)) ! 106: #define dptov(p, i) ((unsigned)((p)->p_tsize + (i))) ! 107: #define sptov(p, i) ((unsigned)(btop(USRSTACK) - 1 - (i))) ! 108: ! 109: /* Tell whether virtual page numbers are in text|data|stack segment */ ! 110: #define isassv(p, v) ((v) & P1TOP) ! 111: #define isatsv(p, v) ((v) < (p)->p_tsize) ! 112: #define isadsv(p, v) ((v) >= (p)->p_tsize && !isassv(p, v)) ! 113: ! 114: /* Tell whether pte's are text|data|stack */ ! 115: #define isaspte(p, pte) ((pte) > sptopte(p, (p)->p_ssize)) ! 116: #define isatpte(p, pte) ((pte) < dptopte(p, 0)) ! 117: #define isadpte(p, pte) (!isaspte(p, pte) && !isatpte(p, pte)) ! 118: ! 119: /* Text|data|stack pte's to segment page numbers and back */ ! 120: #define ptetotp(p, pte) ((pte) - (p)->p_p0br) ! 121: #define ptetodp(p, pte) ((pte) - ((p)->p_p0br + (p)->p_tsize)) ! 122: #define ptetosp(p, pte) (((p)->p_p0br + (p)->p_szpt*NPTEPG - 1) - (pte)) ! 123: #define tptopte(p, i) ((p)->p_p0br + (i)) ! 124: #define dptopte(p, i) ((p)->p_p0br + (p)->p_tsize + (i)) ! 125: #define sptopte(p, i) (((p)->p_p0br + (p)->p_szpt*NPTEPG - 1) - (i)) ! 126: ! 127: /* Bytes to pages without rounding, and back */ ! 128: #define btop(x) (((unsigned)(x)) >> PGSHIFT) ! 129: #define ptob(x) ((caddr_t)((x) << PGSHIFT)) ! 130: ! 131: /* Turn virtual addresses into kernel map indices */ ! 132: #define kmxtob(a) (usrpt + (a) * NPTEPG) ! 133: #define btokmx(b) (((b) - usrpt) / NPTEPG) ! 134: ! 135: /* Average new into old with aging factor time */ ! 136: #define ave(smooth, cnt, time) \ ! 137: smooth = ((time - 1) * (smooth) + (cnt)) / (time) ! 138: ! 139: /* ! 140: * Virtual memory related instrumentation ! 141: */ ! 142: struct vmmeter ! 143: { ! 144: unsigned v_swpin; /* swapins */ ! 145: unsigned v_swpout; /* swapouts */ ! 146: unsigned v_pswpin; /* pages swapped in */ ! 147: unsigned v_pswpout; /* pages swapped out */ ! 148: unsigned v_pgin; /* pageins */ ! 149: unsigned v_pgout; /* pageouts */ ! 150: unsigned v_intrans; /* intransit blocking page faults */ ! 151: unsigned v_pgrec; /* total page reclaims */ ! 152: unsigned v_exfod; /* pages filled on demand from executables */ ! 153: unsigned v_zfod; /* pages zero filled on demand */ ! 154: unsigned v_vrfod; /* fills of pages mapped by vread() */ ! 155: unsigned v_nexfod; /* number of exfod's created */ ! 156: unsigned v_nzfod; /* number of zfod's created */ ! 157: unsigned v_nvrfod; /* number of vrfod's created */ ! 158: unsigned v_pgfrec; /* page reclaims from free list */ ! 159: unsigned v_faults; /* total faults taken */ ! 160: unsigned v_scan; /* scans in page out daemon */ ! 161: unsigned v_rev; /* revolutions of the hand */ ! 162: unsigned v_dfree; /* pages freed by daemon */ ! 163: unsigned v_swtch; /* context switches */ ! 164: }; ! 165: #ifdef KERNEL ! 166: struct vmmeter cnt, rate, sum; ! 167: #endif ! 168: ! 169: /* systemwide totals computed every five seconds */ ! 170: struct vmtotal ! 171: { ! 172: short t_rq; /* length of the run queue */ ! 173: short t_dw; /* jobs in ``disk wait'' (neg priority) */ ! 174: short t_pw; /* jobs in page wait */ ! 175: short t_sl; /* jobs sleeping in core */ ! 176: short t_sw; /* swapped out runnable/short block jobs */ ! 177: short t_vm; /* total virtual memory */ ! 178: short t_avm; /* active virtual memory */ ! 179: short t_rm; /* total real memory in use */ ! 180: short t_arm; /* active real memory */ ! 181: short t_vmtxt; /* virtual memory used by text */ ! 182: short t_avmtxt; /* active virtual memory used by text */ ! 183: short t_rmtxt; /* real memory used by text */ ! 184: short t_armtxt; /* active real memory used by text */ ! 185: short t_free; /* free memory pages */ ! 186: }; ! 187: #ifdef KERNEL ! 188: struct vmtotal total; ! 189: #endif ! 190: ! 191: struct forkstat ! 192: { ! 193: int cntfork; ! 194: int cntvfork; ! 195: int sizfork; ! 196: int sizvfork; ! 197: }; ! 198: #ifdef KERNEL ! 199: struct forkstat forkstat; ! 200: #endif ! 201: ! 202: struct swptstat ! 203: { ! 204: int pteasy; /* easy pt swaps */ ! 205: int ptexpand; /* pt expansion swaps */ ! 206: int ptshrink; /* pt shrinking swaps */ ! 207: int ptpack; /* pt swaps involving spte copying */ ! 208: }; ! 209: #ifdef KERNEL ! 210: struct swptstat swptstat; ! 211: #endif ! 212: ! 213: #ifdef KERNEL ! 214: int freemem; /* remaining blocks of free memory */ ! 215: int avefree; /* moving average of remaining free blocks */ ! 216: int deficit; /* estimate of needs of new swapped in procs */ ! 217: int nscan; /* number of scans in last second */ ! 218: int multprog; /* current multiprogramming degree */ ! 219: int desscan; /* desired pages scanned per second */ ! 220: ! 221: unsigned rectime; /* accumulator for reclaim times */ ! 222: unsigned pgintime; /* accumulator for page in times */ ! 223: ! 224: /* writable copies of tunables */ ! 225: int maxpgio; /* max paging i/o per sec before start swaps */ ! 226: int maxslp; /* max sleep time before very swappable */ ! 227: int lotsfree; /* max free before clock freezes */ ! 228: int minfree; /* minimum free pages before swapping begins */ ! 229: int desfree; /* no of pages to try to keep free via daemon */ ! 230: int saferss; /* no pages not to steal; decays with slptime */ ! 231: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.