1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1985-2011 AT&T Intellectual Property * 5* and is licensed under the * 6* Common Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.opensource.org/licenses/cpl1.0.txt * 11* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* Glenn Fowler <gsf@research.att.com> * 18* David Korn <dgk@research.att.com> * 19* Phong Vo <kpv@research.att.com> * 20* * 21***********************************************************************/ 22#if defined(_UWIN) && defined(_BLD_ast) 23 24void _STUB_vmstat(){} 25 26#else 27 28#include "vmhdr.h" 29 30/* Get statistics from a region. 31** 32** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94. 33*/ 34 35#if __STD_C 36int vmstat(Vmalloc_t* vm, Vmstat_t* st) 37#else 38int vmstat(vm, st) 39Vmalloc_t* vm; 40Vmstat_t* st; 41#endif 42{ 43 reg Seg_t* seg; 44 reg Block_t *b, *endb; 45 reg size_t s = 0; 46 reg Vmdata_t* vd = vm ? vm->data : Vmregion->data; 47 reg int inuse; 48 49 SETINUSE(vd, inuse); 50 if(!st) 51 { CLRINUSE(vd, inuse); 52 return inuse ? 1 : 0; 53 } 54 if(!(vd->mode&VM_TRUST)) 55 { if(ISLOCK(vd,0)) 56 { CLRINUSE(vd, inuse); 57 return -1; 58 } 59 SETLOCK(vd,0); 60 } 61 62 st->n_busy = st->n_free = 0; 63 st->s_busy = st->s_free = st->m_busy = st->m_free = 0; 64 st->n_seg = 0; 65 st->extent = 0; 66 st->mode = vd->mode; 67 68 if(vd->mode&VM_MTLAST) 69 st->n_busy = 0; 70 else if((vd->mode&VM_MTPOOL) && (s = vd->pool) > 0) 71 { s = ROUND(s,ALIGN); 72 for(b = vd->free; b; b = SEGLINK(b)) 73 st->n_free += 1; 74 } 75 76 for(seg = vd->seg; seg; seg = seg->next) 77 { st->n_seg += 1; 78 st->extent += seg->extent; 79 80 b = SEGBLOCK(seg); 81 endb = BLOCK(seg->baddr); 82 83 if(vd->mode&(VM_MTDEBUG|VM_MTBEST|VM_MTPROFILE)) 84 { while(b < endb) 85 { s = SIZE(b)&~BITS; 86 if(ISJUNK(SIZE(b)) || !ISBUSY(SIZE(b))) 87 { if(s > st->m_free) 88 st->m_free = s; 89 st->s_free += s; 90 st->n_free += 1; 91 } 92 else /* get the real size */ 93 { if(vd->mode&VM_MTDEBUG) 94 { /* strict-aliasing dance */ 95 void* d = DB2DEBUG(DATA(b)); 96 s = DBSIZE(d); 97 } 98 else if(vd->mode&VM_MTPROFILE) 99 s = PFSIZE(DATA(b)); 100 if(s > st->m_busy) 101 st->m_busy = s; 102 st->s_busy += s; 103 st->n_busy += 1; 104 } 105 106 b = (Block_t*)((Vmuchar_t*)DATA(b) + (SIZE(b)&~BITS) ); 107 } 108 } 109 else if(vd->mode&VM_MTLAST) 110 { if((s = seg->free ? (SIZE(seg->free) + sizeof(Head_t)) : 0) > 0) 111 { st->s_free += s; 112 st->n_free += 1; 113 } 114 if((s = ((char*)endb - (char*)b) - s) > 0) 115 { st->s_busy += s; 116 st->n_busy += 1; 117 } 118 } 119 else if((vd->mode&VM_MTPOOL) && s > 0) 120 { if(seg->free) 121 st->n_free += ((int)SIZE(seg->free)+sizeof(Head_t))/(int)s; 122 st->n_busy += ((int)(seg->baddr - (Vmuchar_t*)b) - sizeof(Head_t))/(int)s; 123 } 124 } 125 126 if((vd->mode&VM_MTPOOL) && s > 0) 127 { st->n_busy -= st->n_free; 128 if(st->n_busy > 0) 129 st->s_busy = (st->m_busy = vd->pool)*st->n_busy; 130 if(st->n_free > 0) 131 st->s_free = (st->m_free = vd->pool)*st->n_free; 132 } 133 134 CLRLOCK(vd,0); 135 CLRINUSE(vd, inuse); 136 return inuse ? 1 : 0; 137} 138 139#endif 140