1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
22 #if defined(_UWIN) && defined(_BLD_ast)
30 /* Get statistics from a region.
32 ** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
36 int vmstat(Vmalloc_t
* vm
, Vmstat_t
* st
)
44 reg Block_t
*b
, *endb
;
46 reg Vmdata_t
* vd
= vm
? vm
->data
: Vmregion
->data
;
51 { CLRINUSE(vd
, inuse
);
54 if(!(vd
->mode
&VM_TRUST
))
56 { CLRINUSE(vd
, inuse
);
62 st
->n_busy
= st
->n_free
= 0;
63 st
->s_busy
= st
->s_free
= st
->m_busy
= st
->m_free
= 0;
67 if(vd
->mode
&VM_MTLAST
)
69 else if((vd
->mode
&VM_MTPOOL
) && (s
= vd
->pool
) > 0)
71 for(b
= vd
->free
; b
; b
= SEGLINK(b
))
75 for(seg
= vd
->seg
; seg
; seg
= seg
->next
)
77 st
->extent
+= seg
->extent
;
80 endb
= BLOCK(seg
->baddr
);
82 if(vd
->mode
&(VM_MTDEBUG
|VM_MTBEST
|VM_MTPROFILE
))
85 if(ISJUNK(SIZE(b
)) || !ISBUSY(SIZE(b
)))
91 else /* get the real size */
92 { if(vd
->mode
&VM_MTDEBUG
)
93 s
= DBSIZE(DB2DEBUG(DATA(b
)));
94 else if(vd
->mode
&VM_MTPROFILE
)
102 b
= (Block_t
*)((Vmuchar_t
*)DATA(b
) + (SIZE(b
)&~BITS
) );
105 else if(vd
->mode
&VM_MTLAST
)
106 { if((s
= seg
->free
? (SIZE(seg
->free
) + sizeof(Head_t
)) : 0) > 0)
110 if((s
= ((char*)endb
- (char*)b
) - s
) > 0)
115 else if((vd
->mode
&VM_MTPOOL
) && s
> 0)
117 st
->n_free
+= (SIZE(seg
->free
)+sizeof(Head_t
))/s
;
118 st
->n_busy
+= ((seg
->baddr
- (Vmuchar_t
*)b
) - sizeof(Head_t
))/s
;
122 if((vd
->mode
&VM_MTPOOL
) && s
> 0)
123 { st
->n_busy
-= st
->n_free
;
125 st
->s_busy
= (st
->m_busy
= vd
->pool
)*st
->n_busy
;
127 st
->s_free
= (st
->m_free
= vd
->pool
)*st
->n_free
;
132 return inuse
? 1 : 0;