1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2012 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 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 24 void _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 36 int vmstat(Vmalloc_t* vm, Vmstat_t* st) 37 #else 38 int vmstat(vm, st) 39 Vmalloc_t* vm; 40 Vmstat_t* st; 41 #endif 42 { 43 size_t s; 44 Seg_t *seg; 45 Block_t *b, *endb; 46 Vmdata_t *vd; 47 Void_t *d; 48 49 if(!st) /* just checking lock state of region */ 50 return (vm ? vm : Vmregion)->data->lock; 51 52 memset(st, 0, sizeof(Vmstat_t)); 53 54 if(!vm) 55 { /* getting data for malloc */ 56 #if ( !_std_malloc || !_BLD_ast ) && !_AST_std_malloc 57 extern int _mallocstat(Vmstat_t*); 58 return _mallocstat(st); 59 #else 60 return -1; 61 #endif 62 } 63 64 SETLOCK(vm, 0); 65 66 st->n_busy = st->n_free = 0; 67 st->s_busy = st->s_free = st->m_busy = st->m_free = 0; 68 st->n_seg = 0; 69 st->extent = 0; 70 71 vd = vm->data; 72 st->mode = vd->mode; 73 s = 0; 74 if(vd->mode&VM_MTLAST) 75 st->n_busy = 0; 76 else if((vd->mode&VM_MTPOOL) && (s = vd->pool) > 0) 77 { s = ROUND(s,ALIGN); 78 for(b = vd->free; b; b = SEGLINK(b)) 79 st->n_free += 1; 80 } 81 82 for(seg = vd->seg; seg; seg = seg->next) 83 { st->n_seg += 1; 84 st->extent += seg->extent; 85 86 b = SEGBLOCK(seg); 87 endb = BLOCK(seg->baddr); 88 89 if(vd->mode&(VM_MTDEBUG|VM_MTBEST|VM_MTPROFILE)) 90 { while(b < endb) 91 { s = SIZE(b)&~BITS; 92 if(ISJUNK(SIZE(b)) || !ISBUSY(SIZE(b))) 93 { if(s > st->m_free) 94 st->m_free = s; 95 st->s_free += s; 96 st->n_free += 1; 97 } 98 else /* get the real size */ 99 { d = DATA(b); 100 if(vd->mode&VM_MTDEBUG) 101 s = DBSIZE(DB2DEBUG(d)); 102 else if(vd->mode&VM_MTPROFILE) 103 s = PFSIZE(d); 104 if(s > st->m_busy) 105 st->m_busy = s; 106 st->s_busy += s; 107 st->n_busy += 1; 108 } 109 110 b = (Block_t*)((Vmuchar_t*)DATA(b) + (SIZE(b)&~BITS) ); 111 } 112 /**/ASSERT(st->extent >= (st->s_busy + st->s_free)); 113 } 114 else if(vd->mode&VM_MTLAST) 115 { if((s = seg->free ? (SIZE(seg->free) + sizeof(Head_t)) : 0) > 0) 116 { st->s_free += s; 117 st->n_free += 1; 118 } 119 if((s = ((char*)endb - (char*)b) - s) > 0) 120 { st->s_busy += s; 121 st->n_busy += 1; 122 } 123 } 124 else if((vd->mode&VM_MTPOOL) && s > 0) 125 { if(seg->free) 126 st->n_free += (SIZE(seg->free)+sizeof(Head_t))/s; 127 st->n_busy += ((seg->baddr - (Vmuchar_t*)b) - sizeof(Head_t))/s; 128 } 129 } 130 131 if((vd->mode&VM_MTPOOL) && s > 0) 132 { st->n_busy -= st->n_free; 133 if(st->n_busy > 0) 134 st->s_busy = (st->m_busy = vd->pool)*st->n_busy; 135 if(st->n_free > 0) 136 st->s_free = (st->m_free = vd->pool)*st->n_free; 137 } 138 139 CLRLOCK(vm, 0); 140 141 return 0; 142 } 143 144 #endif 145