home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / sps3 / part01 / vmstat.c < prev   
Encoding:
C/C++ Source or Header  |  1992-05-08  |  1.9 KB  |  72 lines

  1. # ifndef lint
  2. static char SccsId[] =  "@(#)vmstat.c    1.1\t10/1/88" ;
  3. # endif
  4.  
  5. # ifdef SUNOS40
  6. # ifndef OLDSTATS
  7. # include "sps.h"
  8. # include <h/mman.h>
  9. # include <vm/hat.h>
  10. # include <vm/as.h>
  11. # include <vm/seg.h>
  12. # include <vm/seg_vn.h>
  13.  
  14. seg_count ( p )
  15.  
  16. struct process                  *p ;
  17.  
  18. {
  19.     extern struct info      Info ;
  20.     struct as               as ;        /* address space */
  21.     struct seg              seg ;        /* segment in addr space */
  22.     struct segvn_data       vn_data ;
  23.     unsigned                private = 0 ;
  24.     unsigned                shared = 0 ;
  25.  
  26.     p->pr_private = 0 ;
  27.     p->pr_shared = 0 ;
  28.  
  29.     if ( getkmem( (long)p->pr_p.p_as, &as, sizeof( as ) ) != sizeof( as ) )
  30.         return( -1 ) ;
  31.     seg.s_next = as.a_segs ;    /* setup for loop */
  32.     do
  33.     {
  34.         if ( ( getkmem( seg.s_next, &seg, sizeof( seg ) ) )
  35.         != sizeof( seg ) )
  36.             break ;
  37.         if ( seg.s_as != p->pr_p.p_as )
  38.             continue ;    /* invalid segment */
  39.         if ( seg.s_ops != Info.i_segvn_ops )
  40.         {            /* mapped device is "shared" */
  41.             shared += seg.s_size ;
  42.             continue ;
  43.         }
  44.         if ( getkmem( (long)seg.s_data, &vn_data, sizeof( vn_data ) )
  45.         != sizeof( vn_data ) )
  46.             continue ;
  47.         /*
  48.          * If a segment has an anonymous mapping, it is in the swap
  49.          * area.  If it is also MAP_PRIVATE, we consider it "private"
  50.          * (even though it may be shared between parent and child after
  51.          * a fork() call).  Segments without an anonymous mapping are
  52.          * considered to be "shared".  [Should we worry about swap
  53.          * space reserved for copy-on-write shared segments?]
  54.          */
  55.  
  56.         if ( vn_data.amp && (vn_data.type & MAP_TYPE) == MAP_PRIVATE )
  57.             private += seg.s_size ;
  58.         else
  59.             shared += seg.s_size ;
  60.     }
  61.     while ( seg.s_next != as.a_segs ) ;
  62.  
  63. # define BYTETOPAGE(x) (((x)+(PAGESIZE-1))>>PGSHIFT)
  64.  
  65.     p->pr_private = BYTETOPAGE( private ) ;
  66.     p->pr_shared = BYTETOPAGE( shared ) ;
  67.     p->pr_p.p_rssize = as.a_rss ;    /* update count of resident pages */
  68.     return( 0 ) ;
  69. }
  70. # endif
  71. # endif
  72.